Model sync (Reverse ETL) from MongoDB to Salesforce

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

  1. Create a MongoDB Connection.
  2. Create a Salesforce Connection.
  3. Create a model over the MongoDB database.
  4. Sync data from MongoDB into Salesforce.

1. Create a MongoDB connection

The following request creates a MongoDB Connection. See the MongoDB connection configuration for the required fields.

$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": "MongoDB Connection",
> "type": "mongodb",
> "configuration": {
> "hosts": "example.mongodb.net",
> "username": "user",
> "password": "secret"
> }
> }'

2. Create a Salesforce connection

The following request creates a Salesforce Connection. See the Salesforce connection configuration for the required fields.

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

3. Create a MongoDB model

Create a model over a MongoDB collection:

$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": "MongoDB Model",
> "configuration": {
> "database": "example",
> "collection": "users"
> },
> "connection_id": "YOUR-MONGODB-CONNECTION-ID"
> }'
Listing source objects

To enumerate the sources available on a Connection, see this example.


4. Sync the MongoDB model into Salesforce

The sync maps email, first_name, and last_name from the MongoDB model onto the matching Salesforce Contact fields. 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.


$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": "Mongo to Salesforce Sync",
> "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-SALESFORCE-CONNECTION-ID",
> "object": "Contact"
> }
> }'