Skip to main content

Fetching a loyalty ledger in Braze

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

To do this, we must send a request to Talon.One from a campaign or canvas body using the List customer data endpoint.

Talon.One requirements

Braze requirements

  • You have created a campaign or 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.

Creating an API key in Talon.One

In the Campaign Manager, create a Braze-specific API key:

  1. In your Application, click Settings > Integration API Keys.

  2. Click Create API Key.

  3. In the Create API Key drawer, select Production as the key type.

  4. In Key name, type a name to identify the key.

  5. In Key expiration date, select a date.

  6. In Third-party integration, select Yes.

  7. From Platform, select Braze.

  8. Click Create API Key.

  9. Click to copy the key for use.

    note

    You cannot view or copy the API key after closing the drawer. If you lose it, create another API key.

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

Retrieving the loyalty information in Braze

To retrieve the loyalty ledger information:

  1. Send a request to the List customer data endpoint with the loyalty query parameter set to true.
    For example, use curl or a similar tool to send the following request, where:

    • YOUR_SUBDOMAIN is your Talon.One subdomain name.
    • CUSTOMER_INTEGRATION_ID is the integration ID of the customer profile in Talon.One.
    • YOUR_API_KEY is the API key you created.
    curl 'https://YOUR_SUBDOMAIN.talon.one/v1/customer_profiles/CUSTOMER_INTEGRATION_ID/inventory?loyalty=true' --header 'Authorization: ApiKey-v1 YOUR_API_KEY'
  2. Check the response. It contains all the loyalty information of this customer profile.

Response sample

{
"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,
}
}
}
}
}

Displaying the loyalty ledger information in Braze

To trigger the Talon.One customer data endpoint, let's use Braze's Connected Content 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.

  2. Add the following Connected Content call to the body of your message, where:

    • YOUR_SUBDOMAIN is your Talon.One subdomain name.
    • YOUR_API_KEY is the API key you created.
    • YOUR_PROGRAM_NAME is the name of your loyalty program.
    {% 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}}
  3. 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.