How To Debug Azure Event Grid Trigger Function Using Postman

This article demonstrates how we can debug an event grid functions locally using Postman. Here, we use Azure Event Grid with an Azure function as an endpoint to handle the events. We will create a mock event to debug into our function.

Using postman, we will create the request. For that we need to form correct URL, HTTP headers and Payload. Let’s see these step by step –

STEP 1 - Create an Event Grid function

A simple event grid trigger function created in visual studio. Here we are deserializing the data property contained within the event into the target object to retrieve the actual data that is intended to handle.

debug an event grid functions locally using Postman

STEP 2 - The URL

We use a local URL that sends a request to trigger the function. {functionname} need to replace with actual function name.

http://localhost:7071/runtime/webhooks/EventGrid?functionName={functionname}

In my case, function name is training-export

http://localhost:7071/runtime/webhooks/eventgrid?functionName=training-export

STEP 3 - Add Required HTTP Header

Add the following headers. Without these headers, request doesn’t work.

  • Content-Type = application/json
  • aeg-event-type = Notification

debug an event grid functions locally using Postman

STEP 4 - Configure Payload

In request body, event grid expects the request to have a certain set of fields as per defined schema. To debug locally we need to understand the schema of the event. Schema reference has been taken from Microsoft documentation.

[
  {
    "topic": string,
    "subject": string,
    "id": string,
    "eventType": string,
    "eventTime": string,
    "data":{
      object-unique-to-each-publisher
    },
    "dataVersion": string,
    "metadataVersion": string
  }
]

To understand the purpose of each event properties, refer Microsoft documentation.

The data element varies depending on the different event sources. For example - If you are sending training request data through event grid such as this:

debug an event grid functions locally using Postman

This event JSON should look something like this with training request data.

{
    "id": "1",
    "subject": "training-export",
    "data": {
        "trainingTopic": "Debugging Event Grid Function",
        "trainer": "Anupam",
        "date": "2022-05-10T12:19:17.000Z"
    },
    "eventType": "ExportSuccessful",
    "dataVersion": "1",
    "metadataVersion": "1",
    "eventTime": "2022-05-16T12:31:22.2592489Z"
}

We will copy paste these JSON into request body.

debug an event grid functions locally using Postman

STEP 5 - Debug and Test the function

Once we send the request from postman, it will hit the function and we can debug it. Here is the console log for function execution.

debug an event grid functions locally using Postman

Awesome! We have successfully debug a Azure event grid trigger function using postman.

Happy Learning!


Similar Articles