# Fetch a loyalty ledger in Braze

> Let's set up Braze 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 this, we must send a request to Talon.One from a campaign
or canvas body using the [List customer data][listCD] endpoint.

## Talon.One requirements

- You have an [Application](/docs/product/applications/create-and-manage-applications.md) and a [campaign](/docs/product/campaigns/create-and-manage-campaigns.md) set up.
- You have at least one [customer profile](/docs/dev/concepts/entities/customer-profiles.md) in your Application. This profile also exists in Braze.
- You have set up a [profile-based loyalty program](/docs/product/loyalty-programs/profile-based/create-pb-programs.md).
- Your loyalty program contains awarded points.

## Braze requirements

- You have created a [campaign](https://www.braze.com/docs/user_guide/messaging/campaigns/creating_campaign) or [canvas](https://www.braze.com/docs/user_guide/messaging/canvas) in Braze.
- You have a way to identify a given customer across Talon.One and Braze.
   In this tutorial, we assume a customer's Talon.One `integrationId` is always equal to Braze's `user_id`.
   You can also create a new property on your Braze customer profiles to store Talon.One's integration ID.

## Set up the integration

<StepsContainer>

### Create an API key in Talon.One

In the Campaign Manager, create a Braze-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.
:::

We will use the API key in the Braze campaign template.

### Retrieve the loyalty information in Braze

To retrieve the loyalty ledger information:

1. Send a request to the [List customer data][listCD] endpoint with the `loyalty` query parameter set to `true`.
   For example, use curl or a similar tool to send the following request, where:
   - `YOUR_DEPLOYMENT_URL` is the base URL of your Talon.One deployment, for example, `mycompany.europe-west1.talon.one`.
   - `CUSTOMER_INTEGRATION_ID` is the integration ID of the customer profile in Talon.One.
   - `YOUR_API_KEY` is the API key you [created](#create-an-api-key-in-talonone).

   ```js
   curl 'https://YOUR_DEPLOYMENT_URL/v1/customer_profiles/CUSTOMER_INTEGRATION_ID/inventory?loyalty=true' --header 'Authorization: ApiKey-v1 YOUR_API_KEY'
   ```

1. Check the response. It contains all the loyalty information of this customer profile, for example:

    ```json
    {
      "loyalty": {
        "programs": {
          "myProgram": {
            "id": 323414846,
            "title": "My loyalty program",
            "name": "myProgram",
            "ledger": {
              "currentBalance": 46,
              "pendingBalance": 10,
              "expiredBalance": 30,
              "spentBalance": 84,
              "tentativeCurrentBalance": 56,
              "currentTier": {
                "id": 11,
                "name": "bronze"
              },
              "pointsToNextTier": 20,
            }
          }
        }
      }
    }
    ```

### Display the loyalty ledger information in Braze

To trigger the Talon.One customer data endpoint, let's use Braze's
[Connected Content](https://www.braze.com/docs/user_guide/messaging/design_and_edit/personalize/connected_content/making_an_api_call) feature.

You can use it in every campaign message body or any canvas message body.

:::important
We assume that your Braze setup sets an attribute for each user equal to the value of
the customer profile's `integrationID` in Talon.One. This allows you to dynamically
retrieve the loyalty points of any user. We call this attribute `${user_id}` in this
tutorial.
:::

1. Open your Braze campaign or canvas for editing.
1. Add the following Connected Content call to the body of your message, where:
   - `YOUR_DEPLOYMENT_URL` is the base URL of your Talon.One deployment, for example, `mycompany.europe-west1.talon.one`.
   - `YOUR_API_KEY` is the API key you [created](#create-an-api-key-in-talonone).
   - `YOUR_PROGRAM_NAME` is the name of your loyalty program.

   ```liquid
   {% connected_content https://YOUR_SUBDOMAIN.talon.one/v1/customer_profiles/{{${user_id}}}/inventory?loyalty=true
      :headers {"Authorization": "ApiKey-v1 YOUR_API_KEY"}
      :method get
      :content_type application/json
      :save result
   %}

   Total points in YOUR_PROGRAM_NAME:
   {{result.loyalty.programs.YOUR_PROGRAM_NAME.ledger.currentBalance}}
   ```

1. To test your request and its parsing, click **Preview** in the template editor.

   :::tip
   We highly recommend you use Postman or similar tools to ensure you understand
   the structure of the response of the List customer data endpoint.
   :::

</StepsContainer>

[listCD]: /integration-api#tag/Customer-profiles/operation/getCustomerInventory
