Skip to content

Commit

Permalink
feat: adds headers_template to webhooks and webhooks_collection (#239)
Browse files Browse the repository at this point in the history
Adds the `headers_template` kwarg and is included in the payload on
POST/PUT to the webhook endpoints.
* The API for create webhook supports headersTemplate parameter. Related
docs at
https://docs.apify.com/api/v2#tag/WebhooksWebhook-collection/operation/webhooks_post
* The API for update webhook supports headersTemplate parameter. Related
docs at
https://docs.apify.com/api/v2#tag/WebhooksWebhook-object/operation/webhook_put

---------

Co-authored-by: Jake Robers <jacob.robers@podium.com>
Co-authored-by: Vlada Dusek <v.dusek96@gmail.com>
  • Loading branch information
3 people authored Jul 16, 2024
1 parent c11edb8 commit 6dbd781
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## [1.7.2](../../releases/tag/v1.7.2) - Unreleased

...
### Add

- add `headers_template` kwarg to webhook create and update

## [1.7.1](../../releases/tag/v1.7.1) - 2024-07-11

Expand Down
8 changes: 8 additions & 0 deletions src/apify_client/clients/resource_clients/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def get_webhook_representation(
event_types: list[WebhookEventType] | None = None,
request_url: str | None = None,
payload_template: str | None = None,
headers_template: str | None = None,
actor_id: str | None = None,
actor_task_id: str | None = None,
actor_run_id: str | None = None,
Expand All @@ -35,6 +36,7 @@ def get_webhook_representation(
webhook: dict = {
'requestUrl': request_url,
'payloadTemplate': payload_template,
'headersTemplate': headers_template,
'ignoreSslErrors': ignore_ssl_errors,
'doNotRetry': do_not_retry,
'idempotencyKey': idempotency_key,
Expand Down Expand Up @@ -80,6 +82,7 @@ def update(
event_types: list[WebhookEventType] | None = None,
request_url: str | None = None,
payload_template: str | None = None,
headers_template: str | None = None,
actor_id: str | None = None,
actor_task_id: str | None = None,
actor_run_id: str | None = None,
Expand All @@ -95,6 +98,7 @@ def update(
event_types (list of WebhookEventType, optional): List of event types that should trigger the webhook. At least one is required.
request_url (str, optional): URL that will be invoked once the webhook is triggered.
payload_template (str, optional): Specification of the payload that will be sent to request_url
headers_template (str, optional): Headers that will be sent to the request_url
actor_id (str, optional): Id of the actor whose runs should trigger the webhook.
actor_task_id (str, optional): Id of the actor task whose runs should trigger the webhook.
actor_run_id (str, optional): Id of the actor run which should trigger the webhook.
Expand All @@ -111,6 +115,7 @@ def update(
event_types=event_types,
request_url=request_url,
payload_template=payload_template,
headers_template=headers_template,
actor_id=actor_id,
actor_task_id=actor_task_id,
actor_run_id=actor_run_id,
Expand Down Expand Up @@ -190,6 +195,7 @@ async def update(
event_types: list[WebhookEventType] | None = None,
request_url: str | None = None,
payload_template: str | None = None,
headers_template: str | None = None,
actor_id: str | None = None,
actor_task_id: str | None = None,
actor_run_id: str | None = None,
Expand All @@ -205,6 +211,7 @@ async def update(
event_types (list of WebhookEventType, optional): List of event types that should trigger the webhook. At least one is required.
request_url (str, optional): URL that will be invoked once the webhook is triggered.
payload_template (str, optional): Specification of the payload that will be sent to request_url
headers_template (str, optional): Headers that will be sent to the request_url
actor_id (str, optional): Id of the actor whose runs should trigger the webhook.
actor_task_id (str, optional): Id of the actor task whose runs should trigger the webhook.
actor_run_id (str, optional): Id of the actor run which should trigger the webhook.
Expand All @@ -221,6 +228,7 @@ async def update(
event_types=event_types,
request_url=request_url,
payload_template=payload_template,
headers_template=headers_template,
actor_id=actor_id,
actor_task_id=actor_task_id,
actor_run_id=actor_run_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def create(
event_types: list[WebhookEventType], # type: ignore
request_url: str,
payload_template: str | None = None,
headers_template: str | None = None,
actor_id: str | None = None,
actor_task_id: str | None = None,
actor_run_id: str | None = None,
Expand All @@ -66,6 +67,7 @@ def create(
event_types (list of WebhookEventType): List of event types that should trigger the webhook. At least one is required.
request_url (str): URL that will be invoked once the webhook is triggered.
payload_template (str, optional): Specification of the payload that will be sent to request_url
headers_template (str, optional): Headers that will be sent to the request_url
actor_id (str, optional): Id of the actor whose runs should trigger the webhook.
actor_task_id (str, optional): Id of the actor task whose runs should trigger the webhook.
actor_run_id (str, optional): Id of the actor run which should trigger the webhook.
Expand All @@ -84,6 +86,7 @@ def create(
event_types=event_types,
request_url=request_url,
payload_template=payload_template,
headers_template=headers_template,
actor_id=actor_id,
actor_task_id=actor_task_id,
actor_run_id=actor_run_id,
Expand Down Expand Up @@ -132,6 +135,7 @@ async def create(
event_types: list[WebhookEventType], # type: ignore
request_url: str,
payload_template: str | None = None,
headers_template: str | None = None,
actor_id: str | None = None,
actor_task_id: str | None = None,
actor_run_id: str | None = None,
Expand All @@ -150,6 +154,7 @@ async def create(
event_types (list of WebhookEventType): List of event types that should trigger the webhook. At least one is required.
request_url (str): URL that will be invoked once the webhook is triggered.
payload_template (str, optional): Specification of the payload that will be sent to request_url
headers_template (str, optional): Headers that will be sent to the request_url
actor_id (str, optional): Id of the actor whose runs should trigger the webhook.
actor_task_id (str, optional): Id of the actor task whose runs should trigger the webhook.
actor_run_id (str, optional): Id of the actor run which should trigger the webhook.
Expand All @@ -168,6 +173,7 @@ async def create(
event_types=event_types,
request_url=request_url,
payload_template=payload_template,
headers_template=headers_template,
actor_id=actor_id,
actor_task_id=actor_task_id,
actor_run_id=actor_run_id,
Expand Down

0 comments on commit 6dbd781

Please sign in to comment.