Webhooks are currently available to
Scale customers only, if you’re
interested contact us.
Summary
To start receiving webhook events in your integration, create and register a webhook endpoint by following the steps below:- Create a webhook endpoint handler to receive event data POST requests.
- Register your endpoint with Brandfetch via an API request.
- Secure your webhook endpoint.
Create a handler
See the events reference to identify the event types your webhook handler needs to process. Set an HTTPS endpoint function that can accept webhook requests with a POST method. Set up your endpoint function so that it:- Handles POST requests with a JSON payload consisting of an event object.
- Quickly returns a successful status code (2xx) prior to any complex logic that could cause a timeout.
Example endpoint
This code snippet is a webhook function configured to check that the event type was received, to handle the event, and return a 200 response. Example code forhasVerifiedPayload()
is available here.
Register your endpoint
Once your handler is deployed on the web and ready to go, register your endpoint with Brandfetch by creating a webhook using the GraphQL APIscreateWebhook
mutation.
Registered webhook endpoint URLs must be publicly accessible HTTPS URLs.
Subscribe to objects using their URNs
The final step is to subscribe to the objects (like brands) for which you want to receive events. You can subscribe to a few objects, or many thousands—one at a time, or in batches. For example, perhaps you want to receive events for the Brandfetch brand. The URN for this brand isurn:brandfetch:brand:idL0iThUh6which
means we would subscribe to that URN.
To add a subscription we need two things: The URN for the webhook we created ($webhookUrn: URN!
) and the URN for the object to which we want to subscribe to ($subscriptions: [URN!]!
).