Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 in webhook.site

While developing and testing handling of webhooks, webhook.site can also be a valuable resource. Go to the site, copy the unique webhook link and paste it into the relevant webhook settings in Struct PIM.

Upon triggering the webhook in Struct PIM, webhook.site is live updated for you to examine the request and e.g. copy it into Postman for testing on a local machine. As it is a free service, the link will only work for a given number of requests after which you will have to generate a new link.

Failed requests and retries

A webhook request counts as delivered when your endpoint responds with a 2xx status code, such as 200 OK. Any other status code counts as a failed request, and so does a request that gets no response, for example because your endpoint could not be reached or did not respond in time.

Struct PIM retries a failed request up to 2 times, so the same event is sent at most 3 times:

Attempt
When it is sent

Original request

When the event is triggered

1st retry

About 1 to 3 minutes after the original request

2nd retry

About 10 to 13 minutes after the original request

  • Retries stop as soon as one of them is delivered.

  • Retries stop if the webhook is deactivated.

  • If the 2nd retry also fails, the event is not sent again.

A retry carries the same body and the same X-Event-Key, X-Hook-Uid and X-User headers as the original request, but a new X-Request-Uid. It is sent to the URL, with the custom request headers and authorization settings, that the webhook has when the retry is sent. So if a request failed because of a wrong URL or wrong authorization settings, correcting the webhook within the first 10 minutes lets the retries get through.

If your endpoint processes a request but still responds with an error, or responds too slowly, the retry delivers the same event again. Design your endpoint so that receiving the same event twice does no harm. Since each retry has a new X-Request-Uid, do not rely on that header to recognise an event you have already received.

Last updated