Webhooks
Webhooks let you build integrations that react to events as they happen in Bazoom. Instead of polling the API, you register a URL, and Bazoom sends a request to it whenever a relevant event occurs. For example, you can be notified when a media is activated or deactivated.
The webhook endpoints let you create, list, update and delete your webhooks through the Client API.
Request anatomy
Every webhook request includes the following headers:
- Name
X-Webhook-Id- Type
- integer
- Description
The ID of the webhook that sent the request.
- Name
X-Webhook-Event- Type
- integer
- Description
The ID of the event that triggered the request.
- Name
X-Webhook-Timestamp- Type
- string
- Description
The time the request was sent, in ISO 8601 format (e.g.
2022-03-25T05:09:27Z).
- Name
X-Webhook-Signature- Type
- string
- Description
A signature you can use to verify that the request came from Bazoom.
The request body contains the resource related to the event.
Verifying requests
The x-webhook-signature header is an HMAC-SHA256 signature of the timestamp, a period (.) and the raw request body, signed with the secret you received when the webhook was created:
signature = HMAC_SHA256(timestamp + “.” + body, secret)
To verify a request, compute the signature yourself and compare it to the value in the header. If they don't match, discard the request.
Verifying a signature
import base64
import hashlib
import hmac
from flask import Request
def validate_signature(request: Request) -> bool:
timestamp = request.headers.get("X-Webhook-Timestamp", "")
signature = request.headers.get("X-Webhook-Signature", "")
body = request.get_data()
secret = "your-webhook-secret"
message = timestamp.encode() + b"." + body
expected_signature = base64.b64encode(
hmac.new(secret.encode(), message, hashlib.sha256).digest()
).decode()
return hmac.compare_digest(expected_signature, signature)```
Testing webhooks locally
To test your Bazoom webhooks locally before deploying them to your production server you can use a localhost tunneling service, such as ngrok, and create a webhook for the tunnel URL.
When you have your tunnel URL, simply create a Bazoom webhook for it and use the trigger webhook endpoint to test.
Events
Order link events
These events are only triggered for order links belonging to a business tied to the user who created the webhook.
- Name
order.link.ready_for_approval- Description
Triggered when an order link is ready for approval.
- Name
order.link.published- Description
Triggered when an order link is published.
Media events
- Name
media.activated- Description
Triggered when a media is activated.
- Name
media.deactivated- Description
Triggered when a media is deactivated.