Provides webhook endpoint management (CRUD) and signature verification.

WEBHOOK_EVENT_FAILED module-attribute

Python
WEBHOOK_EVENT_FAILED: str = 'job.failed'

Event name sent when a job fails.

WEBHOOK_EVENT_RUNNING module-attribute

Python
WEBHOOK_EVENT_RUNNING: str = 'job.running'

Event name sent when a job starts running.

WEBHOOK_EVENT_SUCCEEDED module-attribute

Python
WEBHOOK_EVENT_SUCCEEDED: str = 'job.succeeded'

Event name sent when a job succeeds.

WebhooksServiceClient

Bases: ScrubbedSessionState

Client for managing webhook endpoints and verifying signatures.

Manages its own requests.Session and implements the context-manager protocol for clean session teardown.

Parameters:

NameTypeDescriptionDefault
api_keystr or _SharedApiKeyAPI key for authenticating requests.required
loggerLoggerLogger instance for debug/info output.required
base_urlstrBase URL for the Infrared API (e.g. "https://api.infrared.city/v2").required

close

Python
close() -> None

Close the underlying requests session.

register

Python
register(url: str, type: str, ip: Optional[str] = None) -> WebhookEndpoint

Register a new webhook endpoint.

POST {base_url}/webhooks with the registration payload.

Parameters:

NameTypeDescriptionDefault
urlstrThe URL to receive webhook events.required
typestrEndpoint type ("production" or "development").required
ipstr or NoneOptional IP address filter.None

Returns:

TypeDescription
WebhookEndpointThe newly created endpoint (without timestamps).

Raises:

TypeDescription
WebhookRegistrationErrorIf the HTTP request fails.

list

Python
list() -> List[WebhookEndpoint]

List all webhook endpoints.

GET {base_url}/webhooks.

Returns:

TypeDescription
[list](#infrared_sdk.webhooks.WebhooksServiceClient.list)[[WebhookEndpoint](#infrared_sdk.webhooks.WebhookEndpoint)]All registered endpoints (with timestamps).

Raises:

TypeDescription
WebhookErrorIf the HTTP request fails.

get

Python
get(endpoint_id: str) -> WebhookEndpoint

Get a specific webhook endpoint by ID.

GET {base_url}/webhooks/{endpoint_id}.

Parameters:

NameTypeDescriptionDefault
endpoint_idstrThe ID of the endpoint to retrieve.required

Returns:

TypeDescription
WebhookEndpointThe requested endpoint (with timestamps).

Raises:

TypeDescription
WebhookNotFoundErrorIf the endpoint is not found (404).
WebhookErrorIf the HTTP request fails for other reasons.

delete

Python
delete(endpoint_id: str) -> None

Delete a webhook endpoint by ID.

DELETE {base_url}/webhooks/{endpoint_id}.

Parameters:

NameTypeDescriptionDefault
endpoint_idstrThe ID of the endpoint to delete.required

Raises:

TypeDescription
WebhookNotFoundErrorIf the endpoint is not found (404).
WebhookErrorIf the HTTP request fails for other reasons.

verify_signature staticmethod

Python
verify_signature(
payload_body: bytes, headers: dict, secret: str, tolerance: int = 300
) -> bool

Verify a Standard Webhooks HMAC-SHA256 signature.

Validates that the signature in the webhook-signature header matches the expected HMAC for the given payload, and that the timestamp is within the tolerance window (replay protection).

Signing format:

Python
signed_content = "{webhook-id}.{webhook-timestamp}.{body}"
signature = "v1," + base64(HMAC-SHA256(decoded_secret, signed_content))

Parameters:

NameTypeDescriptionDefault
payload_bodybytesThe raw request body bytes.required
headersdictRequest headers containing webhook-id, webhook-timestamp, and webhook-signature.required
secretstrThe webhook secret ("whsec_" prefixed, base64-encoded).required
toleranceintMaximum age of the timestamp in seconds (default 300). Set to 0 to disable replay protection.300

Returns:

TypeDescription
boolTrue if the signature is valid and the timestamp is within tolerance; False otherwise.

WebhookEndpoint dataclass

Immutable snapshot of a webhook endpoint from the API.

The created_at and updated_at fields are optional because the registration response (POST /webhooks) only returns {id, url, type} without timestamps, whereas list/get responses include them.

Attributes:

NameTypeDescription
idstrIdentifier of the endpoint.
urlstrThe URL that receives webhook events.
typestrEndpoint type ("production" or "development").
created_atstr or NoneCreation time as returned by the API, or None when the response carried no timestamps.
updated_atstr or NoneLast-update time as returned by the API, or None when the response carried no timestamps.

from_response classmethod

Python
from_response(data: dict) -> WebhookEndpoint

Build a WebhookEndpoint from an API response dict.

Handles both registration responses (no timestamps) and list/get responses (with timestamps via camelCase keys).

WebhookError

Bases: Exception

Base exception for all webhook errors.

HTTP error context lives on attributes (status_code, response_body) instead of the positional message so the raw response body never lands in args[0] / default repr / Sentry's message capture.

Attributes:

NameTypeDescription
status_codeint or NoneHTTP status of the failed response, if there was one.
response_bodystr or NoneThe raw response text, if any.

WebhookNotFoundError

Bases: WebhookError

Raised when a webhook endpoint is not found.

WebhookRegistration dataclass

Registration request payload for creating a webhook endpoint.

Attributes:

NameTypeDescription
urlstrThe URL to receive webhook events.
typestrEndpoint type ("production" or "development").
ipstr or NoneOptional IP address filter for the endpoint.

WebhookRegistrationError

Bases: WebhookError

Raised when webhook registration fails.