---
title: "Run a headless experience"
slug: "run-a-headless-experience"
abstract: "Learn how to run a headless personalization or A/B/n test after you publish it."
---
# Run a headless experience

After a headless personalization or A/B/n test is **Live**, your application can run it to receive the configured response for the personalization or assigned test variants.

For details about what your application sends, what SitecoreAI returns, and what to do if no response is returned, see [Request and render a headless experience](https://doc.sitecore.com/sai/en/users/sitecoreai/headless-personalization-and-abn-testing/request-and-render-a-headless-experience.html).

Use the **Integration guide** in SitecoreAI for instructions and code specific to the selected experience.

You can run a headless experience using Content SDK, REST API, or Cloud SDK.

## Open the Integration guide

To open the **Integration guide**:

1. In the navigation menu, click **Optimization**.
2. In the left sidebar, click :mdiFlaskOutline: **Tests & personalizations**.
3. Select **Headless**.
4. Select the live headless experience you want to run.
   
   The **Configuration** page opens.

5. In the right pane, click the **Connect** tab.
6. Click **Open guide**.

   The **Integration guide** pane opens.
7. Select the integration method that matches your application:
   - [Content SDK](https://doc.sitecore.com/sai/en/users/sitecoreai/headless-personalization-and-abn-testing/run-a-headless-experience.html#content-sdk)
   - [REST API](https://doc.sitecore.com/sai/en/users/sitecoreai/headless-personalization-and-abn-testing/run-a-headless-experience.html#rest-api)
   - [Cloud SDK](https://doc.sitecore.com/sai/en/users/sitecoreai/headless-personalization-and-abn-testing/run-a-headless-experience.html#cloud-sdk)

> [!note]
> The **Integration guide** provides the request or code **specific** to the selected experience. SitecoreAI returns the [configured API response](https://doc.sitecore.com/sai/en/users/sitecoreai/headless-personalization-and-abn-testing/configure-the-api-response-of-a-headless-experience.html), which your application uses to render the experience.

## Content SDK

> [!note]
> **Before you begin**
>
> Make sure:
>
> Your application uses Content SDK 2.x and is initialized with the `analytics`, `events`, and `personalize` plugins. For details, see the [Content SDK initialization guide](https://doc.sitecore.com/sai/en/developers/content-sdk/20/initializing-tracking-events-and-personalization-in-the-content-sdk.html).

To run the experience from a Content SDK application:

1. In the **Integration guide** pane, click the **Content SDK** tab.

2. In **Step 1 - Run the personalization**, click the copy icon :mdiContentCopy: to copy the TypeScript or JavaScript code.
3. Add the code to your application and run it to request the headless experience.
      
   The SDK reuses the visitor's client ID and site information from initialization, so you only need to specify the experience's friendly ID and channel.

   For example:

   ```ts
   import { personalize } from "@sitecore-content-sdk/personalize";

   const personalizeResponse = await personalize({
     channel: "WEB",
     friendlyId: "headlesspersonalization",
   });
   ```
   > [!note]
   > The sample sets `channel` to `WEB` for a website. For a mobile app, set it to `MOBILE_APP`. For a kiosk, set it to `KIOSK`. Use the same value in the goal event.

4. If the **Integration guide** includes **Step 2 - Send the goal event**, click the copy icon :mdiContentCopy: to copy the code and send it after the personalization request. A goal is optional. Skip this step when the experience does not track one.

   For example, for a *Page views* goal:

   ```ts
   import { pageView } from "@sitecore-content-sdk/events";

   await pageView({
      channel: "WEB",
      language: "EN",
      page: "/speakers",
   });
   ```
   The SDK reuses the same visitor and site information as the personalization request.

## REST API

> [!note]
> **Before you begin**
>
> Make sure:
>
> - You have a [Sitecore context ID](https://doc.sitecore.com/portal/en/developers/sitecore-cloud-portal/context-ids.html) for the environment. Include this ID in each request.
> - You have an [analytics identifier](https://doc.sitecore.com/sai/en/users/sitecoreai/create-and-manage-sites/manage-personalization-and-analytics-for-sites.html) for the site to which traffic and goal results are attributed.

To run the experience using the REST API:

1. In the **Integration guide** pane, click the **REST API** tab.

2. In the **Sitecore context ID** field, enter the context ID for your environment.

   If necessary, click **View context IDs** :mdiOpenInNew: to find the ID.

3. In the **Analytics identifier** list, select the analytics identifier to use for tracking.

4. In **Step 1 - Get a client ID**, click the copy icon :mdiContentCopy: to copy the request template and send the request.

   A client ID identifies the visitor across requests. For a new visitor, retrieve the `id` from the response, store it, and reuse it as `<CLIENT_ID>` in subsequent requests for the same visitor.

   For example:

   ```bash
   curl -X POST '<baseURL>/v1/events/api/dp/v1/clients' \
     -H 'Content-Type: application/json' \
     -H 'Accept: application/json' \
     -H 'x-sitecore-contextid: <SITECORE_CONTEXT_ID>' \
     --data-raw '{
       "clientKey": ""
     }'
   ```

   Send this request from the visitor's browser or device so SitecoreAI can derive location and device information from the request.

5. In **Step 2 - Run the personalization**, click the copy icon :mdiContentCopy: to copy the request template and send the personalization request.

   Use the analytics identifier selected in step 3 and the client ID obtained in step 4.

   For example:

   ```bash
   curl -X POST '<baseURL>/v1/personalize/v2/callFlows?siteId=<ANALYTICS_IDENTIFIER>' \
     -H 'Content-Type: application/json' \
     -H 'Accept: application/json' \
     -H 'x-sitecore-contextid: <SITECORE_CONTEXT_ID>' \
     --data-raw '{
       "clientKey": "",
       "channel": "web",
       "pointOfSale": "<ANALYTICS_IDENTIFIER>",
       "browserId": "<CLIENT_ID>",
       "friendlyId": "headlesspersonalization"
     }'
   ```
   The response contains the data defined in the headless experience's API response template. Your application uses this data to display the experience to visitors.

6. If the **Integration guide** includes **Step 3 – Send the goal event**, click :mdiContentCopy: to copy the request template and send the page view event after the personalization request.

   Use the same client ID and analytics identifier as in the personalization request.

   For example, for a *Page views* goal:

   ```bash
   curl -X POST '<baseURL>/v1/events/api/dp/v1/events' \
      -H 'Content-Type: application/json' \
      -H 'Accept: application/json' \
      -H 'x-sitecore-contextid: <SITECORE_CONTEXT_ID>' \
      --data-raw '{
        "clientKey": "",
        "clientId": "<CLIENT_ID>",
        "siteId": "<ANALYTICS_IDENTIFIER>",
        "channel": "WEB",
        "language": "EN",
        "type": "pageView",
        "name": "/speakers"
   }'
   ```

## Cloud SDK

> [!note]
> **Before you begin**
>
> Make sure:
>
> Your application uses the Sitecore Cloud SDK and is initialized with the `events` and `personalize` packages by using `addEvents()` and `addPersonalize()`. For details, see the [Cloud SDK initialization guide](https://doc.sitecore.com/sdk/en/developers/006/cloud-sdk/cloud-sdk-concepts/initializing-the-cloud-sdk.html).

To run the experience from a Cloud SDK application:

1. In the **Integration guide** pane, click the **Cloud SDK** tab.

2. In **Step 1 - Run the personalization**, click the copy icon :mdiContentCopy: to copy the TypeScript or JavaScript code. 
3. Add the code to your application and run it to request the headless experience.
      
   The SDK reuses the visitor's client ID and site information from initialization, so you only need to specify the experience's friendly ID and channel.

   For example:

   ```ts
   import { personalize } from "@sitecore-cloudsdk/personalize/browser";

   const personalizeResponse = await personalize({
     channel: "WEB",
     friendlyId: "headlesspersonalization",
   });
   ```

   The response contains the data defined in the headless experience's API response template. Your application uses this data to display the experience to visitors.

4. If the **Integration guide** includes **Step 2 – Send the goal event**, click :mdiContentCopy: and send it after the personalization request. Skip this step when the experience does not track a goal.


    For example, for a *Page views* goal:
   ```ts
      import { pageView } from "@sitecore-cloudsdk/events/browser";

      await pageView({
         channel: "WEB",
         language: "EN",
         page: "/speakers",
      });
      ```
      The SDK reuses the same visitor and site information as the personalization request.