> 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. ## 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 webhook Connection. 2. Create a Google Cloud Storage Connection. 3. Verify the Connection is ready. 4. Create a model over a Google Cloud Storage CSV file. 5. Sync the model to your webhook. ## 1. Create a webhook connection Create the webhook Connection through Polytomic Connect's [embedded authentication](/guides/embedding-authentication) or the [Create Connection](/api-reference/connections/create) endpoint. See the [webhook configuration reference](/guides/configuring-your-connections/connections/webhook#configuration) for the required fields. ## 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": "${GOOGLE_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": "GOOGLE_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: "GOOGLE_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": "GOOGLE_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 your Google Cloud Storage Connection ID until `cache_status` is `true`. Once it is, the Connection is ready to use. ## 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 the webhook The sync sends `email`, `first_name`, and `last_name` from the GCS model to the webhook. Add more entries to the `fields` array to sync additional columns. 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 "Authorization: Bearer ${POLYTOMIC_API_KEY}" \ -d '{ "name": "Sync GCS to Webhook", "active": true, "mode": "updateOrCreate", "fields": [ { "source": { "field": "email_address", "model_id": "YOUR_MODEL_ID" }, "target": "record" }, { "source": { "field": "first_name", "model_id": "YOUR_MODEL_ID" }, "target": "record" }, { "source": { "field": "last_name", "model_id": "YOUR_MODEL_ID" }, "target": "record" } ], "target": { "connection_id": "YOUR_WEBHOOK_CONNECTION_ID", "object": "http", "configuration": { "batch_size": 100, "record_requests": true } }, "schedule": { "frequency": "manual" } }' ``` #### TypeScript ```typescript import { Polytomic, PolytomicClient } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.modelSync.create({ name: "Sync GCS to Webhook", mode: "updateOrCreate", active: true, fields: [ { source: { field: "email_address", model_id: "YOUR_MODEL_ID" }, target: "record" }, { source: { field: "first_name", model_id: "YOUR_MODEL_ID" }, target: "record" }, { source: { field: "last_name", model_id: "YOUR_MODEL_ID" }, target: "record" } ], schedule: { frequency: Polytomic.ScheduleFrequency.Manual }, target: { connection_id: "YOUR_WEBHOOK_CONNECTION_ID", object: "http", configuration: { batch_size: 100, record_requests: true } } }).then((resp) => { console.log(resp); }) ``` #### 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="Sync GCS to Webhook", active="true", mode="updateOrCreate", fields=[ ModelSyncField( source=Source(field="email_address", model_id="YOUR_MODEL_ID"), target="record", ), ModelSyncField( source=Source(field="first_name", model_id="YOUR_MODEL_ID"), target="record", ), ModelSyncField( source=Source(field="last_name", model_id="YOUR_MODEL_ID"), target="record", ), ], target=Target(connection_id="YOUR_WEBHOOK_CONNECTION_ID", object="http", configuration={batch_size: 100, record_requests: true}), schedule=Schedule( frequency=ScheduleFrequency.MANUAL ) ) print(resp.data) ``` #### 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: "Sync GCS to Webhook", Active: true, Mode: "updateOrCreate", Fields: []*polytomic.ModelSyncField{ { Source: &polytomic.Source{ Field: "email_address", ModelId: "YOUR_MODEL_ID", }, Target: "record" }, { Source: &polytomic.Source{ Field: "first_name", ModelId: "YOUR_MODEL_ID", }, Target: "record" }, { Source: &polytomic.Source{ Field: "last_name", ModelId: "YOUR_MODEL_ID", }, Target: "record" } }, Target: &polytomic.Target{ ConnectionId: "YOUR_WEBHOOK_CONNECTION_ID", Object: "http", Configuration: map[string]any{ "batch_size": 100, "record_requests": true } }, Schedule: &polytomic.Schedule{ Frequency: pointer.ToString(string(polytomic.ScheduleFrequencyManual)), } } ) if err != nil { panic(err) } fmt.Println(resp) ``` This example uses a `manual` schedule, so the sync runs only when you trigger it. Use a manual schedule when you drive syncs from your own orchestration. To run the sync on a recurring schedule instead, set a different [schedule frequency](/api-reference/model-sync/create#request.body.schedule.frequency).