I am relatively new to Azure APIM and I have this backend which I am able to invoke which returns the response in format
{
"data": {
"attributes": {
"municipalities": []
}
}
}
I want to modify the response so that the data is returned in the format
{
"data": {
"municipalities": []
}
}
I have tried using the set body liquid template
<outbound>
<set-body template="liquid">
{
"data": {
"municipalities": {{body.data.attributes.municipalities}}
}
}</set-body>
</outbound>
But the response I get is just
{
"data": {
"municipalities":
}
}
If someone can point out to me what I am doing wrong or if there is a better way to do this?
I also tried to use the below code just to check if I am able to retrieve the "data" attribute but I got the below error in the trace part of Azure APIM Test
<outbound>
<set-body>
@{
JObject inBody = context.Request.Body.As<JObject>();
return inBody["data"].ToString();
}
</set-body>
</outbound>
ERROR:
{
"messages": [
{
"message": "Expression evaluation failed.",
"expression": " \n JObject inBody = context.Request.Body.As<JObject>();\n return inBody[\"data\"].ToString(); \n",
"details": "Object reference not set to an instance of an object."
},
"Expression evaluation failed. Object reference not set to an instance of an object.",
"Object reference not set to an instance of an object."
]
}

<outbound><set-body>. According to some test, I guess you didn't get the response data success there. - Hury Shen