I have two APIs added to Azure API Management. It's basically the same API, but for different environments. For monitoring purposes, I want to create an operation that would call the same method in both of the APIs and merge their result into one. I currently work on mocked APIs with mocked data.
To achieve that I created a blank API with a blank operation. Inside this operation, I declared the following inbound policies:
<inbound>
<set-variable name="env1" value="" />
<set-variable name="env2" value="" />
<send-request mode="new" response-variable-name="env1" timeout="20" ignore-error="false">
<set-url>https://env1-api.azure-api.net/api/data</set-url>
<set-method>GET</set-method>
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
</send-request>
<send-request mode="new" response-variable-name="env2" timeout="20" ignore-error="false">
<set-url>https://env2-api.azure-api.net/api/data</set-url>
<set-method>GET</set-method>
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
</send-request>
<base />
</inbound>
When tested the operation called throws 500 (which, I believe, is understandable, as no response is being set). When I look at the Trace tab I can see two messages:
GET request to 'https://env1-api.azure-api.net/api/data' has been sent, result stored in 'env1' variable.
GET request to 'https://env2-api.azure-api.net/api/data' has been sent, result stored in 'env2' variable.
Based on that I conclude that the calls are working correctly. Here's where I'm stuck. I don't know how to merge those two variables inside a response.
The API's return an array of objects in the form of a JSON object. What I want to achieve is to merge those two responses into one response that will be returned by the operation. How can I compose a response?
Please have in mind that I'm a noob in Azure, so my approach might be too primitive. If you have something better I'd love to hear about it.
<set-variable name="var1body" value="@((IResponse)context.Variables["var1"]).Body.As<string>())" />
If you would add it, I would accept it as an answer. – Witchcraft