Search code examples
xmlazurejqazure-api-managementazure-rest-api

Azure rest api - APIM policy XML errors


We ran into an issue with API managment, our client wants us to automate adding API level policies to the APIs we have configured there.
We are trying it to resolve this with a bash script(we can't use powershell or any other tool), but we ran into a problem: the API expects Content-Type: application/json, but one of the values should be an XML string.

I tried multiple ways to make the request body for this, but I get errors in the response, like: "message":"An error occurred while parsing EntityName. Line 6, position 74."

or "Data at the root level is invalid. Line 1, position 1."

Does anyone have any idea how we should form our request body?
We are doing this with jq, like this:

jq -Rs \
   --arg contentFormat "xml" \
   '{properties: {format: $contentFormat, value: . }}' <${policy}

Where policy is path to xml document which is copied from the manually generated policy from the GUI.

Any help is appreciated!

I suspect the problem is with XML formatting, but we tried to encode it in various ways and it didn't help.


Solution

  • In the meanwhile I managed to solve this, the XML's special characters had to be replaced(";&;<;>). Previously we did it for the whole document not just in the values.