Accessing post query params in Azure webhook

610 views Asked by At

I am trying to read the URL query params from a POST coming into my Azure webhook (PowerShell).

My webhook is receiving a POST request such as:

Content-Type: text/plain; charset=utf-8
POST https://{notificationUrl}?validationToken={opaqueTokenCreatedByMicrosoftGraph}

As you may tease out, the context here is the creation of a Microsoft Graph subscription. However, I don't want to muddy up this post with too many details because I think my question is general enough: how to read POST params in an Azure webhook.

The runbook attached to this webhook (based on this one) apparently requires all the client data to come in via a single parameter called WebhookData. I am able to read the WebhookName, RequestBody, and RequestHeader inside WebhookData. However, I don't know how to read the URL query parameter in the POST request that is reaching my webhook.

Specifically, I need to access that validationToken. It doesn't show up in the WebhookData. I've also tried removing the Webhookdata param altogether from my runbook, but then absolutely nothing comes in. I've also tried adding a validationToken param, alongside the WebhookData param, but validationToken comes out empty.

I should add that, along with the POST from Graph (which doesn't work), I am testing my runbook with Postman and making sure to include a validationToken in the URL. Again, I can read it if I include it in the POST body, but not if it's a query param. And since ultimately Graph will be sending it via the query param, I think I have to get that to work first.

1

There are 1 answers

1
HAL9256 On BEST ANSWER

Very specifically, Azure Runbooks, do not support query strings. From the documentation:

To receive data from the client, the runbook supports a single parameter called WebhookData. This parameter defines an object containing data that the client includes in a POST request.

The WebhookData parameter has the following properties:

Property Description
WebhookName Name of the webhook.
RequestHeader Hashtable containing the headers of the incoming POST request.
RequestBody Body of the incoming POST request. This body keeps any data formatting, such as string, JSON, XML, or form-encoded. The runbook must be written to work with the data format that is expected.

Azure Runbooks has 2 parts to it, triggers and runbooks:

Azure Runbooks

The Runbook (Right Box) only accepts the single WebhookData object to manage variable and data that Azure Runbooks will operate with.

Webhooks (Left Box), handles the triggering, receiving of data and passing it on to the Runbook. Very specifically, the RequestBody is specified as the:

Body of the incoming POST request. This body keeps any data formatting, such as string, JSON, XML, or form-encoded.This body keeps any data formatting, such as string, JSON, XML, or form-encoded.

With this definition, very specifically, even though WebHooks can support query strings, in this case for triggering Azure Runbooks they are explicitly ignored.


Aside, if the end desire is to subscribe to Microsoft Graph events, the "better" way is to use Event Hubs to handle notifications:

Using Azure Event Hubs to receive change notifications differs from webhooks in a few ways, including:

  • You don't rely on publicly exposed notification URLs. The Event Hubs SDK will relay the notifications to your application.
  • You don't need to reply to the notification URL validation. You can ignore the validation message that you receive.
  • You'll need to provision an Azure Event Hub.
  • You'll need to provision an Azure Key Vault.