Model sync from Salesforce to Netsuite

UI demo video

Watch the same steps in the Polytomic admin console in this demo video.

Code

Set your Polytomic API key as an environment variable:

$export POLYTOMIC_API_KEY=YOUR-API-TOKEN

This example covers five steps:

  1. Create a Salesforce Connection.
  2. Create a NetSuite Connection.
  3. Verify the Connections are ready.
  4. Create a Salesforce model.
  5. Sync Salesforce Contacts to NetSuite, filtering out records with an empty LastName.

1. Create a Salesforce connection

The following request creates a Salesforce Connection through the Create Connection endpoint. For end-user onboarding, prefer 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"}}'

Salesforce 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.

2. Create a NetSuite connection

The following request creates 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 connection readiness

Before syncing, poll the Get Schema Status endpoint for each Connection ID until cache_status is true. Once it is, the Connection’s schema is ready to query.

4. Create a Salesforce source model

Next, create a Salesforce model. A model is a view — a collection of fields you can sync to other systems in whole or in part.

Listing source objects

This example builds a model over the Salesforce Contact object. To list all Salesforce objects, call the Get Sync Source endpoint with your Salesforce Connection ID.

Listing fields on an object

To see the fields available on a specific object, call the same Get Sync Source endpoint with the query parameter params[stream_id]=<object> — for example, params[stream_id]=companies.

Create the model

Create the source model with 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. Sync Salesforce Contacts to NetSuite Contacts

The sync maps Email, FirstName, and LastName from the Salesforce model onto the matching NetSuite Contact fields, and filters out records with an empty LastName. Add more entries to the fields array to sync additional columns.

Listing target objects

To discover the target objects available on a destination, use the Get Sync Target Objects endpoint.

Creating the sync

Create the sync with 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 NetSuite 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"
> }
> ]
> }'