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

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


Solution 1:[1]

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>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mangesh Kathar