# Fetch a loyalty ledger in Iterable

> In this tutorial, let's set up Iterable 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 the Iterable-specific [Get loyalty ledger](/third-party-api#tag/Iterable/operation/iterable/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 [customer profiles](/docs/product/applications/display-customer-profiles.md).
- You have set up a [profile-based loyalty program](/docs/product/loyalty-programs/profile-based/create-pb-programs.md).

## Iterable requirements

- You have created a campaign and a template.
- You have [added users](https://support.iterable.com/hc/en-us/articles/115000770906-Adding-Users-and-Creating-Lists) to your Iterable project.
  Your user data includes the user's first name and email address. For this tutorial, we assume the corresponding fields are named `firstName` and `email`.
- You have a way to identify a given customer across Talon.One and Iterable.
  For this tutorial, we assume the customer integration ID in Talon.One is identical to the customer's email address in Iterable.

## Set up the integration

<StepsContainer>

### Create an API key in Talon.One

In the Campaign Manager, create an Iterable-specific API key:

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 a data feed in Iterable

To get the loyalty information of a given customer in Iterable, we call the following endpoint:

```text title="GET loyalty"
https://integration.talon.one/iterable/loyalty
```

<Button variant="primary" size="l" href="/third-party-api#tag/Iterable/operation/iterable/loyalty">
  See API docs
</Button>

To access this endpoint, create a [data feed](https://support.iterable.com/hc/en-us/articles/204795659-Personalizing-Templates-with-Data-Feeds) in Iterable:

1. In Iterable, open **Content > Data feeds**.
1. Click **New data feed**.
1. In **Name**, enter a name for the feed.
1. In **URL**, enter the URL of the Talon.One endpoint including parameters. To generate the URL, use the [form below](#generate-the-url).
1. Set **Format** to `JSON`.
1. In **Authorization token**, type `ApiKey-v1 YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you [created](#create-an-api-key-in-talonone).

#### Generate the URL

Generate the URL for the data feed with the following form.

You can use Iterable field values, for example `{{userid}}` or `{{email}}`.

<IterableURIGenerator endpoint="loyalty"/>

### Create a template in Iterable

To send the loyalty information, let's create an email [template](https://support.iterable.com/hc/en-us/articles/205480315-Templates-Overview) in Iterable:

1. In Iterable, open **Content > Templates**.
1. Click **New Template > Email**.
1. Enter a name and click **Create template**.
1. In **Details**, click **Edit details** and make the following settings:
   1. Enter a subject for the email.
   1. Select **Connect data feeds for dynamic template creation** and choose the data feed you [created](#create-a-data-feed-in-iterable).
1. In **Design**, click **Edit design**. When asked, choose the WYSIWYG editor.
1. Use the following example to create your email template:

   ```jinja2
   Hi {{firstName}},

   Thank you for participating in our loyalty program. Your current balance is: [[ledger.currentBalance]].

   To unsubscribe from these emails, click {{unsubscribeUrl}}.
   ```

    :::tip
    In the example above, we use the following syntax:

    - Double curly braces `{{...}}` for [user profile data][user profile data] and [merge parameters][merge parameters].
    - Double square brackets `[[...]]` for [data feed data][data feed data].

    When the campaign is triggered and the email template is sent, these placeholders are populated with values from Iterable and Talon.One.
    :::

You can now use this template in a campaign to send loyalty information to your customers.

</StepsContainer>

## Test the connection

Let's test our setup using the [Preview](https://support.iterable.com/hc/en-us/articles/115002807783-Previewing-Templates-with-Data) feature in Iterable.

To test the connection:

1. In Iterable, open the template you [created](#create-a-template-in-iterable).
1. Click **Preview**.
1. In **User data**, enter the email address of an existing user and click **Load user data**.The user's data appears.
1. In **Data feeds**, click **Load data feeds**.
1. Check whether the correct loyalty balance is shown in the template preview.

[data feed data]: https://support.iterable.com/hc/en-us/articles/204795659-Personalizing-Templates-with-Data-Feeds#step-4-reference-the-data-feed-in-the-template-s-content
[merge parameters]: https://support.iterable.com/hc/en-us/articles/206514205-Universal-Merge-Parameters
[user profile data]: https://support.iterable.com/hc/en-us/articles/205480365-Personalizing-Templates-with-Handlebars#referencing-user-profile-and-event-fields-with-handlebars
