Code examples

Model sync from Salesforce to Netsuite

UI demo video

You can watch a demo video of these operations in Polytomic’s admin console here.

Code

Before getting started make sure to set your Polytomic API key as an environment variable:

$export POLYTOMIC_API_KEY=YOUR-API-TOKEN

This example tutorial will cover 4 steps:

  1. Connecting to Salesforce.
  2. Connecting to Netsuite.
  3. Creating a Salesforce data model.
  4. Create a sync loading data from Saleforce into Netsuite that filters Contacts with empty LastName field.

1. Create a Salesforce connection

The following request will create a Salesforce connection. The configuration for each type of connection can be found at the connection configuration page.

$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"}}'

Since Salesforce connections uses OAuth to authenticate, we’ll need to follow the link returned in the auth_url parameter in the response

Redirection


By default, the API expects the auth_url to be opened in a new browser window. If you’d like to modify the redirect behavior, there is an optional redirect_url parameter that can be added to the request body.

2. Create a Netsuite connection

The following request will create a Salesforce connection. The configuration for each type of connection can be found at the connection configuration page.

$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"}}'

3. Create a Salesforce data model

$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"
> }'

Enumerating model sources


For information about how to enumerate sources, see this example.


4. Create a sync from Salesforce into Netsuite using the data model

This sync maps the email field in the data model to the email field of Netsuite Contacts. It additionally maps the FirstName and LastName fields. The field mappings can be extended to sync additional fields.

Enumerating targets


For information about how to enumerate targets, see this example.


$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 Netuite 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"
> }
> ]
> }'
Was this page helpful?