> 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/syncing-contacts-from-google-cloud-storage-to-salesforce/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://apidocs.polytomic.com/_mcp/server. ## 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 Google Cloud Storage connection. 3. Verify the connections are ready. 4. Create a model over a Google Cloud Storage CSV file. 5. Sync the model to Salesforce Contacts. ## 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 Google Cloud Storage connection The following request creates a [Google Cloud Storage Connection](/guides/configuring-your-connections/connections/google-cloud-storage#configuration). #### 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": "Google Cloud Storage Connection","type": "gcs", "configuration": { "service_account": "service_account_json_key", "bucket": "gcs://mybucket/mypath"}}' ``` #### Python ```python import os from polytomic.client import Polytomic client = Polytomic( token=os.getenv("POLYTOMIC_API_KEY"), ) resp = client.connections.create( name="Google Cloud Storage Connection", type="gcs", configuration={ "service_account": "service_account_json_key", "bucket": "gcs://mybucket/mypath" }, ) print(resp.data) ``` #### Typescript ```typescript import { PolytomicClient } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.connections.create({ name: "Google Cloud Storage Connection", type: "gcs", configuration: { service_account: "service_account_json_key", bucket: "gcs://mybucket/mypath" }, }).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: "Google Cloud Storage Connection", Type: "gcs", Configuration: map[string]interface{}{ "service_account": "service_account_json_key", "bucket": "gcs://mybucket/mypath" }, }, ) 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 source model over the GCS CSV Next, create a model over a CSV file in Google Cloud Storage (GCS). A model is a view — a collection of fields you can sync to other systems in whole or in part. Call the [Create Model](/api-reference/models/create) endpoint to expose every column in `high_paying_users.csv`: #### 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": "GCS Contacts", "configuration": { "model_from": "single_file", "key": "high_paying_users.csv" }, "connection_id": "YOUR_GCS_CONNECTION_ID" }' ``` #### Python ```python import os from polytomic.client import Polytomic client = Polytomic( token=os.getenv("POLYTOMIC_API_KEY"), ) resp = client.models.create( name="GCS Contacts", configuration={ "model_from": "single_file", "key": "high_paying_users.csv" }, connection_id="YOUR_GCS_CONNECTION_ID" ) print(resp.data) ``` #### Typescript ```typescript import { PolytomicClient } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.models.create({ name: "GCS Contacts", configuration: { model_from: "single_file", key: "high_paying_users.csv" }, connection_id: "YOUR_GCS_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{}{ "model_from": "single_file", "key": "high_paying_users.csv" }, ConnectionId: "YOUR_GCS_CONNECTION_ID", }, ) if err != nil { panic(err) } fmt.Println(resp) ``` ## 5. Sync the GCS model to Salesforce Contacts The sync maps `email` on the GCS model to the `Email` field on Salesforce Contacts, and also maps `first_name` and `last_name`. 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": "GCS to Salesforce Sync", "mode": "updateOrCreate", "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": "Manual" }, "target": { "connection_id": "YOUR_SALESFORCE_CONNECTION_ID", "object": "Contact" } }' ``` #### 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="GCS to Salesforce Sync", mode="updateOrCreate", identity=Identity( source=Source(field="email", model_id="YOUR_MODEL_ID"), target="Email", function="equality", ), fields=[ ModelSyncField( source=Source(field="first_name", model_id="YOUR_MODEL_ID"), target="FirstName", ), ModelSyncField( source=Source(field="LastName", model_id="YOUR_MODEL_ID"), target="LastName", ), ], schedule=Schedule( frequency=ScheduleFrequency.MANUAL, ), 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: "GCS to Salesforce Sync", mode: "updateOrCreate", 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: Polytomic.ScheduleFrequency.Manual }, 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")), ) resp, err := client.ModelSync.Create( context.TODO(), &polytomic.CreateModelSyncRequest{ Name: "GCS to Salesforce 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: "first_name", ModelId: "YOUR_MODEL_ID", }, Target: "FirstName", }, { Source: &polytomic.Source{ Field: "last_name", ModelId: "YOUR_MODEL_ID", }, Target: "LastName", }, }, Schedule: &polytomic.Schedule{ Frequency: pointer.ToString(string(polytomic.ScheduleFrequencyManual)), }, Target: &polytomic.Target{ ConnectionId: "YOUR_SALESFORCE_CONNECTION_ID", Object: "Contact", } } ) if err != nil { panic(err) } fmt.Println(resp) ```