> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://apidocs.polytomic.com/2023-04-25/code-examples/model-sync-reverse-etl-from-mongo-db-to-salesforce/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://apidocs.polytomic.com/_mcp/server. Before getting started make sure to set your Polytomic API key as an environment variable: ```bash export POLYTOMIC_API_KEY=YOUR-API-TOKEN ``` This example tutorial will cover four steps: 1. Connecting to MongoDB. 2. Connecting to Salesforce. 3. Creating a data model using the MongoDB database. 4. Loading data from MongoDB into Salesforce. ## 1. Create a MongoDB connection The following request will create a MongoDB connection. The configuration for each type of connection can be found at the [connection configuration](https://apidocs.polytomic.com/2023-04-25/configuring-your-connections) page. ```bash curl --request POST \ --url https://app.polytomic.com/api/connections \ --header "accept: application/json" \ --header "content-type: application/json" \ --header "X-Polytomic-Version: 2023-04-25" \ --header "Authorization: Bearer ${POLYTOMIC_API_KEY}" \ -d '{"name": "MongoDB Connection", "type": "mongodb", "configuration": { "hosts": "example.mongodb.net", "username": "user", "password": "secret" } }' ``` ## 2. Create an Salesforce connection The following request will create a Salesforce connection. The configuration for each type of connection can be found at the [connection configuration](https://apidocs.polytomic.com/2023-04-25/configuring-your-connections) page. ```bash curl --request POST \ --url https://app.polytomic.com/api/connections \ --header "accept: application/json" \ --header "content-type: application/json" \ --header "X-Polytomic-Version: 2023-04-25" \ --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 \ > **Note** > > 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. ## 3. Create a MongoDB data model ```bash curl --request POST \ --url https://app.polytomic.com/api/models \ --header "accept: application/json" \ --header "content-type: application/json" \ --header "X-Polytomic-Version: 2023-04-25" \ --header "Authorization: Bearer ${POLYTOMIC_API_KEY}" \ -d '{ "name": "MongoDB Model", "configuration": { "database": "example", "collection": "users" }, "connection_id": "YOUR-MONGODB-CONNECTION-ID" }' ``` #### Enumerating model sources \ > **Note** > > For information about how to enumerate sources see the Quickstart [Create a model](https://apidocs.polytomic.com/2023-04-25/quickstart#2--create-a-model) section. \ ## 4. Create a sync from MongoDB into Salesforce using the data model This sync maps the email field in the data model to the email field of Salesforce Contacts. It additionally maps the `FirstName` and `LastName` fields. The field mappings can be extended to syncs additional fields. #### Enumerating targets \ > **Note** > > For information about how to enumerate targets, see our [Create a sync](https://apidocs.polytomic.com/2023-04-25/quickstart#3--create-a-sync) section. \ ```bash curl --request POST \ --url https://app.polytomic.com/api/syncs \ --header "accept: application/json" \ --header "content-type: application/json" \ --header "X-Polytomic-Version: 2023-04-25" \ --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": "manual" }, "target": { "connection_id": "YOUR-SALESFORCE-CONNECTION-ID", "object": "Contact" } }' ```