> ## 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 Mage

> Learn how to trigger syncs with Mage.ai.

## Overview

Mage provides a native `HightouchClient` to trigger Hightouch syncs. Check out the [Mage's integration documentation](https://docs.mage.ai/integrations/hightouch) for usage details.

## Setup

To use Mage to trigger syncs, you need a Hightouch API key.

### 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.

### Set sync schedule type

For the Mage 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 Mage, 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 Mage.

![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)

## Usage

You can then trigger a sync with Mage's `HightouchClient`:

```python theme={null}
from mage_ai.services.hightouch.hightouch import HightouchClient

client = HightouchClient(config=dict(api_key='api_key'))
syncs = client.list_syncs()      # Get all the syncs
sync_id = syncs['data'][0]['id'] # Get sync id
client.sync_and_poll(sync_id)    # Trigger sync and poll status
```

If successful, the output looks like this:

```bash theme={null}
Polling Hightouch Sync [id]. Current status: querying. 0% completed.
Polling Hightouch Sync [id]. Current status: success. 100% completed.
Sync request status: success. Polling complete
```
