Need to modify request payload in Azure APIM set body to send modified request body to BE

1.5k views Asked by At
My APIM is receiving request payload in POST request -
and I have to format and send to backend --
Formatted payload for BE

I have to add the 2 parameters after every newreq line and append 2 new lines after GET request line. how to achive this in apim.

    newreq
    Content-Type: application/http--I have to append these parameter in payload
    Accept: application/json
    GET Abc?$format=json HTTP/1.1
    newreq
    Content-Type: application/http
    Accept: application/json
    GET Abc?$format=json HTTP/1.1
    endnewreq
1

There are 1 answers

0
Mangesh Kathar On

You can read request body first and then append the parameters to object.

        <set-body>@{ 
        var requestBody = context.Request.Body.As<JObject>(preserveContent: 
        true);

        requestBody ["Content-Type"] = "Your Value";
        requestBody ["Accept"] = "Your Value";

        return requestBody.ToString();
        }</set-body>