Overview
Webhooks allow your application to receive real-time notifications when events occur in Grantex. Thewebhooks client manages webhook endpoint registrations, and the verify_webhook_signature() function validates incoming payloads.
Access the webhooks client via client.webhooks.
Create
Register a new webhook endpoint that will receive event notifications:Parameters
All parameters are keyword-only.| Parameter | Type | Required | Description |
|---|---|---|---|
url | str | Yes | The HTTPS URL that will receive webhook events. |
events | list[str] | Yes | The event types to subscribe to. |
Returns
AWebhookEndpointWithSecret dataclass. The secret field is only returned at creation time — store it securely for signature verification.
Supported Events
| Event | Description |
|---|---|
grant.created | A new grant has been issued. |
grant.revoked | A grant has been revoked. |
token.issued | A new grant token has been issued. |
List
List all registered webhook endpoints:ListWebhooksResponse
| Field | Type | Description |
|---|---|---|
webhooks | tuple[WebhookEndpoint, ...] | The list of webhook endpoints. |
WebhookEndpoint
| Field | Type | Description |
|---|---|---|
id | str | Unique webhook endpoint identifier. |
url | str | The webhook URL. |
events | tuple[str, ...] | Subscribed event types. |
created_at | str | ISO 8601 creation timestamp. |
Delete
Remove a webhook endpoint:Verify Webhook Signatures
When your server receives a webhook payload, verify the signature to ensure it was sent by Grantex and has not been tampered with.Import
Usage
Parameters
| Parameter | Type | Description |
|---|---|---|
payload | str | bytes | The raw request body received from Grantex. |
signature | str | The value of the X-Grantex-Signature header. |
secret | str | The webhook secret returned when the endpoint was created. |
Returns
True if the signature is valid, False otherwise.
How It Works
The signature is computed assha256=<hex-digest> using HMAC-SHA256 with the webhook secret as the key and the raw request body as the message. The verification uses constant-time comparison to prevent timing attacks.