# Marketo Export Integration [Learn more about Marketo Import Integration](/int/marketo-import-integration). You can create a connector to write Treasure Data job results directly to your Marketo account records. The TD query job results add users, such as appending to Marketo Target lists or updating existing users. For sample workflows of exporting to Marketo, view [Treasure Boxes](https://github.com/treasure-data/treasure-boxes/tree/master/td/marketo). # Prerequisites - Basic knowledge of Treasure Data, including the [TD Toolbelt](https://toolbelt.treasuredata.com/). - A Marketo Account with API access enabled (done via Marketo Console). # Create a New Connection 1. Go to **Integrations Hub** > **Catalog**. Select **Marketo**. ![](/assets/marketotile.663647a59e2e9da836a3819264228b9fb05248cf52749853c826f09ab25de70f.fbe2a812.png) 1. The dialog opens. ![](/assets/marketoimport.aefe5bd733c9ee00014b97821d7e477b303fff29a96821bd4ca9e5e88d12d779.fbe2a812.png) 1. Complete the new connection information, providing your Marketo credential: - **Marketo Account ID** (required): Your Marketo Service/Munchkin ID. - **Marketo Client ID** (required): A service-specific client ID. - **Marketo Client Secret** (required): A service-specific client secret. 1. Enter the name of your newly created connection and select **Done**. # Configure to Output Results to Marketo Connection 1. Check the o`utput results` at the top of your query editor and select your Marketo connection. There are several parameter fields to complete. | Parameter | Type | Required? | Description | | --- | --- | --- | --- | | Mode | string | yes | The connector mode could be `upload_leads`  or `delete_leads. Default is upload_leads.` | | Marketo Target List ID | string | yes | The ID of the list is where the new leads are imported. The list must be from an existing list; otherwise, the new leads will go into the central Marketo database. | | Headers for importing data | string | no | Specify headers as export target field. In addition to the query, specify the field name here. | | Marketo Partition Name | string | no | Name of the partition to which the new leads will belong. | | Lookup Field | string | no | The value in this field is bound to this data set and can be used to look up or de-dup the data set. The default is email. | | Retry limit | integer | no | The number of retries before the connector stops trying to connect and send data. The retry limit default is six. | | Retry initial wait in milliseconds | integer | no | The interval to retry if a recoverable error happens (in milliseconds). The default is 1000. | | Retry Max wait in milliseconds | integer | no | The maximum time in milliseconds between retry attempts. The default is `30000.` | | Max HTTP waiting time in milliseconds | integer | no | The maximum HTTP wait time. The default is 3000000. | | Max upload chunk size (in bytes) | integer | no | The maximum chunk size to upload. The default is 10000000. | | Batch max wait in milliseconds | integer | no | The Maximum batch waiting time. The default is 3600000. | | Ignore Invalid Records | boolean | no | Ignore invalid records during deletion. The default is false. | | Skip Invalid Records | boolean | no | Ignore invalid records during upload data. The default is true. | ## Sample Configuration ![](/assets/screenshot-2025-01-10-at-00.14.27.f723816021568bda17f3091968a0004e685bf385fac145ed94e7f263607e7ab0.fbe2a812.png) The list ID is available on the Marketo Console: ![](/assets/image-20191021-145434.f0f29d1e9d8a6473de9a9b30395771d9702bcdbd82fb5c0d666946c7af3c7733.fbe2a812.png) # Activate a Segment in Audience Studio You can also send segment data to the target platform by creating an activation in the Audience Studio. 1. Navigate to **Audience Studio**. 2. Select a parent segment. 3. Open the target segment, right-mouse click, and then select **Create Activation.** 4. In the **Details** panel, enter an Activation name and configure the activation according to the previous section on Configuration Parameters. 5. Customize the activation output in the **Output Mapping** panel. ![](/assets/ouput.b2c7f1d909c4f98ed10f5300df858a4b19f71a3b0834df952f5fb24018a5ea78.8ebdf569.png) - Attribute Columns - Select **Export All Columns** to export all columns without making any changes. - Select **+ Add Columns** to add specific columns for the export. The Output Column Name pre-populates with the same Source column name. You can update the Output Column Name. Continue to select **+ Add Columns**to add new columns for your activation output. - String Builder - **+ Add string** to create strings for export. Select from the following values: - String: Choose any value; use text to create a custom value. - Timestamp: The date and time of the export. - Segment Id: The segment ID number. - Segment Name: The segment name. - Audience Id: The parent segment number. 1. Set a **Schedule**. ![](/assets/snippet-output-connector-on-audience-studio-2024-08-28.a99525173709da1eb537f839019fa7876ffae95045154c8f2941b030022f792c.8ebdf569.png) - Select the values to define your schedule and optionally include email notifications. 1. Select **Create**. # (Optional) Export Integration Using the CLI The [TD Toolbelt](https://toolbelt.treasuredata.com/) can trigger exporting the Query Result to Marketo from the CLI. You need to specify the parameters for the export job using the --result option of the td query command. For more information, refer to [Querying and Importing Data to Treasure Data from the Command Line](https://docs.treasuredata.com/smart/project-product-documentation/querying-and-importing-data-to-treasure-data-from-the-command-line). The format of the option is JSON, and the general structure is as follows: For upload lead mode ```json {"type": "marketo", "account_id": "account id", "client_id": "client id", "client_secret": "client secret", "mode": "upload_leads", "list_id": "list id", "batch_max_wait_msec": 3600000, "upload_chunk_size_in_bytes": 10000000, "retry_limit": 7, "retry_initial_wait_msec": 1000, "max_retry_wait_msec": 32000, "http_timeout_millis": 300000, "skips_invalid_records": true}# For delete mode{ "type": "marketo", "account_id": "account id", "client_id": "client id", "client_secret": "client secret", "mode": "delete_leads", "list_id": "list id", "batch_max_wait_msec": 3600000, "upload_chunk_size_in_bytes": 10000000, "retry_limit": 7, "retry_initial_wait_msec": 1000, "max_retry_wait_msec": 32000, "http_timeout_millis": 300000, "ignore_invalid_records": false} ``` ### CLI Parameters. | Parameter | Type | Required? | Description | | --- | --- | --- | --- | | type | string | yes | Export type. It must be the exact value of "marketo." | | account_id | string | yes | A specific Marketo Munchkin ID is needed for this service/account. | | client_id | string | yes | Client ID. Available from the Marketo console. | | client_secret | string | yes | Client secret. Available from the Marketo console. | | mode | string | yes | The connector mode could be `upload_leads` or `delete_leads.` | | list_id | string | yes | The ID of the list is where the new leads are imported. The list must be from an existing list; otherwise, the new leads will go into the central Marketo database. | | file_format | string | no | File format to be used. The default format is CSV | | headers | string | no | Specify headers as export target field. In addition to the query, specify the field name here. | | partition_name | string | no | Name of the partition to which the new leads will belong. | | lookup_field | string | no | The value in this field is bound to this data set and can be used to look up or de-dup the data set. The default is email. | | retry_limit | integer | no | The number of retries before the connector stops trying to connect and send data. The retry limit default is six. | | retry_initial_wait_msec | integer | no | The interval to retry if a recoverable error happens (in milliseconds). The default is 1000. | | max_retry_wait_msec | integer | no | The maximum time in milliseconds between retry attempts. The default is `30000.` | | http_timeout_millis | integer | no | The maximum HTTP wait time. The default is 3000000. | | upload_chunk_size_in_bytes | integer | no | The maximum chunk size to upload. The default is 10000000. | | batch_max_wait_msec | integer | no | The Maximum batch waiting time. The default is 3600000. | | ignore_invalid_records | boolean | no | Ignore invalid records during deletion. The default is false. | | skip_invalid_records | boolean | no | Ignore invalid records during upload data. The default is true. | ### Examples ```bash td query -d [database] -w 'SELECT id, email, company FROM marketo' --type presto --result '{"type":"marketo", "account_id”:”[account id]”, "client_id”:”[client id]”, "client_secret”:”[client secret]”, "mode":"upload_leads", "list_id”:”[list id]”, "retry_limit": 3}'; ``` # Write the Query to Populate a Leads List On TD Console, run the following query  `Output results` into a connection with Marketo. The query does not match any real users and is for demonstration purposes only. For more details on column naming, see the [Appendix](https://docs.treasuredata.com/articles/project-integrations/marketo-export-integration#MarketoExportIntegration-Appendix). ```sql SELECT td_global_id as tdglobalid, firstname, lastname, email, company FROM ( VALUES ('b1b065f5-1222-4a14-b151-379d49ec39e3', 'John', 'Doe', 'name+test1@treasure-data.com', 'Marketo Dummy Lead - DO NOT USE'), ('x1b065f5-1222-4a14-b151-379d49ec39e3', 'Janes', 'Doe', 'name+test2@treasure-data.com', 'Marketo Dummy Lead - DO NOT USE'), ('p1b065f5-1222-4a14-b151-379d49ec39e3', 'Tony', 'Doe', 'name+test3@treasure-data.com', 'Marketo Dummy Lead - DO NOT USE'), ('o1b065f5-1222-4a14-b151-379d49ec39e3', 'Bill', 'Adam', 'name+test4@treasure-data.com', 'Marketo Dummy Lead - DO NOT USE'), ('t1b065f5-1222-4a14-b151-379d49ec39e3', 'Dan', 'Steve', 'name+test5@treasure-data.com', 'Marketo Dummy Lead - DO NOT USE') ) tbl ( td_global_id, firstname, lastname, email, company ) ``` The demo query requires no source table (for the ease of testing this feature), but you must choose your database, so pick “sample_datasets” or any other arbitrary table. If you don’t want to specify the data headers in the configuration, you can use aliases in your query to rename columns of your query result. ### Example ```sql SELECT an_email_column AS EMAIL, another_phone_column AS PHONE FROM your_table; ``` In the previous code sample, we are creating a new data set with headers of EMAIL and PHONE. Column names are case-insensitive. For example, you can use either `email` or `EMAIL`. The query should be completed in a few seconds. When complete, check the Marketo Console for your new leads: ![](/assets/image-20191021-145325.e5c9ae872920dc020631e83011f1760ce267fd991e014ae7485b3e4ea03f3fc8.fbe2a812.png) # Appendix ## Marketo Leads Data Output result data must follow [Marketo data specifications](http://developers.marketo.com/rest-api/lead-database/fields/field-types/). For example, when the field is set up as an Integer, the data Treasure Data sends to Marketo must be convertible to int (1001aa is not a valid integer). ## Munchkin Account Information Access to your API-enabled account is required before uploading the Marketo list. The Munchkin Account ID can be retrieved from the Marketo Admin page. Steps to enable and create a new account for API access 1. Create an [API-Only User](http://docs.marketo.com/display/public/DOCS/Create+an+API+Only+User). 2. Create an [API-Only User Role](http://docs.marketo.com/display/public/DOCS/Create+an+API+Only+User+Role). 3. Enable the [Advanced List Import Permission on a Role](http://docs.marketo.com/display/public/DOCS/Enable+the+Advanced+List+Import+Permission+on+a+Role). 4. Create a [Custom Service for Use with REST API](http://docs.marketo.com/display/public/DOCS/Create+a+Custom+Service+for+Use+with+ReST+API). 5. Check the endpoint for Rest API on the “Web Service” menu. There, you can find a client ID and a client secret for using the API. ![](/assets/image-20191021-145135.ba4107f8ad71bae8a1ad1f8738693333fee194aea9346a87f01fb0bece8a593f.fbe2a812.png) ## Preparing Data for Marketo Leads - Reference - [Error code](http://developers.marketo.com/rest-api/error-codes/) - [Partition Name](http://developers.marketo.com/blog/how-to-specify-lead-partitions-using-the-rest-api/) - [FilterType/LookupField](http://developers.marketo.com/rest-api/lead-database/leads/#query) - [Data Type for Marketo Lead fields](http://developers.marketo.com/rest-api/lead-database/fields/field-types/) - [Standard Lead fields](http://developers.marketo.com/rest-api/lead-database/fields/list-of-standard-fields/) (available from API access)