# Salesforce Marketing Cloud Exacttarget Export Integration Legacy Beta Treasure Data can publish user segments into [Salesforce Marketing Cloud](https://www.salesforce.com/products/marketing-cloud/overview/) (ExactTarget), and enable you to send personalized emails to your customers. You can run data-driven email campaigns, by using your first party data from Web, Mobile, CRM, and other data sources. For sample workflows of this, view [Treasure Boxes](https://github.com/treasure-data/treasure-boxes/tree/master/td/salesforce_marketing_cloud_exacttarget). Treasure Data provides two methods to write job results to Salesforce Marketing Cloud (SFMC), our SFTP and SFMC plugins. This SFMC plugin can be used for small and medium data sets. We recommend you use SFTP for large data sets. ![](/assets/image-20201105-213053.512d355d0d38313bc0f7972e08fd3ccb6ddbca979342d33bd2e9eb2ca238b42b.1eb9641a.png) ## Synchronous or Asynchronous API This data connector supports two kinds of APIs to put records into SFMC: Synchronous APIs and Asynchronous APIs. As a best practice, if you are trying to put a result set with less than 100,000 records into SFMC, Synchronous APIs is a great fit. However, if you are planning to send a million+ data set, then consider using Asynchronous APIs because it provides higher availability and reliability in comparison with Synchronous APIs. In order to use the Asynchronous APIs, you must ensure that your SFMC account is enabled as a Data Extensions Async REST API from Salesforce Marketing Cloud. You can also [create a support case in Salesforce Marketing Cloud](https://help.salesforce.com/articleView?id=workcom_contact_support.htm&type=5) to have them enable it. ## Replace or Upsert Existing Audience Data in a Data Extension This data connector also supports two modes to perform with existing data in a data extension--Upsert and Replace. ### Upsert Audience Data The first mode is **Upsert** which updates existing dataand inserts any new additional data in the data extension. Both update or insert operations will use the data extension primary key to determine if a record existed or not in order to perform update or insert. All the existing data in the target data extension remains. ### Replace Audience Data The second mode is **Replace** which means before updating data, we will clear all existing data in the target data extension. This mode useful if you need only the newest data in the data extension each time in order to send an email to targeted customers every time. When you use this mode, the deleted data is unrecoverable. The connector will clear all the data before pushing new data which means whether your job succeeds or fails, the data will be cleared. As a best practice, use this mode with data that is temporary and when data history is not important. In order to use this mode, your account must be an Enterprise 2.0 account and the installed package must have admin privileges. Contact your Customer Success representative to find out more. ## Prerequisites - Basic knowledge of Treasure Data - Basic knowledge of Salesforce Marketing Cloud - TD account This connector also requires that the Data Extension have a primary key that uniquely identifies each record. ## Create an Installed App in Salesforce Marketing Cloud Treasure Data supports several versions for Salesforce Marketing Cloud. **Enhanced Package:** We highly recommend that you use the [Salesforce Marketing Cloud V2 Export Integration](/int/salesforce-marketing-cloud-v2-export-integration). Rather than the legacy integration. ### Create a Legacy Package 1. Log on to your Salesforce Marketing Cloud account 2. On the **Welcome Page**, select your name on top right corner and select **Setup.** ![](/assets/image2021-3-16_11-44-8.f6967ec2c58968597d6b4dbb8704f13c41dd703e2449c361988a56ceadf4d1e7.1eb9641a.png) 3. Navigate to **App** > **Installed Packages.** ![](/assets/image2021-3-16_11-44-46.3c8ccc3d7269eb714c7c82f8dd5a62c4ab2a7fcc0ebe7cc39d9e60922cde1141.1eb9641a.png) 4. On the **Installed Packages** screen, select **New**. ![](/assets/image2021-3-16_11-45-17.75477b4afd4b2c948e3eab2aa93c1ec104fab1a193b99891e11b8fab47333106.1eb9641a.png) 5. In New Package Details, enter the **Name** and **Description.** Clear **Create with enhanced functionality (recommended).** 6. Select **Save.** ![](/assets/image2021-3-16_11-45-43.4773b91a84cf8cb16caf0cd6cab48bf073f68612553c57ce7b836fe8d4603f2d.1eb9641a.png) 7. On the Package Details screen, select **Add Component.** ![](/assets/image2021-3-16_11-46-21.74645d076f5445b4602ecd80bc931682f204df93e195e1b4e4ad00ce59c23273.1eb9641a.png) 8. On Add Component, select **API Integration**. Select **Next.** ![](/assets/image2021-3-16_11-46-50.6d681505050449e2cab3275fd10ea306ffcd274e60a6523bd6466a137693f834.1eb9641a.png) 9. On the Add API Integration screen, scroll to Contacts > Audiences and to Contacts > List and Subscribers. 10. Select **Read** and **Write** under both in order to use Replace Audience feature. 11. Scroll down to the Data > Data Extensions. 12. Select **Read** and **Write**. You need these permissions to write data to Salesforce Marketing Cloud. 13. Select Save. ![](/assets/image2021-3-16_11-47-19.269748fa9a94ab854803834e2662725d9c8b3653029cbc13e4041a2ea9908424.1eb9641a.png) 14. On the Installed Packages screen, scroll down to the Components panel. Copy down the **Client Id** and **Client Secret.** You use that information to write the data from Treasure Data to Salesforce Marketing Cloud. ![](/assets/image2021-3-16_11-47-50.455d844799c26b696b6c7b8ce909a9d0a41b813eff321912b5a88fbdfe9e38b8.1eb9641a.png) ## Using TD Console Complete the following steps to export TD query results to a Salesforce Marketing Cloud Data Extension: ### Create a New Data Connection When you configure a data connection, you provide authentication to access the integration. In Treasure Data, you configure the authentication and then specify the source information. 1. Open TD Console. 2. Navigate to **Integrations Hub** > **Catalog.** 3. Search for and select Salesforce Marketing Cloud. ![](/assets/image2021-3-16_11-48-30.6b2a2677c5330821f8deb090d60f2bbae92c8b5199165b2eac21c2ae43956857.1eb9641a.png) 4. The following dialog opens. Select a Legacy Package Integration. ![](/assets/image2021-3-16_11-48-50.e7c5040ecf8d92a533b85551ce12da325f86914f93dbe5a94a54497fdf032ef1.1eb9641a.png) ### Create a Legacy Package Integration 1. In the **New Authentication** dialog, select **Legacy Package,** then enter the **Client Id** and **Client Secret** (which you obtained when you created legacy package in SFMC). Select **Continue.** ![](/assets/image2021-3-16_11-49-43.308b0de6d804d367e81780dcfc3def18d010ba6a31eee858fecb21efa7c8afc2.1eb9641a.png) 2. Enter a **Name** for this integration and select **Done.** ![](/assets/image2021-3-16_11-50-9.f35887a8645e782f370f17c6bebf521dbd68403386cb2260f783e20d301cded0.1eb9641a.png) ### Configure Export Results in Your Data Connection In this step, you create or reuse a query. In the query, you configure the data connection. Sometimes you need to define the column mapping in the query. ### Configure the Connection by Specifying the Parameters 1. Open the TD Console. 2. Navigate to **Data Workbench** > **Queries** > **New Query.** ![](/assets/image2021-3-16_11-50-31.421e5eba50ed5dc5a90060685a5d3c6bdf2d58236b8e6e0df9d5b459c7e50654.1eb9641a.png) 3. Enter your query in the query editor. 4. Select **Export Results** located at top of your query editor. ![](/assets/image2021-3-16_11-50-51.5b2dc7c1f2cdfed4f02b7433552bc9b872d1d244ec275965d0b624d87f4aa437.1eb9641a.png) The Choose Integration dialog opens. You have two options when selecting a connection to use to export the results, using an existing connection or creating a new one. #### Use an Existing Connection 1. Type the connection name in the search box to filter. 2. Select your connection. ![](/assets/image2021-3-16_11-51-14.a473df30648fc300743cf1a83201f6331d5e2dca82beaf8e340398c47daf39ee.1eb9641a.png) 3. On the **Export Results** screen, enter a **Data Extension Name**. 4. Select one of the following: 1. To use Asynchronous API**,** select the **Using Async API** checkbox. To use the Synchronous API,leave the box clear. 2. Continue on failure. ![](/assets/image-20201105-214110.065bd6f2958cd485bdcad38bb6349cb0dc8ef245a6d3ac62e842603e9d3e8a6e.1eb9641a.png) 5. Select **Done.** ### Run the Query 1. Select Run to run the query. 2. Check the query results are written to the configured data extension. ![](/assets/image2021-3-16_11-53-1.b3d50e192eadb8fb66c83ef0bacdfc4059a556772b81d68a7482de02bdc4000b.1eb9641a.png) ### Plugin Configuration and Options #### Available Configurations | Configuration name | Description | Type | Sample value | | --- | --- | --- | --- | | `client_id` | Installed package client key | string | `Th1s1s4n3x4mpl3Cl13nt1ds` | | `client_secret` | Installed package client secret | string | `Th1s1s4F4k3dCl13ntS3cr3t` | | `auth_type` | Authenticate type | string | `v1` (for the legacy package) `v2` (for the enhanced package) | | `auth_uri` | Authenticate URI (required if auth_type=v2) | string | `https://th1s1sf4k3d1nst4nc3h0st.auth.marketingcloudapis.com/` | | `de_name` | Data Extension name | string | `data_extension_name` | | `create_new_de` | Flag to indicate create new data extension if it does not exist | boolean default is false | `true` (create new DE if it doesn’t exist) `false` (do not create a new DE if doesn’t exist) | | `is_sendable` | Flag to indicate created DE is sendable or not | boolean default is false | `true` `false` | | `sendable_rule` | Your account’s configured sendable business rule (required if is_sendable=true) | string | `Subscriber Key` (if the business rule is Subscriber Key) `Email Address` (if the business rule is Email Address) | | `sendable_column` | Column name to use as sendable property (required if is_sendable=true) | string | `my_sendable_column` | | `async` | Flag to indicate using asynchronous or synchronous API from SFMC | boolean default is false | `true` (using Async API) `false` (using Synchronous API) | | `continue_on_failure` | Flag to indicate continue running if there is an insertion error (applied only for synchronous API) | boolean default is true | `true` `false` | ### Example Configurations Example configuration for using **Synchronous API**s to upsert data extension using the **Legacy package.** ```yaml out: type: salesforce_marketing_cloud  client_id: Th1s1s4n3x4mpl3Cl13nt1ds client_secret: Th1s1s4F4k3dCl13ntS3cr3t  auth_type: v1 de_name: data_extension_name continue_on_failure: false ``` Example configuration for **Asynchronous APIs** to upsert data extension using the **Legacy package.** ```yaml out: type: salesforce_marketing_cloud client_id: Th1s1s4n3x4mpl3Cl13nt1ds client_secret: Th1s1s4F4k3dCl13ntS3cr3t  auth_type: v1 de_name: data_extension_name async: true ``` ### **When Replace is Selected** If: - There is a data error (NULL value, wrong data type, invalid primary key) in the exported results, all the records in the Data Extension are cleared and not recoverable, but the invalid data is not exported. - There is a schema error (missing primary_key) in the exported results, the existing records in the data extension are not cleared.