Unable to pass the set-body in Send-response POST method

Pothiraj, Saranya-ADM 0 Reputation points
2024-03-21T22:02:30.9566667+00:00

Hi Team,

I'm trying to get the bearer token and set variables as needed .

Then want to send request to the backend with the variables set above in send-request body.

User's image

I cannot see the body attached this post send-requestUser's image

But when i use same set-body in <return-response>, I can get the all the values correctly.

The same set-body doesn't show values in <send-request>.

Can you please help on this

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,751 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Charlie Wei 1,900 Reputation points
    2024-03-22T05:19:15.23+00:00

    Hello Pothiraj, Saranya-ADM,

    According to this document, you need to additionally use the set-header policy to set the Content-Type to application/json.

    <send-request>
        <set-url>...</set-url>
        <set-method>POST</set-method>
        <set-header name="Content-Type" exists-action="override">
            <value>application/json</value>
        </set-header>
        <set-body template="liquid">...</set-body>
    </send-request>
    

    Best regards,
    Charlie


    If you find my response helpful, please consider accepting this answer and voting yes to support the community. Thank you!


  2. JananiRamesh-MSFT 21,171 Reputation points
    2024-03-29T17:11:56.0433333+00:00

    @Pothiraj, Saranya-ADM Thanks for getting back, instead of using the variable could you please add context.Response.Body directly as shown below.

    <send-request mode="new" response-variable-name="db_secret" timeout="20" ignore-error="true">
                <set-url>****</set-url>
                <set-method>GET</set-method>
                <set-header name="X-Vault-Token" exists-action="override">
    			 <value>@(context.Response.Body.As<JObject>(preserveContent: true)["auth"]["client_token"].ToString())</value>
                </set-header>
            </send-request>
    
    0 comments No comments