> 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/code-examples/model-sync-from-salesforce-to-netsuite/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/98dd5597dc82464a97d607ce3b835a80?sid=4c7a7558-b341-4f63-af32-de682c2c3b49). ## Code Set your Polytomic API key as an environment variable: ```bash export POLYTOMIC_API_KEY=YOUR-API-TOKEN ``` This example covers five steps: 1. Create a Salesforce Connection. 2. Create a NetSuite Connection. 3. Verify the Connections are ready. 4. Create a Salesforce model. 5. Sync Salesforce Contacts to NetSuite, filtering out records with an empty `LastName`. ## 1. Create a Salesforce connection The following request creates a [Salesforce Connection](/guides/configuring-your-connections/connections/salesforce) through the [Create Connection](/api-reference/connections/create) endpoint. For end-user onboarding, prefer Polytomic Connect's [embedded auth](/guides/embedding-authentication). #### 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": "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]interface{}{ "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. ## 2. Create a NetSuite connection The following request creates a [NetSuite Connection](/guides/configuring-your-connections/connections/netsuite). #### 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": "NetSuite Connection","type": "netsuite", "configuration": { "account_id": "1234567_SB1", "consumer_key": "consumer_key", "consumer_secret": "secret", "token": "token", "token_secret": "token_secret"}}' ``` #### Python ```python import os from polytomic.client import Polytomic client = Polytomic( token=os.getenv("POLYTOMIC_API_KEY"), ) resp = client.connections.create( name="NetSuite Connection", configuration={ "account_id": "1234567_SB1", "consumer_key": "consumer_key", "consumer_secret": "secret", "token": "token", "token_secret": "token_secret", }, type="netsuite" ) print(resp.data) ``` #### Typescript ```typescript import { PolytomicClient } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.connections.create({ name: "NetSuite Connection", type: "netsuite", configuration: { account_id: "1234567_SB1", consumer_key: "consumer_key", consumer_secret: "secret", token: "token", token_secret: "token_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: "NetSuite Connection", Type: "netsuite", Configuration: map[string]interface{}{ "account_id": "1234567_SB1", "consumer_key": "consumer_key", "consumer_secret": "secret", "token": "token", "token_secret": "token_secret" }, }, ) if err != nil { panic(err) } fmt.Println(resp) ``` ## 3. Verify connection readiness Before syncing, poll the [Get Schema Status](/api-reference/schemas/get-status) endpoint for each Connection ID until `cache_status` is `true`. Once it is, the Connection's schema is ready to query. ## 4. Create a Salesforce source model Next, create a Salesforce model. A model is a view — a collection of fields you can sync to other systems in whole or in part. ### Listing source objects This example builds a model over the Salesforce `Contact` object. To list all Salesforce objects, call the [Get Sync Source](/api-reference/model-sync/get-source) endpoint with your Salesforce Connection ID. ### Listing fields on an object To see the fields available on a specific object, call the same [Get Sync Source](/api-reference/model-sync/get-source) endpoint with the query parameter `params[stream_id]=` — for example, `params[stream_id]=companies`. ### Create the model Create the source model with the [Create Model](/api-reference/models/create) endpoint: #### 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: 2024-02-08" \ --header "Authorization: Bearer ${POLYTOMIC_API_KEY}" \ -d '{ "name": "Salesforce Contacts", "configuration": { "table": "Contact" }, "connection_id": "YOUR-SALESFORCE-CONNECTION-ID" }' ``` #### Python ```python import os from polytomic.client import Polytomic client = Polytomic( token=os.getenv("POLYTOMIC_API_KEY"), ) resp = client.models.create( name="Salesforce Contacts", configuration={ "table": "Contact" }, connection_id="YOUR-SALESFORCE-CONNECTION-ID" ) print(resp.data) ``` #### Typescript ```typescript import { PolytomicClient } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.models.create({ name: "Salesforce Contacts", configuration: { table: "Contact" }, connection_id: "YOUR-SALESFORCE-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", p Configuration: map[string]interface{}{ "table": "Contact", }, ConnectionId: "YOUR-SALESFORCE-CONNECTION-ID", }, ) if err != nil { panic(err) } fmt.Println(resp) ``` ## 5. Sync Salesforce Contacts to NetSuite Contacts The sync maps `Email`, `FirstName`, and `LastName` from the Salesforce model onto the matching NetSuite Contact fields, and filters out records with an empty `LastName`. 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. ### Creating the sync Create the sync with the [Create Sync](/api-reference/model-sync/create) 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: 2024-02-08" \ --header "Authorization: Bearer ${POLYTOMIC_API_KEY}" \ -d '{ "name": "Salesforce to NetSuite Sync", "mode": "updateOrCreate", "identity": { "source": { "field": "Email", "model_id": "YOUR-MODEL-ID" }, "target": "email", "function": "equality" }, "fields": [ { "source": { "field": "FirstName", "model_id": "YOUR-MODEL-ID" }, "target": "firstName" }, { "source": { "field": "LastName", "model_id": "YOUR-MODEL-ID" }, "target": "lastName" } ], "schedule": { "frequency": "continuous" }, "target": { "connection_id": "YOUR-NETSUITE-CONNECTION-ID", "object": "contact" }, "filters": [ { "field_id": "YOUR-LASTNAME-FIELD-ID", "field_type": "Model", "function": "IsNotNull" } ] }' ``` #### Python ```python import os from polytomic.client import Polytomic from polytomic import ModelSyncField, Source, Identity, Schedule, ScheduleFrequency, Target client = Polytomic( token=os.getenv("POLYTOMIC_API_KEY"), ) resp = client.model_sync.create( name="Salesforce to NetSuite Sync", mode="updateOrCreate", identity=Identity( source=Source(field="Email", model_id="YOUR-MODEL-ID"), target="email", function="equality", ), fields=[ ModelSyncField( source=Source(field="FirstName", model_id="YOUR-MODEL-ID"), target="firstName", ), ModelSyncField( source=Source(field="LastName", model_id="YOUR-MODEL-ID"), target="lastName", ), ], schedule=Schedule( frequency=ScheduleFrequency.CONTINUOUS, ), target=Target(connection_id="YOUR-NETSUITE-CONNECTION-ID", object="contact"), filters=[ Filter( field_id="YOUR-LASTNAME-FIELD-ID", function="IsNotNull", field_type="Model", ) ], ) print(resp.data) ``` #### Typescript ```typescript import { Polytomic, PolytomicClient } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.modelSync.create({ name: "Salesforce to NetSuite Sync", mode: "updateOrCreate", identity: { source: { field: "Email", model_id: "YOUR-MODEL-ID" }, target: "email", function: "equality" }, fields: [ { source: { field: "FirstName", model_id: "YOUR-MODEL-ID" }, target: "firstName" }, { source: { field: "LastName", model_id: "YOUR-MODEL-ID" }, target: "lastName" } ], schedule: { frequency: Polytomic.ScheduleFrequency.Continuous }, target: { connection_id: "YOUR-NETSUITE-CONNECTION-ID", object: "contact" }, filters: [ { field_id: "YOUR-LASTNAME-FIELD-ID", field_type: "Model", function: "IsNotNull" } ], }).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")), ) resp, err := client.ModelSync.Create( context.TODO(), &polytomic.CreateModelSyncRequest{ Name: "Salesforce to NetSuite Sync", Identity: &polytomic.Identity{ Source: &polytomic.Source{ Field: "Email", ModelId: "YOUR-MODEL-ID", }, Target: "email", Function: "Equality", }, Mode: "updateOrCreate", Fields: []*polytomic.ModelSyncField{ { Source: &polytomic.Source{ Field: "FirstName", ModelId: "YOUR-MODEL-ID", }, Target: "firstName", }, { Source: &polytomic.Source{ Field: "LastName", ModelId: "YOUR-MODEL-ID", }, Target: "lastName", }, }, Schedule: &polytomic.Schedule{ Frequency: pointer.ToString(string(polytomic.ScheduleFrequencyContinuous)), }, Target: &polytomic.Target{ ConnectionId: "YOUR-NETSUITE-CONNECTION-ID", Object: "contact", }, Filters: []*polytomic.Filter{ { FieldId: "YOUR-LASTNAME-FIELD-ID", Function: "IsNotNull", FieldType: "Model", }, }, }, ) if err != nil { panic(err) } fmt.Println(resp) ```