> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hightouch.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Trigger syncs with Airflow

> Learn how to trigger syncs with Hightouch's Airflow Operator.

## Overview

Hightouch provides an [Airflow Operator](https://airflow.apache.org/docs/apache-airflow/stable/concepts.html#operators) for triggering syncs via Airflow. The [Git repository](https://github.com/hightouchio/airflow-provider-hightouch) contains the latest code as well as [example DAGs](https://github.com/hightouchio/airflow-provider-hightouch#examples) to help you get started.

## Setup

### Create an API key

The first step is to create a Hightouch API key in your Hightouch workspace settings.

1. From the [**API keys** tab](https://app.hightouch.com/settings/api-keys?from=docs) on the **Settings** page, click **Add API key**.
2. Enter a descriptive **Name** for your key.
3. Under **User group**, select the group whose permissions the key should have in this workspace, or select **All of the creator's groups** to give the key the same permissions as you.
4. Copy your **API key** and store it in a safe location. The key is only displayed once.
5. Click **Create API key**.

> [!WARNING]
>
> Your API key provides read/write access to sensitive Hightouch resources and should be kept secure. If you believe your API key may have been compromised, [revoke it](https://docs.hightouch.com/developer-tools/api-guide.md#revoke-an-api-key) immediately.

### Add the Airflow connection

1. In Airflow, create a new connection by going to **Admin > Connections** and clicking the **+** button to add a new connection.
2. Enter `hightouch_default` as the **Conn ID**, select **HTTP** as the **Conn Type**, and set the host to `https://api.hightouch.com`. Optionally, enter a **Description**.
3. Enter the **API key** you created in the **Password** field.

![Adding a connection in the Airflow UI](https://mintcdn.com/hightouch-3c037897/L_vQfA0JQEpeGUUo/images/integrations/airflow-add-connection.png?fit=max\&auto=format\&n=L_vQfA0JQEpeGUUo\&q=85\&s=489ce4ba8ef056488c80edb3e73eb675)

### Set sync schedule type

For the Airflow extension to trigger syncs via the Hightouch API, you must set the syncs' [schedules](https://docs.hightouch.com/syncs/schedule-sync-ui.md) to **Manual**.

You can do this by going to the [**Syncs** overview page](https://app.hightouch.com/syncs), selecting the particular sync you want to trigger with Airflow, and opening the **Schedule** tab. Here, make sure the **Schedule type** is set to **Manual**. You should do this for each sync you want to trigger with Airflow.

![Manual sync Hightouch UI](https://mintcdn.com/hightouch-3c037897/L_vQfA0JQEpeGUUo/images/syncs/manual-schedule.png?fit=max\&auto=format\&n=L_vQfA0JQEpeGUUo\&q=85\&s=760a7361e91e628d1a7d3ab6c7d1d7d1)

You can also find the sync ID on this page, which you need for scheduling syncs in the next step.

![A sync ID in the Hightouch UI](https://mintcdn.com/hightouch-3c037897/L_vQfA0JQEpeGUUo/images/syncs/sync-id.png?fit=max\&auto=format\&n=L_vQfA0JQEpeGUUo\&q=85\&s=e20f6ca1ba141dee298ec3010739eb83)

### Install the Airflow package

While the details will vary for your particular Airflow installation, the simplest way to install our package is through pip.

```bash theme={null}
pip install airflow-provider-hightouch
```

### Add the HightouchTriggerSyncOperator to your DAG

The last step is to add the operator to a DAG and enter the sync ID of the sync you want to trigger. When the task is run, Airflow sends a call to the Hightouch API to trigger a run which completes asynchronously.

Alternatively, you can choose to send a synchronous request and await the results of the sync before completing the task.

For a full description of the operator parameters, [view the source code in the GitHub repository](https://github.com/hightouchio/airflow-provider-hightouch/blob/main/airflow_provider_hightouch/operators/hightouch.py).

```python theme={null}
from airflow_provider_hightouch.operators.hightouch \
    import HightouchTriggerSyncOperator

with DAG(....) as dag:
...
    # This task submits the request but doesn't wait for completion of the sync before completing.
    my_async_task = HightouchTriggerSyncOperator(
        task_id="run_my_sync", sync_id=1234
        )

    # This task waits for the sync status to complete or error before completing.
    # Warnings can be treated as errors or successes depending on your use case.
    my_sync_task = HightouchTriggerSyncOperator(
        task_id="run_sync", sync_id=1234, synchronous=True, error_on_warning=True
    )

```
