Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/apify_client/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3766,6 +3766,18 @@ class WebhookRepresentation(BaseModel):
"""
Optional template for the HTTP headers sent by the webhook.
"""
idempotency_key: Annotated[str | None, Field(alias='idempotencyKey', examples=['fdSJmdP3nfs7sfk3y'])] = None
"""
Optional key that prevents creating duplicate webhooks, e.g. when the run-starting request is retried.
"""
ignore_ssl_errors: Annotated[bool | None, Field(alias='ignoreSslErrors', examples=[False])] = None
"""
Optional flag to ignore SSL errors when the webhook sends the request.
"""
do_not_retry: Annotated[bool | None, Field(alias='doNotRetry', examples=[False])] = None
"""
Optional flag to skip retrying the webhook request on failure.
"""


@docs_group('Models')
Expand Down
24 changes: 24 additions & 0 deletions src/apify_client/_typeddicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,18 @@ class WebhookRepresentationDict(TypedDict):
"""
Optional template for the HTTP headers sent by the webhook.
"""
idempotency_key: NotRequired[str | None]
"""
Optional key that prevents creating duplicate webhooks, e.g. when the run-starting request is retried.
"""
ignore_ssl_errors: NotRequired[bool | None]
"""
Optional flag to ignore SSL errors when the webhook sends the request.
"""
do_not_retry: NotRequired[bool | None]
"""
Optional flag to skip retrying the webhook request on failure.
"""


@docs_group('Typed dicts')
Expand Down Expand Up @@ -374,3 +386,15 @@ class WebhookRepresentationCamelDict(TypedDict):
"""
Optional template for the HTTP headers sent by the webhook.
"""
idempotencyKey: NotRequired[str | None]
"""
Optional key that prevents creating duplicate webhooks, e.g. when the run-starting request is retried.
"""
ignoreSslErrors: NotRequired[bool | None]
"""
Optional flag to ignore SSL errors when the webhook sends the request.
"""
doNotRetry: NotRequired[bool | None]
"""
Optional flag to skip retrying the webhook request on failure.
"""
3 changes: 3 additions & 0 deletions src/apify_client/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ def encode_webhooks_to_base64(webhooks: WebhooksList | None) -> str | None:
request_url=webhook.request_url,
payload_template=webhook.payload_template,
headers_template=webhook.headers_template,
idempotency_key=webhook.idempotency_key,
ignore_ssl_errors=webhook.ignore_ssl_errors,
do_not_retry=webhook.do_not_retry,
)
)
else:
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

import io
import json
from base64 import b64decode
from datetime import timedelta
from http import HTTPStatus
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -58,6 +60,33 @@ def test_encode_webhooks_to_base64() -> None:
)


def test_encode_webhooks_to_base64_keeps_adhoc_fields() -> None:
"""Test that the idempotency key and the SSL/retry flags survive the projection onto `WebhookRepresentation`."""
result = encode_webhooks_to_base64(
[
WebhookCreate(
event_types=['ACTOR.RUN.SUCCEEDED'],
condition=WebhookCondition(),
request_url='https://example.com/run-succeeded',
idempotency_key='some-key',
ignore_ssl_errors=True,
do_not_retry=True,
),
]
)

assert result is not None
assert json.loads(b64decode(result)) == [
{
'eventTypes': ['ACTOR.RUN.SUCCEEDED'],
'requestUrl': 'https://example.com/run-succeeded',
'idempotencyKey': 'some-key',
'ignoreSslErrors': True,
'doNotRetry': True,
}
]


def test_encode_webhooks_to_base64_from_dicts() -> None:
"""Test that encode_webhooks_to_base64 accepts plain dicts typed as WebhookRepresentationDict."""
webhooks: list[WebhookRepresentationDict] = [
Expand Down
Loading