> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://apidocs.polytomic.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://apidocs.polytomic.com/_mcp/server.

## UI demo video

Watch the same steps in the Polytomic admin console in this [demo video](https://www.loom.com/share/2195b632a9d9459f811fbe0388238e95?sid=01168066-619c-4dfb-8321-1ffc98d0abce).

## Code

Set your Polytomic API key as an environment variable:

```bash
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](/api-reference/connections/create) to HubSpot. See the [connection configuration reference](/guides/configuring-your-connections/overview) for the fields each Connection type accepts.

#### 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)
```

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

```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)
```

### Bulk sync schemas

\


> **Note**
>
> 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](/api-reference/bulk-sync/create) that replicates every HubSpot object 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"
          }
    	}'
```

#### Python

```python
import os
from polytomic.client import Polytomic
from polytomic import BulkSchedule


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="continuous",
    ),
    destination_configuration={
        "schema": "hubspot"
    }
)

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"
  }
}).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",
        },
    },
)
if err != nil {
    panic(err)
}
fmt.Println(resp)
```