Sync data with Hightouch

Hightouch makes it easy to collect, prepare, and sync your data into any ad platform, CRM, email tool and more. No engineering, manual work, or costly traditional CDP required.

With Python Actions, Y42 enables programmatic triggering of Hightouch syncs via its API.

Create Sync in Hightouch

Syncs establish connections between your Data Warehouse sources and Destination Services. For detailed information, refer to the Hightouch documentation (opens in a new tab).

Add a new sync or use an existing one. Choose as source for the Sync, one of the tables published by Y42 in your data warehouse.

Sync between BigQuery table and Google Sheets.

Sync between BigQuery table and Google Sheets.

Trigger Sync via its API

You can trigger each sync programmatically through its API. The sync configuration page provides the trigger API endpoint.

To initiate the sync, use the following POST request format, as documented here (opens in a new tab):


_10
https://api.hightouch.com/api/v1/syncs/{syncId}/trigger

Store the API Token as a Secret in Y42

To trigger a sync programmatically in Hightouch, you must authenticate your request using headers that include a bearer token. This token is obtained from your Hightouch API keys.

Steps to create an API Token in Hightouch:

  • Navigate to Settings in the Hightouch UI.
  • Select API keys.
  • Click on Add API key to generate a new token. For more detailed instructions on generating and managing API keys, refer to the Hightouch documentation here (opens in a new tab).

You can securely store API tokens (or any other secrets) within Y42 using the Secrets menu.

Store the API Token as a Secret in Y42.

Store the API Token as a Secret in Y42.

Create Python Action asset

  1. Create the Python Action asset: Use the POST request method outlined earlier and reference the API Token from the Secrets vault.
trigger_sync_to_hightouch.py

_35
import json
_35
import requests
_35
from requests.exceptions import ConnectionError
_35
_35
from y42.v1.decorators import data_action
_35
import logging
_35
_35
@data_action
_35
def trigger_sync_to_hightouch(context, assets):
_35
_35
api_token = context.secrets.get('hightouch_api_token')
_35
bearer_token = f'Bearer {api_token}'
_35
_35
sync_id = '567890'
_35
_35
url = f'https://api.hightouch.com/api/v1/syncs/{sync_id}/trigger'
_35
_35
header = {'Authorization': bearer_token,
_35
'Content-Type': 'application/json'}
_35
json_obj = {
_35
"resetCDC": "false",
_35
"fullResync": "false"
_35
}
_35
_35
response = requests.post(url, json=json_obj, headers=header)
_35
_35
# log the response from your POST request
_35
logging.info(response.status_code)
_35
response_payload = json.loads(response.text)
_35
_35
# throw error when job was not triggered successfully
_35
if response_payload['status'] == 'error':
_35
raise ConnectionError(f"Triggering the job {response_payload['data']['sync_run_id']} failed with error: {response_payload['message']}")
_35
else:
_35
logging.info(response_payload)

  1. Specify an upstream dependency (Optional, but recommended): In the Dependencies tab, you can specify an upstream dependency for the Python asset. This dependency acts as a trigger, activating the Python Action to synchronize data with a third-party application upon the successful completion of the upstream asset.

It's often practical to select the source table, which was utilized to establish the Sync, as the dependency.

Specify an upstream dependency to act as the trigger for the Python asset.

Specify an upstream dependency to act as the trigger for the Python asset.

Build asset

Build the asset using dag selectors or via the Build history tab.

trigger_exposure

_10
y42 build -s +exposure:trigger_sync_to_hightouch

The + selector, when used in front of the asset name in the command, also triggers all upstream dependencies.

Build history tab.

Build history tab.

Verify Sync status in Hightouch

After returning to the Hightouch interface, the sync should be activated, having data to flowing to your configured destination. Congrats! 🎉

Sync successfully triggered.

Sync successfully triggered.