> 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/7fe613f4d3754bce8f3d95bfb2c037f7?sid=c732ef5b-3d2b-464f-9869-1ea897ea7dab).

## Code

Set your Polytomic API key as an environment variable:

```bash
export POLYTOMIC_API_KEY=YOUR-API-TOKEN
```

This example covers four steps:

1. Create a Snowflake Connection.
2. Create a Salesforce Connection.
3. Create a model over a custom Snowflake query.
4. Sync data from Snowflake into Salesforce.

## 1. Create a Snowflake Connection

The Snowflake instance must be reachable from Polytomic over the network. For details, see the [Snowflake connection guide](https://docs.polytomic.com/docs/snowflake-connections).

#### 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: 2025-09-18"  \
     --header "Authorization: Bearer ${POLYTOMIC_API_KEY}" \
     -d '{
     "name": "Snowflake Connection",
     "type": "snowflake",
     "configuration": {
        "account": "uc193736182",
        "username": "user",
        "password": "secret",
        "dbname": "database"
        }
    }'
```

#### Python

```python

import os
from polytomic.client import Polytomic

client = Polytomic(
    token=os.getenv("POLYTOMIC_API_KEY"),
)

resp = client.connections.create(
    name="Snowflake Connection",
    type="snowflake",
    configuration={
        "account": "uc193736182",
        "username": "user",
        "password": "secret",
        "dbname": "database"
     }
)

print(resp.data)
```

#### Typescript

```typescript
import { PolytomicClient } from 'polytomic';

const polytomic = new PolytomicClient({
  token: "POLYTOMIC_API_KEY",
});

polytomic.connections.create({
  name: "Snowflake Connection",
  type: "snowflake",
  configuration: {
     account: "uc193736182",
     username: "user",
     password: "secret",
     dbname: "database"
  },
}).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: "Snowflake Connection",
          Type: "snowflake",
          Configuration: map[string]any{
               "account":  "uc193736182",
               "username": "user",
               "password": "secret",
               "dbname":   "database",
          },
     },
)
if err != nil {
    panic(err)
}
fmt.Println(resp)
```

## 2. Create a Salesforce Connection

The following request creates a Salesforce Connection. See the [Salesforce connection configuration](/guides/configuring-your-connections/connections/salesforce) for the required fields.

#### 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: 2025-09-18"   \
     --header "Authorization: Bearer ${POLYTOMIC_API_KEY}"  \
     -d '{"name": "Salesforce Connection","type": "salesforce", "configuration": {"domain": "https://example.my.salesforce.com"}}'
```

#### Python

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

client = Polytomic(
    token=os.getenv("POLYTOMIC_API_KEY"),
)

resp = client.connections.create(
    name="Salesforce Connection",
    configuration={"domain": "https://example.my.salesforce.com"},
    type="salesforce"
)

print(resp.data)
```

#### Typescript

```typescript

import { PolytomicClient } from 'polytomic';

const polytomic = new PolytomicClient({
  token: "POLYTOMIC_API_KEY",
});

polytomic.connections.create({
  name: "Salesforce Connection",
  type: "salesforce",
  configuration: {
     domain: "https://example.my.salesforce.com"
  },

}).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:          "Salesforce Connection",
        Type:          "salesforce",
        Configuration: map[string]any{
          "domain": "https://example.my.salesforce.com",
        },
    },
)
if err != nil {
    panic(err)
}
fmt.Println(resp)
```

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

## 3. Create a Snowflake model

Create a model over a Snowflake query:

#### cURL

```bash
curl --request POST  \
     --url https://app.polytomic.com/api/models \
     --header "accept: application/json"  \
     --header "content-type: application/json"  \
     --header "X-Polytomic-Version: 2025-09-18"  \
     --header "Authorization: Bearer ${POLYTOMIC_API_KEY}"  \
     -d '{
           "name": "Active Users",
            "configuration": {
               "query": "SELECT MAX(last_activity_date) AS last_activity_date, plan, first_name, last_name, email FROM users GROUP BY plan, first_name, last_name, email",
            },
            "connection_id": "YOUR-SNOWFLAKE-CONNECTION-ID"
          }'
```

#### Python

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


client = Polytomic(
    token=os.getenv("POLYTOMIC_API_KEY"),
)

resp = client.models.create(
    name="Active Users",
    configuration={
        "query": "SELECT MAX(last_activity_date) AS last_activity_date, plan, first_name, last_name, email FROM users GROUP BY plan, first_name, last_name, email",
    },
    connection_id="YOUR-SNOWFLAKE-CONNECTION-ID"
)

print(resp.data)
```

#### Typescript

```typescript
import { PolytomicClient } from 'polytomic';


const polytomic = new PolytomicClient({
  token: "POLYTOMIC_API_KEY",
});


polytomic.models.create({
  name: "Active Users",
  configuration: {
    query: "SELECT MAX(last_activity_date) AS last_activity_date, plan, first_name, last_name, email FROM users GROUP BY plan, first_name, last_name, email",
  },
  connection_id: "YOUR-SNOWFLAKE-CONNECTION-ID",

}).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.Models.Create(
  context.TODO(),
  &polytomic.CreateModelRequest{
      Name: "Active Users",
      Configuration: map[string]any{
        "query": "SELECT MAX(last_activity_date) AS last_activity_date, plan, first_name, last_name, email FROM users GROUP BY plan, first_name, last_name, email",
      },
      ConnectionID: "YOUR-SNOWFLAKE-CONNECTION-ID",
  },
)
if err != nil {
    panic(err)
}
fmt.Println(resp)
```

> **Listing source objects**
>
> To enumerate the sources available on a Connection, see this [example](./model-sync-reverse-etl-from-mongo-db-to-salesforce).

## 4. Sync the Snowflake model into Salesforce

The sync maps `email`, `first_name`, and `last_name` from the Snowflake model onto the matching Salesforce Contact fields. Add more entries to the `fields` array to sync additional columns.

#### cURL

```bash
curl --request POST  \
     --url https://app.polytomic.com/api/syncs \
     --header "accept: application/json"  \
     --header "content-type: application/json"  \
     --header "X-Polytomic-Version: 2025-09-18"  \
     --header "Authorization: Bearer ${POLYTOMIC_API_KEY}"  \
     -d '{
          "name": "Snowflake to Salesforce Sync",
          "mode": "create",
          "identity": {
               "source": {
                    "field": "email",
                    "model_id": "YOUR-MODEL-ID"
               },
               "target": "Email",
               "function": "Equality"
           },
          "fields": [
               {
                    "source": {
                         "field": "first_name",
                         "model_id": "YOUR-MODEL-ID"
                    },
                    "target": "FirstName"
               },
               {
                    "source": {
                         "field": "last_name",
                         "model_id": "YOUR-MODEL-ID"
                    },
                    "target": "LastName"
               }
          ],
          "schedule": {
               "frequency": "continuous"
          },
          "target": {
               "connection_id": "YOUR-SALESFORCE-CONNECTION-ID",
               "object": "Contact"
          }
     }'
```

#### Python

```python

import os
from polytomic.client import Polytomic
from polytomic import SyncField, Source, Identity, Schedule, ScheduleFrequency, Target

client = Polytomic(
    token=os.getenv("POLYTOMIC_API_KEY"),
)

resp = client.model_sync.create(
     name="Snowflake to Salesforce Sync",
     mode="create",
     identity=Identity(
          source=Source(
               field= "email",
               model_id= "YOUR-MODEL-ID"
          ),
          target="Email",
          function="Equality"
     ),
     fields=[
          SyncField(
               source=Source(
               field="first_name",
               model_id="YOUR-MODEL-ID"
               ),
               target="FirstName",
          ),
          SyncField(
               source=Source(
               field="last_name",
               model_id="YOUR-MODEL-ID"
               ),
               target="LastName",
          ),
     ],
     schedule=Schedule(
          frequency=ScheduleFrequency.CONTINUOUS,
     ),
     target=Target(
          connection_id="YOUR-SALESFORCE-CONNECTION-ID",
          object="Contact"
     )
)

print(resp.data)
```

#### Typescript

```typescript
import { Polytomic, PolytomicClient } from 'polytomic';

const polytomic = new PolytomicClient({
  token: "POLYTOMIC_API_KEY",
});

polytomic.modelSync.create({
  name: "Snowflake to Salesforce Sync",
  mode: Polytomic.ModelsyncSyncTargetMode.Create,
  identity: {
    source: {
      field: "email",
      model_id: "YOUR-MODEL-ID"
    },
    target: "Email",
    function: Polytomic.SchemaIdentityFunction.Equality
  },
  fields: [
    {
      source: {
        field: "first_name",
        model_id: "YOUR-MODEL-ID"
      },
      target: "FirstName"
    },
    {
      source: {
        field: "last_name",
        model_id: "YOUR-MODEL-ID"
      },
      target: "LastName"
    }
  ],
  schedule: {
    frequency: Polytomic.ScheduleFrequency.Continuous
  },
  target: {
    connection_id: "YOUR-SALESFORCE-CONNECTION-ID",
    object: "Contact"
  }
}).then((resp) => {
  console.log(resp);
})
```

#### 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")),
)

object := "Contact"
resp, err := client.ModelSync.Create(
     context.TODO(),
     &polytomic.CreateSyncRequest{
          Name: "Snowflake to Salesforce Sync",
          Mode: polytomic.ModelsyncSyncTargetModeCreate,
          Identity: &polytomic.Identity{
               Source: &polytomic.Source{
                    Field:   "email",
                    ModelID: "YOUR-MODEL-ID",
               },
               Target:   "Email",
               Function: polytomic.SchemaIdentityFunctionEquality,
          },
          Fields: []*polytomic.SyncField{
               {
                    Source: &polytomic.Source{
                         Field:   "first_name",
                         ModelID: "YOUR-MODEL-ID",
                    },
                    Target: "FirstName",
               },
               {
                    Source: &polytomic.Source{
                         Field:   "last_name",
                         ModelID: "YOUR-MODEL-ID",
                    },
                    Target: "LastName",
               },
          },
          Schedule: &polytomic.Schedule{
               Frequency: polytomic.ScheduleFrequencyContinuous.Ptr(),
          },
          Target: &polytomic.Target{
               ConnectionID: "YOUR-SALESFORCE-CONNECTION-ID",
               Object:       &object,
          },
     },
)

if err != nil {
     panic(err)
}
fmt.Println(resp)
```