77from crawlee ._utils .urls import validate_http_url
88
99from apify ._utils import docs_group
10+ from apify .log import logger
1011
1112if TYPE_CHECKING :
1213 from apify_client ._literals import WebhookEventType
@@ -19,6 +20,9 @@ class Webhook:
1920
2021 The same instance can be passed as an ad-hoc webhook to `Actor.start()` / `Actor.call()` or as a persistent
2122 webhook to `Actor.add_webhook()` (the `condition.actor_run_id` is set automatically to the current run).
23+
24+ Ad-hoc webhooks support only `event_types`, `request_url`, `payload_template` and `headers_template`; the
25+ remaining fields apply only to `Actor.add_webhook()` and are ignored (with a warning) otherwise.
2226 """
2327
2428 event_types : list [WebhookEventType ]
@@ -34,23 +38,41 @@ class Webhook:
3438 """Template for the HTTP headers sent by the webhook."""
3539
3640 idempotency_key : str | None = None
37- """Key that prevents creating duplicate webhooks."""
41+ """Key that prevents creating duplicate webhooks. Only applies to `Actor.add_webhook()`. """
3842
3943 ignore_ssl_errors : bool | None = None
40- """Whether to ignore SSL errors when sending the request."""
44+ """Whether to ignore SSL errors when sending the request. Only applies to `Actor.add_webhook()`. """
4145
4246 do_not_retry : bool | None = None
43- """Whether to skip retrying the request on failure."""
47+ """Whether to skip retrying the request on failure. Only applies to `Actor.add_webhook()`. """
4448
4549 def __post_init__ (self ) -> None :
4650 # Fail fast on a malformed URL at construction time instead of deferring the error to the API call.
4751 validate_http_url (self .request_url )
4852
4953
5054def to_client_representations (webhooks : list [Webhook ] | None ) -> list [WebhookRepresentation ] | None :
51- """Project SDK webhooks to the minimal ad-hoc representation accepted by the client's `start()` / `call()`."""
55+ """Project SDK webhooks to the minimal ad-hoc representation accepted by the client's `start()` / `call()`.
56+
57+ Fields not supported by ad-hoc webhooks (`idempotency_key`, `ignore_ssl_errors`, `do_not_retry`) are dropped
58+ with a warning.
59+ """
5260 if not webhooks :
5361 return None
62+
63+ for webhook in webhooks :
64+ dropped = [
65+ field
66+ for field in ('idempotency_key' , 'ignore_ssl_errors' , 'do_not_retry' )
67+ if getattr (webhook , field ) is not None
68+ ]
69+ if dropped :
70+ fields = ', ' .join (f'`{ field } `' for field in dropped )
71+ logger .warning (
72+ f'Ad-hoc webhooks do not support { fields } ; the field(s) will be ignored. '
73+ f'Use `Actor.add_webhook()` to create a webhook with them.'
74+ )
75+
5476 return [
5577 WebhookRepresentation (
5678 event_types = w .event_types ,
0 commit comments