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 covers five steps:

  1. Connecting to Salesforce.
  2. Connecting to Netsuite.
  3. Verifying connection readiness.
  4. Creating a Salesforce data model.
  5. Create a sync from Saleforce to Netsuite that filters out Salesforce Contacts with an empty LastName field.

1. Create a Salesforce connection

The following request will create a Salesforce connection using the Create Connection endpoint (note that, as an alternative, you can also use Polytomic Connect’s embedded auth).

$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 use 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 NetSuite connection.

$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. Verify that Polytomic has loaded schemas

Before using either connection for syncing, verify that the Get Schema Status call for each connection ID returns cache_status = true (you can poll the endpoint until you see this).

When this value is set to true, the connections’ object schemas are ready to be interrogated.

4. Create a Salesforce source data model

We will now create a data model on Salesforce. Data models are collections of fields (i.e. views) from which you can select any subset to sync to other systems.

Enumerating source objects

In this example, we will build a data model on the Salesforce Contact object. To list all Salesforce objects, call the Get Sync Source endpoint with your Salesforce connection ID.

Enumerating source object fields

You can list all fields for a particular object to see what’s available to select from in your model. You can do that by calling the Get Sync Source endpoint with your Salesforce connection ID and the query parameter params[stream_id]=${salesforce_object_name} (for example: params[stream_id]=companies).

Building our Salesforce model

We will now build a Polytomic source model using the Create Model endpoint.

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

5. Create a sync from Salesforce to Netsuite using the above data model

This sync maps the email field from the Salesforce 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 destination objects

To list the destination objects to sync to, use the Get Sync Target Objects endpoint.

Creating a sync from Salesforce Contacts to NetSuite Contacts

We will now build a sync from Salesforce Contacts to NetSuite Contacts using the Create Sync endpoint.

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