How to send one-way request to Logic App from Azure API Management
Introduction
I had a need to send one-way request to Logic Apps from Azure API Management. Sending one-way request is already described in the API Management advanced policies. However, there are two things to be aware when making request to Logic Apps from APIM policy.
Request made to Beeceptor
Let’s say that you want to conditionally send oneway request; POST a json body message using a part of url path from the request.
/messages/{messageId}/{lockToken}
Following the sample in API Management advanced policies, you can easily verify the request is made as expected.
<outbound> <base /> <choose> <when condition="@(context.Response.StatusCode == 200)"> <send-one-way-request mode="new"> <set-url>https://testack.free.beeceptor.com</set-url> <set-method>POST</set-method> <set-body>@{ return new JObject( new JProperty("messageId", context.Request.Url.Path.Split('/')[3]), new JProperty("lockToken", context.Request.Url.Path.Split('/')[4]) ).ToString(); }</set-body> </send-one-way-request> </when> </choose> </outbound>
Request made to Logic Apps
However, when making a request to Logic Apps, you will need to rember two different things.
Escape Logic Apps url for xml
Since APIM policy is in xml, you will need to escape the url before copying that into the policy.
Add Content-Type header
Make sure to add the content-type header, otherwise, the request will still be made but will not have the request body.
Before
After
<outbound> <base /> <choose> <when condition="@(context.Response.StatusCode == 200)"> <send-one-way-request mode="new"> <set-url>{REPLACE TO LOGIC APPS URL}</set-url> <set-method>POST</set-method> <set-header name="Content-Type" exists-action="override"> <value>application/json</value> </set-header> <set-body>@{ return new JObject( new JProperty("messageId", context.Request.Url.Path.Split('/')[3]), new JProperty("lockToken", context.Request.Url.Path.Split('/')[4]) ).ToString(); }</set-body> </send-one-way-request> </when> </choose> </outbound>