Home > Software design >  How to subscribe to Azure Event Grid Topic using HTTP Webhook activity in Azure Logic App
How to subscribe to Azure Event Grid Topic using HTTP Webhook activity in Azure Logic App

Time:05-07

I have a scenario in which I want to use Azure Logic App / Azure Power App to use the HTTP Webhook activity to subscribe to Event Grid Topic. I have been using Azure Event Grid connector/activity to connect with Event Grid in the Logic App but now my manager wants to move from native connector to HTTP Webhook activity. Surprisingly I have been look into this but I could not find any resource online which demonstrate/suggest how HTTP Webhook activity can be used.

I tried to use the below flow but I am getting this error

"Unauthorized","message":"The request authorization key is not authorized for EVENTGRIDNAME.NORTHEUROPE-1.EVENTGRID.AZURE.NET.

enter image description here

CodePudding user response:

Though I have'nt done this yet myself, my first guess is that you manually need to verify your Endpoint first.

As per Code you get an Event of type "Microsoft.EventGrid.SubscriptionValidationEvent". In this Event is a validationCode included that you must send back to the EventGrid as Validation-Handshake.

enter image description here

The Http Webhook Trigger has a responsibility to create an AEG subscription with a callback event handler destination endpoint during its subscribing process and also for deleting this subscription from the AEG (unsubscribing process). Based on the AEG REST APIs in my example:

Subscribe - Method:

PUT

Subscribe - URI:

https://management.azure.com/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxxxx/providers/Microsoft.EventGrid/topics/xxxxx/providers/Microsoft.EventGrid/eventSubscriptions/mySubscription123?api-version=2021-12-01

Subscribe - Body:

  {
    "properties": {
      "destination": {
        "endpointType": "WebHook",
        "properties": {
          "endpointUrl": @{listCallbackUrl()}
          }
       }
   }
 }

Subscribe - Headers:

 Authorization  Bearer eyJ0eXAiOiJKV1QiLCJ....

Unsubscribe - Method:

DELETE

Unsubscribe - URI:

https://management.azure.com/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxxxx/providers/Microsoft.EventGrid/topics/xxxxx/providers/Microsoft.EventGrid/eventSubscriptions/mySubscription123?api-version=2021-12-01

Unsubscribe - Headers:

 Authorization  Bearer eyJ0eXAiOiJKV1QiLCJ....

Note, that the Authorization header is required for using the AEG REST APIs.

Also, I do recommend to read the following docs:

https://docs.microsoft.com/en-us/azure/connectors/connectors-native-webhook https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-create-api-app

  • Related