> 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. Set your Polytomic API key as an environment variable: ```bash export POLYTOMIC_API_KEY=YOUR-API-TOKEN ``` This example covers three steps: 1. Create a MySQL Connection. 2. Create a model over a MySQL table. 3. Create a sync to Snowflake. ## 1. Create a MySQL connection The following request creates a MySQL Connection. See the [connection configuration reference](/guides/configuring-your-connections/overview) 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: 2024-02-08" \ --header "Authorization: Bearer ${POLYTOMIC_API_KEY}" \ -d '{ "name": "MySQL Connection", "type": "mysql", "configuration": { "hostname": "localhost", "port": 3306, "dbname": "company", "account": "user", "passwd": "secret" } }' ``` #### Python ```python import os from polytomic.client import Polytomic client = Polytomic( token=os.getenv("POLYTOMIC_API_KEY"), ) resp = client.connections.create( name="MySQL Connection", type="mysql", configuration={ "hostname": "localhost", "port": 3306, "dbname": "company", "account": "user", "passwd": "secret" } ) print(resp.data) ``` #### Typescript ```typescript import { PolytomicClient } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.connections.create({ name: "MySQL Connection", type: "mysql", configuration: { hostname: "localhost", port: 3306, dbname: "company", account: "user", passwd: "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: "MySQL Connection", Type: "mysql", Configuration: map[string]interface{}{ "hostname": "localhost", "port": 3306, "dbname": "company", "account": "user", "passwd": "secret", }, }, ) if err != nil { panic(err) } fmt.Println(resp) ``` ## 2. Create a model Next, create a model over the `customers` table on the MySQL Connection. First, use the [source endpoint](/api-reference/model-sync/get-source) to list the tables available on the Connection: #### cURL ```bash curl --request GET \ --url https://app.polytomic.com/api/connections/{YOUR-CONNECTION-ID}/modelsync/source \ --header "content-type: application/json" \ --header "X-Polytomic-Version: 2024-02-08" \ --header "Authorization: Bearer ${POLYTOMIC_API_KEY}" ``` The response will look like: ```json { "data": { "items": { "query": { "items": null, "requires_one_of": null, "has_items": false }, "table": { "items": [ "company.accounts", "company.customers", "company.teams" ], "requires_one_of": null, "has_items": true }, "tracking_columns": { "items": null, "requires_one_of": null, "has_items": false }, "view": { "items": null, "requires_one_of": null, "has_items": false } }, "requires_one_of": [ "query", "table", "view" ] } } ``` #### Python ```python import os from polytomic.client import Polytomic client = Polytomic( token=os.getenv("POLYTOMIC_API_KEY"), ) resp = client.model_sync.get_source( id="YOUR-CONNECTION-ID" ) print(resp.data) ``` #### Typescript ```typescript import { PolytomicClient } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.modelSync.getSource("YOUR-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.ModelSync.GetSource( context.TODO(), "YOUR-CONNECTION-ID", &polytomic.ModelSyncGetSourceRequest{}, ) if err != nil { panic(err) } fmt.Println(resp) ``` ### Sources Drill into each level with query parameters — for example, `?table=company.accounts`. In this case, `requires_one_of` on `table` is null, so no further drill-down is needed. Now create a model over `company.customers`: #### 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": "Customer Model", "configuration": { "table": "company.customers" }, "connection_id": "YOUR-CONNECTION-ID" }' ``` #### Python ```python import os from polytomic.client import Polytomic client = Polytomic( token=os.getenv("POLYTOMIC_API_KEY"), ) resp = client.models.create( name="Customer Model", configuration={ "table": "company.customers" }, connection_id="YOUR-CONNECTION-ID" ) print(resp.data) ``` #### Typescript ```typescript import { PolytomicClient } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.models.create({ name: "Customer Model", configuration: { table: "company.customers" }, connection_id: "YOUR-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: "Customer Model", Configuration: map[string]interface{}{ "table": "company.customers", }, ConnectionId: "YOUR-CONNECTION-ID", }, ) if err != nil { panic(err) } fmt.Println(resp) ``` \ > **Note** > > Replace `YOUR-CONNECTION-ID` with the Connection ID returned in Step 1. ## 3. Create a sync Next, create a sync from the customer model to a new Snowflake target. ### Create a target Connection Create a Snowflake Connection to use as the sync target: #### 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": "Snowflake Connection", "type": "snowflake", "configuration": { "account": "account", "dbname": "database", "password": "secret-password", "username": "user" } }' ``` #### Python ```python import os from polytomic.client import Polytomic client = Polytomic( token=os.getenv("POLYTOMIC_API_KEY"), ) resp = client.connections.create( name="Snowflake Connection", type="snowflake", configuration={ "account": "account", "dbname": "database", "password": "secret-password", "username": "user" } ) print(resp.data) ``` #### Typescript ```typescript import { PolytomicClient } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.connections.create({ name: "Snowflake Connection", type: "snowflake", configuration: { account: "account", dbname: "database", password: "secret-password", username: "user" }, }).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: "Snowflake Connection", Type: "snowflake", Configuration: map[string]interface{}{ "account": "account", "username": "user", "password": "secret-password", "dbname": "database", }, }, ) if err != nil { panic(err) } fmt.Println(resp) ``` ### Enumerate the target Targets enumerate the same way sources do: #### cURL ```bash curl --request GET \ --url https://app.polytomic.com/api/connections/YOUR-CONNECTION-ID/modelsync/target \ --header "accept: application/json" \ --header "content-type: application/json" \ --header "X-Polytomic-Version: 2024-02-08" \ --header "Authorization: Bearer ${POLYTOMIC_API_KEY}" ``` The response will look like: ```json { "data": { "items": { "schema": { "items": null, "requires_one_of": [ "table", "view" ], "has_items": false }, "table": { "items": null, "requires_one_of": null, "has_items": false }, "view": { "items": null, "requires_one_of": null, "has_items": false } }, "requires_one_of": [ "schema" ] } } ``` #### Python ```python import os from polytomic.client import Polytomic client = Polytomic( token=os.getenv("POLYTOMIC_API_KEY"), ) resp = client.model_sync.get_target( id="YOUR-CONNECTION-ID" ) print(resp.data) ``` #### Typescript ```typescript import { PolytomicClient } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.modelSync.getTarget("YOUR-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.ModelSync.GetTarget( context.TODO(), "YOUR-CONNECTION-ID", &polytomic.ModelSyncGetTargetRequest{}, ) if err != nil { panic(err) } fmt.Println(resp) ``` Drill down recursively using the `requires_one_of` field. For example: #### cURL ```bash curl --request GET \ --url https://app.polytomic.com/api/connections/YOUR-CONNECTION-ID/modelsync/target?type=schema \ --header "accept: application/json" \ --header "content-type: application/json" \ --header "X-Polytomic-Version: 2024-02-08" \ --header "Authorization: Bearer ${POLYTOMIC_API_KEY}" ``` The response will look like: ```json { "data": { "items": { "schema": { "items": [ "__pt_new_schema", "CUSTOMERS", "TEAMS" ], "requires_one_of": [ "table" ], "has_items": true }, "table": { "items": null, "requires_one_of": null, "has_items": false } }, "requires_one_of": [ "schema" ] } } ``` #### Python ```python import os from polytomic.client import Polytomic client = Polytomic( token=os.getenv("POLYTOMIC_API_KEY"), ) resp = client.model_sync.get_target( id="YOUR-CONNECTION-ID", type="schema" ) print(resp.data) ``` #### Typescript ```typescript import { PolytomicClient } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.modelSync.getTarget( "YOUR-CONNECTION-ID", {type: "schema"}).then((res) => { console.log(res) }) ``` #### Go ```golang import ( "context" "fmt" "github.com/AlekSi/pointer" 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.GetTarget( context.TODO(), "YOUR-CONNECTION-ID", &polytomic.ModelSyncGetTargetRequest{ Type: pointer.ToString("schema"), }, ) if err != nil { panic(err) } fmt.Println(resp) ``` The schema level requires a table. Enumerate tables by adding another query parameter: #### cURL ```bash curl --request GET \ --url https://app.polytomic.com/api/connections/YOUR-CONNECTION-ID/modelsync/target?type=table&search=CUSTOMERS \ --header "accept: application/json" \ --header "content-type: application/json" \ --header "X-Polytomic-Version: 2024-02-08" \ --header "Authorization: Bearer ${POLYTOMIC_API_KEY}" ``` The response will look like: ```json { "data": { "items": { "schema": { "items": null, "requires_one_of": [ "table" ], "has_items": false }, "table": { "items": [ "__pt_new_target", "CUSTOMERS.COMPANIES", "CUSTOMERS.CONTACTS" ], "requires_one_of": null, "has_items": true } }, "requires_one_of": [ "schema" ] } } ``` #### Python ```python import os from polytomic.client import Polytomic client = Polytomic( token=os.getenv("POLYTOMIC_API_KEY"), ) resp = client.model_sync.get_target( id="YOUR-CONNECTION-ID", type="table", search="CUSTOMERS" ) print(resp.data) ``` #### Typescript ```typescript import { PolytomicClient } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.modelSync.getTarget( "YOUR-CONNECTION-ID", {type: "table", search: "CUSTOMERS"}).then((res) => { console.log(res) }) ``` #### Go ```golang import ( "context" "fmt" "github.com/AlekSi/pointer" 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.GetTarget( context.TODO(), "YOUR-CONNECTION-ID", &polytomic.ModelSyncGetTargetRequest{ Type: pointer.ToString("table"), Search: pointer.ToString("CUSTOMERS"), }, ) if err != nil { panic(err) } fmt.Println(resp) ``` ### Query target fields Finally, query the available fields on the target. `POST` to the fields endpoint for the target resource: #### cURL ```bash curl --request POST \ --url https://app.polytomic.com/api/connections/YOUR-CONNECTION-ID/modelsync/target/fields \ --header 'X-Polytomic-Version: 2024-02-08' \ --header "Authorization: Bearer ${POLYTOMIC_API_KEY}" \ --header 'content-type: application/json' \ -d '{"target": "CUSTOMERS.CONTACTS"}' ``` The response lists the available sync modes and every field on the target along with its metadata. For example: ```json { "data": { "id": "CUSTOMERS.CONTACTS", "name": "CUSTOMERS.CONTACTS", "modes": [{ "mode": "create", "description": "Create records when they don’t exist; don’t update existing ones", "label": "Create", "requires_identity": true, "supports_target_filters": false, "supports_field_sync_mode": false }, { "mode": "update", "description": "Update existing records only; don’t create new ones", "label": "Update", "requires_identity": true, "supports_target_filters": false, "supports_field_sync_mode": false }, { "mode": "updateOrCreate", "description": "Update records when they exist and create them when they don’t", "label": "Update or Create", "requires_identity": true, "supports_target_filters": false, "supports_field_sync_mode": false }, { "mode": "replace", "description": "Replace all existing rows", "label": "Replace", "requires_identity": false, "supports_target_filters": false, "supports_field_sync_mode": false }, { "mode": "append", "description": "Append rows to the end of the table", "label": "Append", "requires_identity": false, "supports_target_filters": false, "supports_field_sync_mode": false } ], "properties": { "supports_field_creation": true }, "refreshed_at": "0001-01-01T00:00:00Z", "fields": [{ "id": "EMAIL", "name": "EMAIL", "description": "", "required": false, "filterable": false, "createable": true, "updateable": true, "association": false, "supports_identity": true, "identity_functions": [ { "id": "Equality", "label": "Equality" } ], "source_type": "VARCHAR(16777216)", "type": "string" }, { "id": "FIRST_NAME", "name": "FIRST_NAME", "description": "", "required": false, "filterable": false, "createable": true, "updateable": true, "association": false, "supports_identity": true, "identity_functions": [ { "id": "Equality", "label": "Equality" } ], "source_type": "VARCHAR(16777216)", "type": "string" }, { "id": "LAST_NAME", "name": "LAST_NAME", "description": "", "required": false, "filterable": false, "createable": true, "updateable": true, "association": false, "supports_identity": true, "identity_functions": [ { "id": "Equality", "label": "Equality" } ], "source_type": "VARCHAR(16777216)", "type": "string" } ] } } ``` #### Python ```python import os from polytomic.client import Polytomic client = Polytomic( token=os.getenv("POLYTOMIC_API_KEY"), ) resp = client.model_sync.get_target_fields( id="YOUR-CONNECTION-ID", target="CUSTOMERS.CONTACTS" ) print(resp.data) ``` #### Typescript ```typescript import { PolytomicClient } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.modelSync.getTargetFields( "YOUR-CONNECTION-ID", {target: "CUSTOMERS.CONTACTS"}).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.ModelSync.GetTargetFields( context.TODO(), "YOUR-CONNECTION-ID", &polytomic.ModelSyncGetTargetFieldsRequest{ Target: "CUSTOMERS.CONTACTS", }, ) if err != nil { panic(err) } fmt.Println(resp) ``` ### Create the sync Map fields from the source model to the target and create the sync: #### cURL ```bash curl --request POST \ --url https://app.polytomic.com/api/syncs \ --header 'X-Polytomic-Version: 2024-02-08' \ --header "Authorization: Bearer ${POLYTOMIC_API_KEY}" \ --header 'content-type: application/json' \ --data '{ "name": "MySQL to Snowflake Sync", "mode": "replace", "fields": [ { "source": { "field": "email", "model_id": "YOUR-SOURCE-MODEL-ID" }, "target": "EMAIL" }, { "source": { "field": "first_name", "model_id": "YOUR-SOURCE-MODEL-ID" }, "target": "FIRST_NAME" }, { "source": { "field": "last_name", "model_id": "YOUR-SOURCE-MODEL-ID" }, "target": "LAST_NAME" } ], "schedule": { "frequency": "continuous" }, "target": { "connection_id": "YOUR-TARGET-CONNECTION-ID", "object": "CUSTOMERS.CONTACTS" } }' ``` #### Python ```python import os from polytomic.client import Polytomic from polytomic import Identity, ModelSyncField, Schedule, Source, Target, ScheduleFrequency client = Polytomic( token=os.getenv("POLYTOMIC_API_KEY"), ) resp = client.model_sync.create( name="MySQL to Snowflake Sync", mode="replace", identity=Identity( source=Source( field= "email", model_id= "YOUR-SOURCE-MODEL-ID" ), target="Email", ), fields=[ ModelSyncField( source=Source( field="first_name", model_id="YOUR-SOURCE-MODEL-ID" ), target="FirstName", ), ModelSyncField( source=Source( field="last_name", model_id="YOUR-SOURCE-MODEL-ID" ), target="LastName", ), ], schedule=Schedule( frequency=ScheduleFrequency.CONTINUOUS, ), target=Target( connection_id="YOUR-TARGET-CONNECTION-ID", object="CUSTOMERS.CONTACTS" ) ) print(resp.data) ``` #### Typescript ```typescript import { Polytomic, PolytomicClient } from 'polytomic'; const polytomic = new PolytomicClient({ token: "POLYTOMIC_API_KEY", }); polytomic.modelSync.create({ name: "MySQL to Snowflake Sync", mode: "replace", 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.Continuous }, target: { connection_id: "YOUR-TARGET-CONNECTION-ID", object: "CUSTOMERS.CONTACTS" } }).then((resp) => { console.log(resp); }) ``` #### Go ```golang import ( "context" "fmt" "github.com/AlekSi/pointer" 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: "MySQL to Snowflake Sync", Mode: "replace", Identity: &polytomic.Identity{ Source: &polytomic.Source{ Field: "email", ModelId: "YOUR-MODEL-ID", }, Target: "Email", Function: "Equality", }, 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.ScheduleFrequencyContinuous)), }, Target: &polytomic.Target{ ConnectionId: "YOUR-TARGET-CONNECTION-ID", Object: "CUSTOMERS.CONTACTS", }, }, ) if err != nil { panic(err) } fmt.Println(resp) ```