# Source: https://docs.apify.com/platform/integrations/kestra.md

# Kestra integration

**Connect Apify with Kestra to orchestrate workflows — run flows, extract structured data, and react to Actor or task events.**

***

[Kestra](https://kestra.io/) is an open-source, event-driven orchestration platform. The [Apify plugin for Kestra](https://github.com/kestra-io/plugin-kestra) connects Apify Actors and storage to your workflows. Run scrapers, extract structured data — all defined declaratively in YAML and orchestrated directly from the UI.

This guide shows you how to set up the integration, configure authentication, and create a workflow that runs an Actor and processes its results.

## Prerequisites

Before you begin, make sure you have:

* An [Apify account](https://console.apify.com/)
* A [Kestra instance](https://kestra.io/docs/getting-started/quickstart) (self‑hosted or cloud)

## Authentication

The Apify plugin uses API key authentication. Store your API key in [Kestra Secrets](https://kestra.io/docs/concepts/secret) through the UI or environment variables. In the open-source version, manage Secrets using base64-encoded environment variables. You can also use [Kestra's KV Store](https://kestra.io/docs/concepts/kv-store) to persist API keys across executions and workflows.

To add your Apify API token, go to the Secrets section in the Kestra UI and create a new secret with the key `APIFY_API_KEY` and your token as the value.

## Use Apify Tasks as an action

Tasks allow you to perform operations like running an Actor within a workflow.

1. Create a new flow.

2. Inside the **Flow code** tab change the hello task's type to be **io.kestra.plugin.apify.actor.Run**.

3. Change the task's id to be **run\_apify\_actor**

4. Remove the message property.

5. Configure the **run\_apify\_actor** task by adding your required values for the properties listed below:

   <!-- -->

   * **actorId**: Actor ID or a tilde-separated owner's username and Actor name.
   * **apiToken**: A reference to the secret value you set up earlier. For example "{{secret(namespace=flow\.namespace, key='APIFY\_API\_KEY')}}"

6. Add a new task below the **run\_apify\_actor** with an ID of **get\_dataset** and a type of **io.kestra.plugin.apify.dataset.Get**.:

7. Configure the **get\_dataset** to fetch the dataset generated by the **run\_apify\_actor** task by configuring the following values:

   <!-- -->

   * **datasetId**: The ID of the dataset to fetch. You can use the value from the previous task using the following syntax: "{{secret(namespace=flow\.namespace, key='APIFY\_API\_KEY')}}"
   * **input**: Input for the Actor run. The input is optional and can be used to pass data to the Actor. For our example we will add 'hashtags: \["fyp"]'
   * **maxItems**: The maximum number of items to fetch from the dataset. For our example we will set this to 5.

8. Now add the final task to log the output of the dataset. Add a new task below the **log\_output** with an ID of **log\_output** and a type of **io.kestra.plugin.core.log.Log**.

9. Configure the **log\_output** task to log the output of the dataset by configuring the following values:
   <!-- -->
   * **message**: The message to log. You can use the value from the previous task using the following syntax: '{{outputs.get\_dataset.dataset}}'

10. Now save and run your flow.

Your completed template should match the template below.


```
id: run_actor_and_fetch_dataset
namespace: company.team

tasks:
    - id: run_actor
      type: io.kestra.plugin.apify.actor.Run
      actorId: GdWCkxBtKWOsKjdch
      maxItems: 5
      input:
          hashtags: ["fyp"]
      apiToken: "{{secret(namespace=flow.namespace, key='APIFY_API_KEY')}}"
    - id: log_get_last_run_results
      type: io.kestra.plugin.core.log.Log
      message: '{{outputs.run_actor}}'
    - id: get_data_set_raw
      type: io.kestra.plugin.apify.dataset.Get
      datasetId: '{{outputs.run_actor.defaultDatasetId}}'
      apiToken: "{{secret(namespace=flow.namespace, key='APIFY_API_KEY')}}"
    - id: log_get_data_set_raw_results
      type: io.kestra.plugin.core.log.Log
      message: '{{outputs.get_data_set_raw}}'
```


## Resources

* [Kestra Apify Plugin](https://kestra.io/plugins/plugin-apify)
* [Apify API Documentation](https://docs.apify.com)
* [Kestra Documentation](https://kestra.io/docs)

## Troubleshooting

If you encounter issues, start by double-checking basics.

* **Authentication errors**: Verify your API token in [Secrets](https://kestra.io/docs/concepts/secret).
* **Operation failures**: Check input parameters, YAML syntax, and resource IDs in your Apify account.

Feel free to explore other resources and contribute to the integration on [GitHub](https://github.com/kestra-io/plugin-apify).