> ## Documentation Index
> Fetch the complete documentation index at: https://moengage.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Treasure Data

## Introduction

[Treasure Data](https://www.treasuredata.com/) is a customer data platform (CDP) that collects and routes information from multiple sources to a variety of other locations in your marketing stack.

## MoEngage × Treasure Data

MoEngage and Treasure Data bi-directional integration allows you to write job results from Treasure Data directly to MoEngage. You can

* Forward user actions and events from Treasure Data to MoEngage
* Create or update users in MoEngage
* Send MoEngage campaign interaction data back to Treasure Data

## Integration

<Info>
  **Prerequisites**

  * Ensure you have permission to create a HTTP webhook on Treasure Data
  * Ensure you have access to the MoEngage Dashboard.
</Info>

### Use cases

1. You can synchronize your consolidated customer profiles from Treasure Data into MoEngage to build-out target segments. Treasure Data supports first-party cookie data, Mobile IDs, third-party systems like your CRM, and many more.
2. You can also send back MoEngage campaign interaction data back to Treasure Data

<Note>
  Please note that the integration is not available directly. Please reach out to your Customer Success Managers to get it enabled!
</Note>

### Step 1: Get your MoEngage endpoint

Speak to your MoEngage Customer Success Manager to help you get a dedicated endpoint for TreasureData. You will be getting two separate endpoints for importing Users and Events.

### Step 2: Configure MoEngage connection on Treasure Data

Repeat the following steps for each of the two URLs given to you:

1. On your Treasure Data dashboard, navigate to **Catalog**.
   <img src="https://mintcdn.com/moengage/Bd87UYpsGgaHFmzr/images/partner_26760984990740.png?fit=max&auto=format&n=Bd87UYpsGgaHFmzr&q=85&s=1bf4cf68d900e46ee94f709145c3ce7e" alt="Treasure Data Catalog page" width="2290" height="588" data-path="images/partner_26760984990740.png" />
2. Search for **HTTP** and click on **Create Authentication** and enter the MoEngage endpoints.

#### Set up MoEngage destination

1. Enter MoEngage user API endpoints
   <img src="https://mintcdn.com/moengage/6TqgY-HweNast5mr/images/partner_35097946571412.png?fit=max&auto=format&n=6TqgY-HweNast5mr&q=85&s=83c33445813d5c55bcec4bcb0858da47" alt="MoEngage destination configuration in Treasure Data" width="1592" height="896" data-path="images/partner_35097946571412.png" />
2. Select **HTTPS** and enter the following details:
   | Field                   | Description                                                                                                                                                                                     |
   | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
   | **HTTPS**               | Check this box.                                                                                                                                                                                 |
   | **Host**                | Enter the URL part before "/v1/partner/treasuredata/events/?configName=" excluding *https\://*.                                                                                                 |
   | **Port**                | Leave this as blank.                                                                                                                                                                            |
   | **Basic auth username** | The Workspace ID of your MoEngage account is available at **Settings** > **Account** > **APIs** > **Workspace ID**. The Data API ID and the Workspace ID of your MoEngage account are the same. |
   | **Basic auth password** | The secret key is the Data API Key. The Data API key of your MoEngage account is available at **Settings** > **Account** > **APIs** > **API Keys** > **Data**.                                  |
3. Click **Continue** and save it as *moengage\_event\_sync* or *moengage\_user\_sync.*

### Step 3: Define your query

On your Treasure Data dashboard,

1. Navigate to **Data Workbench** > **Queries** and select a query you would like to export data.
   <img src="https://mintcdn.com/moengage/Bd87UYpsGgaHFmzr/images/partner_26760949405332.png?fit=max&auto=format&n=Bd87UYpsGgaHFmzr&q=85&s=589937170ba5a02d3b34dff42aa706e3" alt="Treasure Data Data Workbench Queries page" width="554" height="542" data-path="images/partner_26760949405332.png" />
2. Run this query to validate the result set. Ensure that the query has a `customer_id` column. This will be used to identify users in MoEngage.
   Note: For users using HIVE to build queries, HIVE requires that any columns or tables that begin with an underscore be wrapped by backquotes, such as *merge\_objects.*
3. Select **Export Results** and select an existing integration authentication.
   <img src="https://mintcdn.com/moengage/Bd87UYpsGgaHFmzr/images/partner_26760984992148.png?fit=max&auto=format&n=Bd87UYpsGgaHFmzr&q=85&s=e4059a2949f5e23f50432e727e3db705" alt="Treasure Data Export Results integration selection" width="1634" height="1168" data-path="images/partner_26760984992148.png" />
4. Enter the remaining part of your MoEngage URL after "moengage.com":
   <img src="https://mintcdn.com/moengage/6TqgY-HweNast5mr/images/partner_35097953628692.png?fit=max&auto=format&n=6TqgY-HweNast5mr&q=85&s=46373f65faeed3c8de90e7e5286a744f" alt="MoEngage URL configuration in Treasure Data export" width="1592" height="850" data-path="images/partner_35097953628692.png" />

Read more on pre-formatted fields, example queries, parameter details, and query export job scheduling on Treasure Data [here](https://docs.treasure.ai/int/web-server-and-http-put-endpoint-export-integration).

### Step 4: Validate data on MoEngage

You can search for the new users and see users and events getting created.

## Send campaign interaction data back to Treasure Data

Treasure Data users can ingest data through its [Postback APIs](https://docs.treasure.ai/products/customer-data-platform/integration-hub/streaming/postback-api) via Connector Campaigns. To create a connector campaign on MoEngage,

1. Navigate to **Create Campaign** > **Connectors** > **Custom** and choose the delivery type most suitable to your needs
   <img src="https://mintcdn.com/moengage/6TqgY-HweNast5mr/images/partner_35136318752788.png?fit=max&auto=format&n=6TqgY-HweNast5mr&q=85&s=4364277e1fd98db94ba85c8d4af4f0a0" alt="Connector campaign creation page in MoEngage" width="1898" height="1494" data-path="images/partner_35136318752788.png" />
2. In step 2 of the campaign, connect to the [Postback APIs](https://docs.treasure.ai/products/customer-data-platform/integration-hub/streaming/postback-api). First, go to your Treasure Data dashboard to [generate](https://docs.treasure.ai/products/my-settings/getting-your-api-keys) your Write-Only Keys.
   * **Method**: POST
   * **URL**: `<treasure-data-base-url>/postback/v3/event/{database}/{table}` You can get your Treasure Data's Base URL from [here](https://api-docs.treasuredata.com/en/overview/aboutendpoints/#treasure-data-api-baseurls). Look for the Postback service URLs for your region.
   * **Headers**:
     | Key                | Description                                                                                                   |
     | ------------------ | ------------------------------------------------------------------------------------------------------------- |
     | **Content-Type**   | Set this header to `application/json`.                                                                        |
     | **X-TD-Write-Key** | Your Treasure Data [Write-Only API Key](https://docs.treasure.ai/products/my-settings/getting-your-api-keys). |
   * **Body**:
     ```json theme={null}
     {
         "col1": "val1",
         "col2": "val2",
         ...
     }
     ```

Note that

* You need to pass `"key": "value"` pairs for each of your columns. The key is the column name in your table.
* Treasure Data does not support bulk operations at the moment.

### Preview your request

At this point, your campaign should be ready to test and send. You can also test your connector configuration using the **Test** functionality available in Step 2 of Create Connector Campaign.

<img src="https://mintcdn.com/moengage/6TqgY-HweNast5mr/images/partner_35136318755220.png?fit=max&auto=format&n=6TqgY-HweNast5mr&q=85&s=12eb71c392cf4e07b5317fe01fa0c292" alt="Preview of the connector campaign request" width="2464" height="270" data-path="images/partner_35136318755220.png" />

You can go ahead and Publish the campaign.
