Skip to content

Latest commit

 

History

History
34 lines (22 loc) · 1.9 KB

File metadata and controls

34 lines (22 loc) · 1.9 KB
id webhooks
title Creating webhooks
description Set up webhooks to trigger actions when Actor run events occur.

import RunnableCodeBlock from '@site/src/components/RunnableCodeBlock';

import WebhookExample from '!!raw-loader!roa-loader!./code/07_webhook.py'; import WebhookPreventingExample from '!!raw-loader!roa-loader!./code/07_webhook_preventing.py';

Webhooks allow you to configure the Apify platform to perform an action when a certain event occurs. For example, you can use them to start another Actor when the current run finishes or fails.

You can learn more in the documentation for webhooks.

Creating an ad-hoc webhook dynamically

Besides creating webhooks manually in Apify Console, or through the Apify API, you can also create ad-hoc webhooks dynamically from the code of your Actor using the Actor.add_webhook method:

{WebhookExample}

Note that webhooks are only supported when running on the Apify platform. When running the Actor locally, the method will print a warning and have no effect.

Preventing duplicate webhooks

To ensure that duplicate ad-hoc webhooks won't get created in a case of Actor restart, you can use the idempotency_key parameter. The idempotency key must be unique across all the webhooks of a user so that only one webhook gets created for a given value. You can use, for example, the Actor run ID as the idempotency key:

{WebhookPreventingExample}

For more information about webhooks, including event types and payloads, see the Apify webhooks documentation.