> 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 six steps:

1. Create a Snowflake Connection.
2. Create a LinkedIn Ads Connection.
3. Create a model from a Snowflake query.
4. Inspect the available audiences in LinkedIn Ads.
5. Sync data into an existing LinkedIn Ads audience.
6. Create a new audience and populate it from Snowflake.

## 1. Create a Snowflake connection

The Snowflake instance must be reachable from Polytomic over the network. For details, see the [Snowflake connection guide](https://docs.polytomic.com/docs/snowflake-connections).

#### 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": "uc193736182",
        "username": "user",
        "password": "secret",
        "dbname": "database"
        }
    }'
```

#### 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": "uc193736182",
"username": "user",
"password": "secret",
"dbname": "database"
}
)

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: "uc193736182",
     username: "user",
     password: "secret",
     dbname: "database"
  },
}).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": "uc193736182",
"username": "user",
"password": "secret",
"dbname": "database",
},
},
)
if err != nil {
panic(err)
}
fmt.Println(resp)

```

## 2. Create a LinkedIn Ads connection and select accounts

The following request creates a LinkedIn Ads Connection. See the [LinkedIn Ads connection configuration](/guides/configuring-your-connections/connections/linkedinads) 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 '{"type":"linkedinads", "name":"LinkedIn Ads","configuration":{}}'
```

```json
{
  "data": {
    "organization_id": "d63a93bd-dfbd-4431-9006-63eb445d30a4",
    "id": "34c27eb9-ec01-45d0-93f8-5b1deb1344c1",
    "name": "Ads Test",
    "configuration": {},
    "auth_url": "https://www.linkedin.com/oauth/v2/authorization?access_type=offline..."
  }
}

```

LinkedIn Ads 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.

A LinkedIn Ads Connection can pull data from multiple ad accounts. To choose which ones, fetch the available [connection parameters](../../api-reference/connections/get-parameter-values), then update the account list on the Connection.

#### cURL

```bash
curl --request GET  \
     --url https://app.polytomic.com/api/connections/YOUR-LINKEDIN-CONNECTION-ID/parameter_values \
     --header "accept: application/json"  \
     --header "content-type: application/json"  \
     --header "X-Polytomic-Version: 2024-02-08"   \
     --header "Authorization: Bearer ${POLYTOMIC_API_KEY}"
```

```json
{
  "data": {
 ...
  }
}

```

Use those values to update the Connection.

#### cURL

```bash
curl --request POST  \
     --url https://app.polytomic.com/api/connections/YOUR-LINKEDIN-CONNECTION-ID \
     --header "accept: application/json"  \
     --header "content-type: application/json"  \
     --header "X-Polytomic-Version: 2024-02-08"   \
     --header "Authorization: Bearer ${POLYTOMIC_API_KEY}"  \
     -d '{"type":"linkedinads", "name":"LinkedIn Ads","configuration":{"accounts":[]}}'
```

```json
{
  "data": {
    "organization_id": "d63a93bd-dfbd-4431-9006-63eb445d30a4",
    "id": "34c27eb9-ec01-45d0-93f8-5b1deb1344c1",
    "name": "Ads Test",
    "configuration": {},
    "auth_url": "https://www.linkedin.com/oauth/v2/authorization?access_type=offline..."
  }
}

```

## 3. Create a Snowflake model

Create a model backed by a Snowflake query:

#### 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": "Active Users",
            "configuration": {
               "query": "SELECT first_name, last_name, email FROM users",
            },
            "connection_id": "YOUR-SNOWFLAKE-CONNECTION-ID"
          }'
```

#### Python

```python
import os
from polytomic.client import Polytomic


client = Polytomic(
    token=os.getenv("POLYTOMIC_API_KEY"),
)

resp = client.models.create(
    name="Active Users",
    configuration={
        "query": "SELECT first_name, last_name, email FROM users",
    },
    connection_id="YOUR-SNOWFLAKE-CONNECTION-ID"
)

print(resp.data)
```

#### Typescript

```typescript
import { PolytomicClient } from 'polytomic';


const polytomic = new PolytomicClient({
  token: "POLYTOMIC_API_KEY",
});


polytomic.models.create({
  name: "Active Users",
  configuration: {
    query: "SELECT first_name, last_name, email FROM users",
  },
  connection_id: "YOUR-SNOWFLAKE-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",
      Configuration: map[string]interface{}{
        "query": "SELECT first_name, last_name, email FROM users",
      },
      ConnectionId: "YOUR-SNOWFLAKE-CONNECTION-ID",
  },
)
if err != nil {
    panic(err)
}
fmt.Println(resp)
```

> **Enumerating model sources**
>
> For information about how to enumerate sources, see this [example](./model-sync-reverse-etl-from-mongo-db-to-salesforce).

## 4. Inspect the available audiences

Retrieve the audiences available on a LinkedIn Ads Connection by [listing the target objects](../../api-reference/model-sync/targets/list) for that Connection.

#### cURL

```bash
curl --request GET  \
     --url https://app.polytomic.com/api/connections/YOUR-LINKEDIN-CONNECTION-ID/modelsync/targetobjects \
     --header "accept: application/json"  \
     --header "content-type: application/json"  \
     --header "X-Polytomic-Version: 2024-02-08"   \
     --header "Authorization: Bearer ${POLYTOMIC_API_KEY}"
```

```json
{
	"target_creation": {
		"supported": true,
		"properties": [
			{
				"id": "account",
				"title": "LinkedIn Ads account ID",
				"enum": true
			},
			{
				"id": "type",
				"title": "Audience type",
				"enum": true
			},
			{
				"id": "name",
				"title": "Audience name",
				"enum": false
			}
		]
	},
	"data": [
		{
			"id": "512630692::urn:li:organization:28818517~company_audience.29728356",
			"name": "Company Audience: Polytomic-Created Company List",
			"modes": [
				{
					"id": "create",
					"requires_identity": false,
					"supports_target_filters": false,
					"supports_per_field_mode": false
				},
				{
					"id": "remove",
					"requires_identity": false,
					"supports_target_filters": false,
					"supports_per_field_mode": false
				}
			]
		}
	]
}

```

#### Python

```python
from polytomic import Polytomic

client = Polytomic(
    version="YOUR_VERSION",
    token="YOUR_TOKEN",
)
client.model_sync.get_target_objects(
    id="YOUR_LINKEDIN_ADS_CONNECTION_ID",
)
```

#### Typescript

```typescript
import { PolytomicClient } from "polytomic";

const client = new PolytomicClient({ token: "YOUR_TOKEN", version: "YOUR_VERSION" });
await client.modelSync.getTargetObjects("YOUR_LINKEDIN_ADS_CONNECTION_ID");

```

#### Go

```golang

import (
	context "context"
	option "github.com/polytomic/polytomic-go/option"
	polytomicgoclient "github.com/polytomic/polytomic-go/client"
)

client := polytomicgoclient.NewClient(
	option.WithToken(
		"<YOUR_AUTH_TOKEN>",
	),
)
response, err := client.ModelSync.GetTargetObjects(
	context.TODO(),
	"YOUR_LINKEDIN_ADS_CONNECTION_ID",
)

```

## 5. Sync into an existing audience

To write to an existing LinkedIn Ads audience, set the audience ID as the target `object` on the sync.

The following sync maps `email`, `first_name`, and `last_name` from the Snowflake model to the corresponding LinkedIn Ads fields. Add more entries to the `fields` array to sync additional columns.

#### 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": "Snowflake to LinkedIn AdsSync",
          "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-LINKEDIN-CONNECTION-ID",
               "object": "YOUR-AUDIENCE-ID"
          }
     }'
```

## 6. Create a new audience and populate it

To write to a new audience, pass the audience's creation properties in the `target` object of the sync request.

The required properties come from the [`target_creation`](/2024-02-08/api-reference/model-sync/targets/list#response.body.target_creation) section of the [target objects list](../../api-reference/model-sync/targets/list) response.

```json
 "target_creation": {
		"supported": true,
		"properties": [
			{
				"id": "account",
				"title": "LinkedIn Ads account ID",
				"enum": true
			},
			{
				"id": "type",
				"title": "Audience type",
				"enum": true
			},
			{
				"id": "name",
				"title": "Audience name",
				"enum": false
			}
		]
	}
```

The Step 4 response shows that LinkedIn Ads supports creating destinations and requires three properties:

* `account`
* `type`
* `name`

Both `account` and `type` are marked `"enum": true`, so you can fetch their allowed values from the [property values](../../api-reference/model-sync/targets/get-create-property) endpoint.

Fetching `account` returns the ad accounts enabled on the Connection:

#### cURL

```bash
curl --request GET  \
     --url https://app.polytomic.com/api/connections/YOUR-LINKEDIN-CONNECTION-ID/modelsync/targetobjects/properties/account \
     --header "accept: application/json"  \
     --header "content-type: application/json"  \
     --header "X-Polytomic-Version: 2024-02-08"   \
     --header "Authorization: Bearer ${POLYTOMIC_API_KEY}"
```

```json
{
	"data": {
		"enum": false,
		"values": [
			{
				"value": "512630692::urn:li:organization:28818517",
				"label": "Polytomic Inc. (512630692)"
			}
		]
	}
}
```

Fetching `type` returns the supported audience types:

#### cURL

```bash
curl --request GET  \
     --url https://app.polytomic.com/api/connections/YOUR-LINKEDIN-CONNECTION-ID/modelsync/targetobjects/properties/type \
     --header "accept: application/json"  \
     --header "content-type: application/json"  \
     --header "X-Polytomic-Version: 2024-02-08"   \
     --header "Authorization: Bearer ${POLYTOMIC_API_KEY}"
```

```json
{
	"data": {
		"enum": false,
		"values": [
			{
				"value": "company_audience",
				"label": "Company Audience"
			},
			{
				"value": "user_audience",
				"label": "User Audience"
			}
		]
	}
}
```

Instead of setting a target `object`, pass these properties as a `create` object on the target. For example:

```json
"target": {
    "connection_id": "248df4b7-aa70-47b8-a036-33ac447e668d",
    "create": {
        "name": "New audience",
        "type": "user_audience",
        "account": "512630692::urn:li:organization:28818517"
    }
}
```

#### 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": "Snowflake to LinkedIn AdsSync",
          "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-LINKEDIN-CONNECTION-ID",
              "create": {
                  "name": "New audience",
                  "type": "user_audience",
                  "account": "512630692::urn:li:organization:28818517"
              }
          }
     }'
```