> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://apidocs.polytomic.com/2024-02-08/guides/quickstart/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://apidocs.polytomic.com/_mcp/server. This quickstart guide illustrates an end-to-end example of setting up a Polytomic sync from HubSpot to a PostgreSQL database. ## Setup Generate an API key in your [user settings panel](https://app.polytomic.com/settings/user). For more information, see the [authentication section](./obtaining-api-keys). ## Making API Requests Set the API token as an environment variable: ```text export POLYTOMIC_API_KEY=YOUR-API-TOKEN ``` Replace `YOUR-API-TOKEN` with the token you just generate in the step above. Make a request to the identity endpoint: #### cURL ```bash curl --request GET \ --url https://app.polytomic.com/api/me \ --header "accept: application/json" \ --header "X-Polytomic-Version: 2024-02-08" \ --header "Authorization: Bearer ${POLYTOMIC_API_KEY}" ``` #### Python ```python import os from polytomic.client import Polytomic client = Polytomic( token=os.getenv("POLYTOMIC_API_KEY"), ) resp = client.identity.get() print(resp.data) ``` #### Typescript ```typescript import { PolytomicClient } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.identity.get().then((res) => { console.log(res) }) ``` #### Go ```golang import ( "context" "fmt" polytomic "github.com/polytomic/polytomic-go" polytomicgoclient "github.com/polytomic/polytomic-go/client" "github.com/polytomic/polytomic-go/option" ) client := polytomicgoclient.NewClient( option.WithToken(os.Getenv("POLYTOMIC_API_TOKEN")), ) resp, err := client.Identity.Get(context.TODO()) if err != nil { panic(err) } fmt.Println(resp) ``` ## 1. Create a HubSpot connection The following request will create a Hubspot connection. The configuration for each type of connection can be found at the connection configuration docs page. #### cURL ```bash 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": {}}' ``` #### Python ```python import os from polytomic.client import Polytomic client = Polytomic( token=os.getenv("POLYTOMIC_API_KEY"), ) resp = client.connections.create( name="Hubspot Connection", configuration={}, type="hubspot" ) print(resp.data) ``` #### Typescript ```typescript import { PolytomicClient } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.connections.create({ name: "Hubspot Connection", type: "hubspot", configuration: {}, }).then((res) => { console.log(res) }) ``` #### Go ```golang import ( "context" "fmt" polytomic "github.com/polytomic/polytomic-go" polytomicgoclient "github.com/polytomic/polytomic-go/client" "github.com/polytomic/polytomic-go/option" ) client := polytomicgoclient.NewClient( option.WithToken(os.Getenv("POLYTOMIC_API_TOKEN")), ) resp, err := client.Connections.Create( context.TODO(), &polytomic.CreateConnectionRequestSchema{ Name: "Hubspot Connection", Type: "hubspot", Configuration: map[string]interface{}{}, }, ) if err != nil { panic(err) } fmt.Println(resp) ``` Since Hubspot connections use OAuth to authenticate, you must follow the link returned in the `auth_url` parameter in the response. #### Redirection \ > **Note** > > By default, the API expects the `auth_url` to be open in a new browser window. If you'd like to modify the redirect behavior, there is an optional `redirect_url` parameter that can be added to the request body. ## 2. Create a PostgreSQL connection The PostgreSQL server must be network-accessible from Polytomic. #### cURL ```bash 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" } }' ``` #### Python ```python import os from polytomic.client import Polytomic client = Polytomic( token=os.getenv("POLYTOMIC_API_KEY"), ) resp = client.connections.create( name="Postgres Connection", type="postgresql", configuration={ "hostname": "localhost", "port": 5432, "database": "postgres", "username": "user", "password": "secret" }) print(resp.data) ``` #### Typescript ```typescript import { PolytomicClient } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.connections.create({ name: "Postgres Connection", type: "postgresql", configuration: { hostname: "localhost", port: 5432, database: "postgres", username: "user", password: "secret" }, }).then((res) => { console.log(res) }) ``` #### Go ```golang import ( "context" "fmt" polytomic "github.com/polytomic/polytomic-go" polytomicgoclient "github.com/polytomic/polytomic-go/client" "github.com/polytomic/polytomic-go/option" ) client := polytomicgoclient.NewClient( option.WithToken(os.Getenv("POLYTOMIC_API_TOKEN")), ) resp, err := client.Connections.Create( context.TODO(), &polytomic.CreateConnectionRequestSchema{ Name: "Postgres Connection", Type: "postgresql", Configuration: map[string]interface{}{ "hostname": "localhost", "port": 5432, "database": "postgres", "username": "user", "password": "secret", }, }, ) if err != nil { panic(err) } fmt.Println(resp) ``` > **Note** > > Source objects may not be immediately readable after creating a connection; Polytomic may take a few moments to cache source schemas after creating a connections. ## 3. Create a bulk sync This will create a bulk sync of all Hubspot objects into Postgres: #### cURL ```bash 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" }, "schemas": ["contacts", "companies", "deals"] }' ``` #### Python ```python import os from polytomic.client import Polytomic from polytomic import BulkSchedule, ScheduleFrequency client = Polytomic( token=os.getenv("POLYTOMIC_API_KEY"), ) resp = client.bulk_sync.create( name="Hubspot Bulk Sync", source_connection_id="YOUR-HUBSPOT-CONNECTION-ID", destination_connection_id="YOUR-POSTGRES-CONNECTION-ID", mode="replicate", schedule=BulkSchedule( frequency=ScheduleFrequency.CONTINUOUS, ), destination_configuration={ "schema": "hubspot" }, schemas=["contacts", "companies", "deals"] ) print(resp.data) ``` #### Typescript ```typescript import { PolytomicClient, Polytomic } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.bulkSync.create({ name: "Hubspot Bulk Sync", source_connection_id: "YOUR-HUBSPOT-CONNECTION-ID", destination_connection_id: "YOUR-POSTGRES-CONNECTION-ID", mode: "replicate", schedule: { frequency: Polytomic.ScheduleFrequency.Continuous, }, destination_configuration: { schema: "hubspot" }, schemas: ["contacts", "companies", "deals"] }).then((res) => { console.log(res) }) ``` #### Go ```golang import ( "context" "fmt" "github.com/AlekSi/pointer" polytomic "github.com/polytomic/polytomic-go" polytomicgoclient "github.com/polytomic/polytomic-go/client" "github.com/polytomic/polytomic-go/option" ) client := polytomicgoclient.NewClient( option.WithToken(os.Getenv("POLYTOMIC_API_TOKEN")), ) resp, err := client.BulkSync.Create( context.TODO(), &polytomic.CreateBulkSyncRequest{ Name: "Hubspot Bulk Sync", SourceConnectionId: "YOUR-HUBSPOT-CONNECTION-ID", DestinationConnectionId: "YOUR-POSTGRES-CONNECTION-ID", Mode: pointer.ToString("replicate"), Schedule: &polytomic.BulkSchedule{ Frequency: polytomic.ScheduleFrequency("continuous"), }, DestinationConfiguration: map[string]interface{}{ "schema": "hubspot", }, Schemas: []string{"contacts", "companies", "deals"}, }, ) if err != nil { panic(err) } fmt.Println(resp) ```