How to digest webhook requests

A guide on how to digest webhook requests.

Webhook requests

Once you have a URL set up for your webhook, it will send a request to that URL, whenever a specified event is triggered. A webhook request consists of two main parts: a header and a body:

  • Header: Contains metadata that describes the nature of the request, such as what event was triggered.

  • Body: Contains data related to the event, such as updated attributes on variants.

When your endpoint receives the webhook request, it should evaluate the contents of the header and body to process the event appropriately. The endpoint should then respond with an HTTP status code to indicate the result:

  • 200 OK - The request was recieved and processed successfully.

  • 400 Bad Request - The request could not be processed.

Depending on the situation, other response codes like 401 (Unauthorized) or 403 (Forbidden) may also be used.

Example of a webhook

The image below illustrates a typical webhook request. The header includes specific metadata such as:

  • X-Request-Uid: Unique ID for the specific webhook request.

  • X-Hook-Uid: Unique ID for the configured webhook in Struct PIM.

  • X-User: Specifies the origin of the request.

  • X-Event-Key: Denotes the event type that triggered the webhook, which in this case, is a "variants:updated" event.

In the image below we see an example of what a request could look like. In this case it includes data such as the ID of a modified variant.

Because this is a detailed change request, it also shows which attributes were updated. For instance, the example below illustrates that the attributes "Sku" and "Color" of the variant were updated.

Webhook request

Last updated