Bulk sync (ELT) from HubSpot to PostgreSQL

UI demo video

Watch the same steps in the Polytomic admin console in this demo video.

Code

Set your Polytomic API key as an environment variable:

$export POLYTOMIC_API_KEY=YOUR-API-TOKEN

This example covers three steps:

  1. Create a HubSpot Connection.
  2. Create a PostgreSQL Connection.
  3. Load data from HubSpot into PostgreSQL.

1. Create a HubSpot connection

The following request creates a Connection to HubSpot. See the connection configuration reference for the fields each Connection type accepts.

$curl --request POST \
> --url https://app.polytomic.com/api/connections \
> --header "accept: application/json" \
> --header "content-type: application/json" \
> --header "X-Polytomic-Version: 2024-02-08" \
> --header "Authorization: Bearer ${POLYTOMIC_API_KEY}" \
> -d '{"name": "Hubspot Connection","type": "hubspot", "configuration": {}}'

HubSpot Connections authenticate with OAuth. Open the URL returned in the auth_url field of the response to complete the flow.

OAuth redirection

By default, the API expects auth_url to open in a new browser window. Set the optional redirect_url parameter in the request body to change the redirect target.

2. Create a PostgreSQL connection

The PostgreSQL server must be network-accessible from Polytomic.

$ curl --request POST \
> --url https://app.polytomic.com/api/connections \
> --header "accept: application/json" \
> --header "content-type: application/json" \
> --header "X-Polytomic-Version: 2024-02-08" \
> --header "Authorization: Bearer ${POLYTOMIC_API_KEY}" \
> -d '{
> "name": "Postgres Connection",
> "type": "postgresql",
> "configuration": {
> "hostname": "localhost",
> "port": 5432,
> "database": "postgres",
> "username": "user",
> "password": "secret"
> }
> }'

Bulk sync schemas


Polytomic may take a few moments to cache source schemas after a new Connection is created.

3. Create a Bulk Sync

The following request creates a Bulk Sync that replicates every HubSpot object into Postgres:

$curl --request POST \
> --url https://app.polytomic.com/api/bulk/syncs \
> --header "accept: application/json" \
> --header "content-type: application/json" \
> --header "X-Polytomic-Version: 2024-02-08" \
> --header "Authorization: Bearer ${POLYTOMIC_API_KEY}" \
> -d '{
> "name": "Hubspot Bulk Sync",
> "source_connection_id": "YOUR-HUBSPOT-CONNECTION-ID",
> "destination_connection_id": "YOUR-POSTGRES-CONNECTION-ID",
> "mode": "replicate",
> "schedule": {
> "frequency": "continuous"
> },
> "destination_configuration": {
> "schema": "hubspot"
> }
> }'