> This page is for version 2025-09-18 (default).
> For other versions, use one of these documentation indexes:
> - 2025-09-18 (default): https://apidocs.polytomic.com/2025-09-18/llms.txt
> - 2024-02-08: https://apidocs.polytomic.com/2024-02-08/llms.txt
> - 2023-04-25: https://apidocs.polytomic.com/2023-04-25/llms.txt
> - 2022-12-12: https://apidocs.polytomic.com/2022-12-12/llms.txt
> - 2021-05-23: https://apidocs.polytomic.com/2021-05-23/llms.txt

> 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/86b354bd790946b69d504379f0e7a58d?sid=bfc514d1-6c3c-4019-ba4e-0691552269cb).

## 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 MongoDB Connection.
2. Create a Salesforce Connection.
3. Create a model over the MongoDB database.
4. Sync data from MongoDB into Salesforce.

## 1. Create a MongoDB Connection

The following request creates a MongoDB Connection. See the [MongoDB connection configuration](/guides/configuring-your-connections/connections/mongodb) 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": "MongoDB Connection",
          "type": "mongodb", 
          "configuration": {
               "hosts": "example.mongodb.net",
               "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="MongoDB Connection",
    type="mongodb",
    configuration={
        "hosts": "example.mongodb.net",
        "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: "MongoDB Connection",
  type: "mongodb",
  configuration: {
     hosts: "example.mongodb.net",
     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:          "MongoDB Connection",
        Type:          "mongodb",
        Configuration: map[string]any{
               "hosts":    "example.mongodb.net",
               "username": "user",
               "password": "secret",
        },
    },
)
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",
    type="salesforce",
    configuration={
        "domain": "https://example.my.salesforce.com"
    }
)

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 MongoDB model

Create a model over a MongoDB collection:

#### 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": "MongoDB Model",
            "configuration": {
               "database": "example",
               "collection": "users"
            },
            "connection_id": "YOUR-MONGODB-CONNECTION-ID"
          }'
```

#### Python

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


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

resp = client.models.create(
    name="MongoDB Model",
    configuration={
        "database": "example",
        "collection": "users"
    },
    connection_id="YOUR-MONGODB-CONNECTION-ID"
)

print(resp.data)    
```

#### Typescript

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


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


polytomic.models.create({
  name: "MongoDB Model",
  configuration: {
     database: "example",
     collection: "users"
  },
  connection_id: "YOUR-MONGODB-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: "MongoDB Model",
          Configuration: map[string]any{
               "database":   "example",
               "collection": "users",
          },
          ConnectionID: "YOUR-MONGODB-CONNECTION-ID",
     },
)
if err != nil {
    panic(err)
}
fmt.Println(resp)
```

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

\


## 4. Sync the MongoDB model into Salesforce

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

> **Listing target objects**
>
> To discover the target objects available on a destination, use the [Get Sync Target Objects](/api-reference/model-sync/get-target-objects) endpoint.

\


#### 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": "Mongo 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="Mongo 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: "Mongo 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: "Mongo 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)
```