Model sync (Reverse ETL) from Snowflake query to Salesforce
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 four steps:
- Create a Snowflake Connection.
- Create a Salesforce Connection.
- Create a model over a custom Snowflake query.
- 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.
cURL
Python
Typescript
Go
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"}}'
import osfrom polytomic.client import Polytomicclient = 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)
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)})
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 for the required fields.
cURL
Python
Typescript
Go
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"}}'
import osfrom polytomic.client import Polytomicclient = 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)
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)})
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.
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
Python
Typescript
Go
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"}'
import osfrom polytomic.client import Polytomicclient = 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)
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)})
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)
To enumerate the sources available on a Connection, see this example.
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
Python
Typescript
Go
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"}}'
import osfrom polytomic.client import Polytomicfrom polytomic import SyncField, Source, Identity, Schedule, ScheduleFrequency, Targetclient = 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)
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);})
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)
