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

# Storing and retrieving external data to target users

> Store external CRM or CDP user data in Kameleoon using the Data API Map endpoint, then use it as a targeting condition in experiment segments.

Kameleoon Web and Feature Experimentation solutions allow you to targeting users based on external data stored on other systems (such as CRMs and CDPs), using the [Data API’s Map endpoint](/api-reference/map/update-data-for-several-keys) and [custom data](../../../custom-data).

This tutorial discusses:

* Storing external user data using the [POST Map endpoint](/api-reference/map/update-data-for-several-keys).
* Reading user data using the [GET Map endpoint](/api-reference/map/get-data-for-a-key). (Note: [This step](#fetch-data-using-retrievedatafromremotesource-activation-api) uses an activation API method for **Web Experimentation** that wraps the **Data API**. For **Feature Experimentation**, a similar method is available across Kameleoon SDKs, simplifying the process by avoiding manual API call logic).
* Leveraging stored data in a targeting segment by utilizing custom data with experiments.

## Post data using the DATA API’s MAP endpoint

Since the Data API is a **REST API**, a **POST** request to the [MAP](/api-reference/map/update-data-for-several-keys) endpoint stores additional information linked to a specific key—usually representing a visitor code or an internal user ID provided when a user visits the website.

<Note>
  You may obtain an authentication token to access the MAP endpoint following the same flow as the [Automation API](../../automation-api-rest/get-started/get-started#authentication) with JSON web tokens (optional). To learn more about authentication and rate limiting, see [this article](../overview#authentication-and-rate-limiting).
</Note>

The cURL request must include the following parameters:

* **`siteCode`**: A string of letters and numbers identifying the experiment project. See [this article](/user-manual/faq#how-do-i-find-my-sitecode) to learn how to retrieve it.
* **JSON object**: The request body contains an object consisting of a list of keys and relevant user data.
* **`User-Agent`**: Requests identified as bots or spiders are rejected according to [IAB/ABC user-agent filtering rules](https://www.iab.com/guidelines/iab-abc-international-spiders-bots-list/). Kameleoon uses a single-pass method, meaning no action is required for requests from standard web browser libraries (like XHR). **However, set a custom `User-Agent` value to override the library default in other cases.**

```shell theme={null}
curl -X POST -L 'https://eu-data.kameleoon.io/map/maps?siteCode=f17c21u1ag' \
-H 'Content-Type: application/json' \
-H 'User-Agent: MyCustomUserAgent/1.0' \
-d '{
	"myUserID1": {
        "audiencesNames": {
            "premium": true
        }
    },
    "myUserID2": {
        "audiencesNames": {
            "premium": false
        }
    },
    ...
}'
```

<Note>
  A processed request returns no content. To verify success, send a request to [this endpoint](/api-reference/map/get-data-for-a-key) using the following URL: `https://eu-data.kameleoon.io/map/map?siteCode=f17c21u1ag&key=myUserID1`
</Note>

## Fetch data using `retrieveDataFromRemoteSource` (Activation API)

With data stored on Kameleoon servers, use custom data to access information for individuals visiting the site. Custom data serves as a **targeting condition** within experiment segments.

First, create and configure custom data in Kameleoon.

From the left-hand menu of the Kameleoon dashboard, click **Custom data** under **Configure**:

<Frame>
  ![Configuration](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/Configure.png)
</Frame>

You will be redirected to the custom data dashboard. Click **New custom data** in the top-right corner.

<Frame>
  ![New\_custom\_data](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/New.png)
</Frame>

You will be taken to the **Edit the custom data** window.

<Frame>
  ![Custom\_data\_window](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/custom-data-window.png)
</Frame>

Example: Establish custom data named "Premium users" for users with a "premium" status of `true`. This information was saved in the [earlier step](#post-data-using-the-data-apis-map-endpoint).

```shell theme={null}
"audiencesNames": {
  "premium": true
}
```

To identify users with a premium status of `true`, adjust the retrieval method to **Custom JavaScript** and insert the following code for the `retrieveDataFromRemoteSource` method under **Paste a sample code**:

```javascript theme={null}
Kameleoon.API.Data.retrieveDataFromRemoteSource(user_id, function (data) {

if (data && data.audiencesNames && data.audiencesNames.premium !== undefined) {
Kameleoon.API.Data.setCustomData("Premium users", data.audiencesNames.premium);
}});
return {"value": null};
```

This method retrieves the value stored for a specific user. In the sample code, the variable `user_id` contains the unique ID of the user.

<Note>
  Projects utilizing Kameleoon Feature Experimentation can use the SDK method `getRemoteData()` within the feature flag code to retrieve data.
</Note>

Once you have populated all the information in the custom data creation window, click **Next**.

<Frame>
  ![Custom\_data\_configured](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/cd.png)
</Frame>

<Frame>
  ![Custom\_data\_configured\_extended](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/cd2.png)
</Frame>

The next window will present you with additional configuration options that are optional. Click **Create**:

<Frame>
  ![Custom\_data\_created](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/create.png)
</Frame>

You will be redirected to your custom data dashboard where you will find the **Premium** users custom data.

<Frame>
  ![Custom\_data\_dashboard](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/dashboard.png)
</Frame>

Once the custom data "Premium users" is established, it can be used for targeting in experiments.

To do so, click **Segments** under **Configure** on the left side of the dashboard.

<Frame>
  ![Configure\_segment](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/config-segment.png)
</Frame>

For instance, if you want to work with a **New segment**, click **Edit**.

<Frame>
  ![New\_segment](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/new-seg.png)
</Frame>

Then, on the left side of the **Segment** configuration window, under **Conditions** > **Technical**, select the **Premium users** custom data you created previously.

<Frame>
  ![Conditions](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/conditions.png)
</Frame>

Then, under **Definitions**, configure the custom data to include visits with the **Premium users custom data** set to **true**.

<Frame>
  ![definition](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/definition.png)
</Frame>

Then click **Next** > **Edit segment**.

<Frame>
  ![EDIT SEGMENT](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/save.png)
</Frame>

You have now successfully configured the segment to include visits with the **Premium users** custom data.

To use New segment in an experiment, return to your experiments dashboard.

Click **Edit** next to the experiment you wish to associate **New segment** with.

<Frame>
  ![Edit-experiment](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/edit-experiment.png)
</Frame>

Once you are redirected to the window below, select **Targeting** in the upper-left corner.

<Frame>
  ![Targeting](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/Targeting.png)
</Frame>

Under **Targeting**, choose **Target a segment**, then select **New segment**.

You will see the following on your screen:

<Frame>
  ![Segment\_targetted](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/Segment-targeting.png)
</Frame>

Then, in the top-right corner, click **Launch**.

<Frame>
  ![Launch](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/Launch.png)
</Frame>

A summary of the experiment draft will be displayed.

<Frame>
  ![Draft](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/Draft.png)
</Frame>

If you are satisfied with the existing configuration, click **Launch**.

<Frame>
  ![Launched](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/Launched.png)
</Frame>

Return to your dashboard and click the experiment you associated the segment with. You will see that **New segment** has been successfully added to the experiment:

<Frame>
  ![Final](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/dataapitutorial/Final.png)
</Frame>
