Saltar a contenido

Webhooks

Recurso client.webhooks (endpoint webhooks/subscriptions) y parser tipado parse_webhook. Ver Webhooks.

alegrapy.webhooks.Webhooks

Operations related to webhook subscriptions (/webhooks/subscriptions).

__init__(client)

Initialize the resource with an explicit AlegraClient.

list(page=None)

List webhook subscriptions, optionally for a 1-based page (10 per page).

Without page, Alegra returns all subscriptions. Unwraps subscriptions.

get(id)

Retrieve a single webhook subscription by ID.

create(event, url)

Create a webhook subscription and return the subscription object.

Note

Before creating, Alegra POSTs {} to https://<url> and requires a 2xx response in under 5 seconds. The wrapper message from Alegra's response is dropped and only subscription is returned.

update(id, url)

Update a subscription's URL and return the subscription object.

Calling PUT (even with the same URL) also reactivates a SUSPENDED subscription and resets its failure counter. The event cannot be changed.

delete(id)

Delete a webhook subscription by ID.

alegrapy.webhooks.WebhookEventType

Bases: str, Enum

Webhook event subjects documented by Alegra.

alegrapy.webhooks.WebhookEvent dataclass

Typed representation of a parsed Alegra webhook delivery.

fetch(client)

Re-read the referenced resource from Alegra before trusting the payload.

Returns None without making a request for delete-* events.

alegrapy.webhooks.parse_webhook(body)

Parse and validate an incoming Alegra webhook payload into a :class:WebhookEvent.

Parameters:

Name Type Description Default
body bytes, str, or dict

Raw JSON request body or already-parsed dict.

required

Returns:

Name Type Description
WebhookEvent WebhookEvent

Parsed, typed webhook event.

Raises:

Type Description
AlegraWebhookError

If the payload is not valid JSON, not a JSON object, has an unknown/missing subject, or lacks the matching resource object with a non-blank id.

alegrapy.webhooks.AlegraWebhookError

Bases: ValueError

Raised when an incoming Alegra webhook payload is malformed or unsupported.