0
votes

Document reference: https://docs.microsoft.com/en-us/azure/api-management/api-management-transformation-policies#example-1

A snippet from my "inbound processing" policies:

<inbound>
   <base />
   <xml-to-json kind="direct" apply="always" consider-accept-header="false" />
</inbound>

Problem: When I apply this policy in "inbound processing" the backend API (Logic App) that is called is given an empty body. The API receiving this request shows Content-Length = 0.

Results from trace:

xml-to-json (0.697 ms)
"XML-to-JSON policy was applied. Original Content-Length header was removed as its value was invalidated. Content-Type header was set to 'application/json'."

Notes: When I apply this exact same policy in the "outbound processing" policies, I get the result I am expecting as JSON.

Basic XML example I am sending:

<note>
    <to>PersonOne</to>
    <from>PersonTwo</from>
    <heading>Test</heading>
    <body>Example</body>
</note>

Result I get when policy is applied to in "outbound policies" section (This is working as expected):

{
    "note": {
        "to": "PersonOne",
        "from": "PersonTwo",
        "heading": "Test",
        "body": "Example"
    }
}
1
I tried a simple scenario just using the xml-to-json policy and it did work as expected. Do you have any other policies that maybe are affecting the request body?PramodValavala-MSFT
@PramodValavala-MSFT - I had tried to use just the single policy and it was still doing the same thing. Maybe knowing that the resource receiving this data is a Logic App would help? I have a simple Logic App that is setup as a trigger to receive this. I will try again today and simplify everything and see if there is anything else inbound that would do this. I'll post back today with some news. Thanks!Brien Foss
Could you add a dump of request you're making to test policy in inbound?Vitaliy Kurokhtin

1 Answers

0
votes

This is caused by the original Content-Length header being removed when APIM does the conversion from XML to JSON. If you do a test request in APIM and look in the trace console you'll see a message like this:

"XML-to-JSON policy was applied. Original Content-Length header was removed as its value was invalidated. Content-Type header was set to 'application/json'."

APIM replaces the header with

Transfer-Encoding: chunked

and sets Content-Length to 0. Unfortunately Logic Apps don't support chunked encoding on triggers (only on some actions) so aren't able to handle the request.