# Fetch a loyalty ledger in CleverTap

> Let's set up CleverTap to retrieve the loyalty ledger information of a customer from Talon.One.

> For the complete documentation index, see [llms.txt](https://docs.talon.one/llms.txt).

To do so, we rely on CleverTap's [linked content](https://docs.clevertap.com/docs/linked-content) functionality and Talon.One's [Get loyalty ledger](/third-party-api#tag/Customer-engagement-platforms/operation/cep/loyalty) endpoint.

## Talon.One requirements

- You are an [admin](/docs/product/account/account-settings/manage-roles.md#admin-role) user.
- You have set up an [Application](/docs/product/applications/create-and-manage-applications.md) that
  contains at least one [customer profile](/docs/product/applications/display-customer-profiles.md).
  This profile also exists in CleverTap.
- You have set up a [profile-based loyalty program](/docs/product/loyalty-programs/profile-based/create-pb-programs.md).

## CleverTap requirements

- You are an [admin](https://docs.clevertap.com/docs/role-based-access-control) user.
- You have configured an [email provider](https://docs.clevertap.com/docs/setup-email) and tested it.
- You have created a [segment](https://docs.clevertap.com/docs/segments) that contains at least one customer profile.
- You have a way to identify a given customer across Talon.One and CleverTap. In this tutorial,
  we use the customer's email address as a unique identifier.

## Set up the integration

<StepsContainer>

### Create an API key in Talon.One

In the Campaign Manager, create an API key of type **Customer Engagement Platform**,
which you can use with CleverTap:

1. In your Application, click <Settings className="icon" /> **Settings** > **Integration API Keys**.
1. Click <Add className="icon" /> **Create API Key**.
1. In the **Create API Key** drawer, if you are asked for a key type, select **Production**.
1. In **Key name**, type a name to identify the key.
1. In **Key expiration date**, select a date.

   :::tip
   Avoid choosing expiration dates that fall at the end of the year or during other
   high-traffic periods.
   :::

1. In **Third-party integration**, select **Yes**.
1. From **Platform**, select **{props.partner}**.
1. Click **Create API Key**.
1. Click <Copy className="icon" /> to copy the key for use.

:::note
You cannot view or copy the API key after closing the drawer.
:::

### Create linked content in CleverTap

[Linked content](https://docs.clevertap.com/docs/linked-content)
allows you to call Talon.One's API endpoints and retrieve data from them.

To create linked content that calls the [Get loyalty ledger](/third-party-api#tag/Customer-engagement-platforms/operation/cep/loyalty) endpoint:

1. In CleverTap, in the sidebar, open **Settings > Setup > Linked Content**.
1. Click **+ Linked Content**.
1. In **API name**, type a name for the linked content.
1. In **Endpoint URL**, set the method to **GET** and enter the following URL:`https://integration.talon.one/customer_engagement/loyalty?profileIntegrationId={{profileIntegrationId}}&loyaltyProgramId={{loyaltyProgramId}}`.

   :::note
   We use double curly braces `{{...}}` to [personalize](https://docs.clevertap.com/docs/linked-content-url-personalization#personalize-linked-content-url) the endpoint URL and add two query parameters. You can verify them in the **Parameters** tab.

1. Click **Headers** and add the following key-value pairs:

   | Key                                 | Value                                                                                                        |
   | ----------------------------------- | ------------------------------------------------------------------------------------------------------------ |
   | `Authorization`                     | `ApiKey-v1 YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you [created](#create-an-api-key-in-talonone). |
   | `customer-engagement-platform-name` | `CleverTap`                                                                                                  |
   | `destination-hostname`              | The base URL of your Talon.One deployment, for example, `mycompany.europe-west1.talon.one`.                  |

1. Click **Test Linked Content** and enter sample values for the query parameters:
   - `profileIntegrationId`: The integration ID of an existing customer in your Talon.One Application.
   - `loyaltyProgramId`: The ID of your loyalty program in Talon.One.

     :::tip
     To see the loyalty program ID, open the <Loyalty className="icon" /> **Loyalty** page in Talon.One. The ID is displayed in the first column of the [list](/docs/product/loyalty-programs/overview.md#list-loyalty-programs).

1. Click **Send Request**.If the request is successful, the response will be displayed as JSON in the **Response** section.
1. Click **Auto-Fill Objects with Response** to automatically populate the **Custom Labels** list with objects from the response.
   For this tutorial, we only need the `name` and `ledger.currentBalance` fields. You can remove the other fields.
1. Click **Test & save changes**.

### Create the campaign in CleverTap

Now that we created the linked content, let's use it in an email campaign:

1. In CleverTap, in the sidebar, open **Campaigns**.
1. Click **+ Campaign > Email**.
1. In **Name**, type a name for your campaign.
1. In **Start here** > **Qualification criteria**, select **Past behavior/Custom list** and click **Done**.
1. In **Email Service Provider**, select the email provider you [configured](#clevertap-requirements)
   and click **Done**.
1. In **Set a goal**, click **Done**.
1. In **Who > Target Segment > Find users from segment**, select the segment you [created](#clevertap-requirements) and click **Done**.
1. In **Control group and target segment cap**, click **Done**.
1. In **What**, select **Single Message** and click **Go To Editor**.
1. At the top right of the page, click **Personalization**.
1. In **APIs**, select the name of the linked content you [created](#create-linked-content-in-clevertap).
1. In **API Parameters**, make the following settings:

   | Parameter              | Property    | Value                                                                                                                                               |
   | ---------------------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
   | `profileIntegrationId` | **Profile** | The CleverTap field containing the unique identifier that is equal to the customer integration ID in Talon.One. In this tutorial, we use **Email**. |
   | `loyaltyProgramId`     | **Custom**  | The ID of your loyalty program in Talon.One, for example, `35`.                                                                                     |

1. Click **Apply**.
1. Select an email template.
1. In the email body, add the following text, where `YOUR_LINKED_CONTENT_NAME` is the name of the linked content you created:

   ```js
   Hi {{ Profile.name | default:"(name)" }},

   Great news! You have collected {{ Linked.YOUR_LINKED_CONTENT_NAME.currentBalance | default:"0" }} points in our loyalty program {{ Linked.YOUR_LINKED_CONTENT_NAME.name | default:"(program name)" }}.
   ```

1. In **Sender Details**, fill in the sender information as required and click **Done**.
1. In **When** > **Date and time**, click **Done**.
1. In **Delivery preferences**, click **Done**.
1. Click **Publish Campaign**.

CleverTap starts sending emails to all customers in the segment. Each email contains information about
the customer's loyalty balance and the name of their loyalty program.

</StepsContainer>

## Related pages

- [Loyalty campaign tutorials](/docs/product/tutorials/loyalty.md)
- [Manage loyalty programs](/docs/product/loyalty-programs/manage-loyalty-programs.md)
