Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Send One Way policy

APIM integrates well with external services via HTTP-based interaction.

This example shows a fire-and-forget send-one-way-request policy, which does not await a response. Alternatively, you can use a send-request policy to send a request and await a return. Some complex in-flight processing logic may also be better handled by using Logic Apps.

Setup the Send-One-Way-Request policy

The following policy and payload applies for both examples in this section (webhook and teams). Please ensure that you replace the value in <set-url> with your webhook target URL. You will identify the URL in either example below.

  • Open the Add two integers operation in the Calculator API.
  • Open the Code View.
  • Add the send-one-way-request policy to Outbound processing and replace the webhook and payload as required. For demo purposes we are going to use the payload for a Teams message (even for Webhook.site) and also send the message on every successful request.

    <outbound>
        <base />
        <xml-to-json kind="direct" apply="always" consider-accept-header="false" />
        <set-header name="x-aspnet-version" exists-action="delete" />
        <set-header name="x-powered-by" exists-action="delete" />
        <choose>
            <when condition="@(context.Response.StatusCode == 200)">
                <send-one-way-request mode="new">
                    <set-url>https://enter-your-webhook-url</set-url>
                    <set-method>POST</set-method>
                    <set-body>@{
          return new JObject(
            new JProperty("@type","MessageCard"),
            new JProperty("@context", "http://schema.org/extensions"),
            new JProperty("summary","Summary"),
            new JProperty("themeColor", "0075FF"),
            new JProperty("sections",
              new JArray (
                new JObject (
                  new JProperty("text", "Hello!")
                )
              )
            )
          ).ToString();
        }</set-body>
                </send-one-way-request>
            </when>
        </choose>
    </outbound>
    

Send a message to Webhook.site

Webhook.site is a simple recipient to test webhook messages and requires no setup overhead, making this an ideal component in this lab, especially as we are not sending any sensitive information in our payload from our test Azure API Management instance.

  • Go to Webhook.site and copy the value for Your unique URL.

    Webhook Site Setup

  • Use this URL as the value in the <set-url> property in the send-one-way-request policy previously defined.

  • Invoke the API from the Azure API Management Test tab by clicking the Trace button and observe the 200 success response.

  • Check the Trace for the Outbound one-way message.

    Webhook Site APIM Trace

  • Observe the success in the Webhook site.

    Webhook Site Success

Send a message to Microsoft Teams channel

An optional lab to connect to Microsoft Teams:

  • Follow the official steps from the documentation to create an Incoming Webhook and when you have your rwebhook URL ready, update the previous send-one-way-request policy.

  • If you want, you can format the required payload. The payload sent to a Teams channel uses the MessageCard JSON schema. You can experiment with different cards in the MessageCard Playground.

  • When you are ready, invoke the API from the Test tab and observe the 200 success response.

  • Look for a received message in your Teams channel:

    Teams APIM Message