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.

note

If you're not using Braze, see the generic customer engagement platform docs.

Talon.One requirements

  1. You have an Application and campaign in Talon.One.
  2. You have a least one customer profile in Talon.One. This profile also exists in Braze.
  3. You have set up a loyalty program for your Application. For more information, see the Product docs.
  4. Your loyalty program contains awarded points.

Braze requirements

  1. You have created a campaign or canvas in Braze.
  2. 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 Talon.One Application, click Settings > Developer settings.
  2. Click Create API Key.
  3. For Do you want to use this API Key with a 3rd party service?, select Yes.
  4. From Platform, select Braze.
  5. Select an expiration date, and click Create API Key.
  6. Copy the key for later use.

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

Retrieving the loyalty information in Braze

To retrieve the loyalty ledger information in Braze, we use the List customer data endpoint with the loyalty query parameter set to true. This endpoint is part of the Integration API which means you can use it real-time scenarios.

For example:

curl  `https://[YOUR_SUBDOMAIN].talon.one/v1/customer_profiles/[CUSTOMER_INTEGRATIONID]/inventory?loyalty=true`
--header 'Authorization: ApiKey-V1 [YOUR_API_KEY]'

Where:

  • CUSTOMER_INTEGRATIONID is the integration ID of the customer profile in Talon.One.
  • YOUR_API_KEY is the API key you generated in the previous section.

The response returns all the loyalty information of this customer profile.

note

You can add the customer profile information to the response by adding the &profile=true parameter to the request URL.

For example:

List customer data 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 and Braze's liquid tags.

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/canvas for editing.

  2. According to the Braze docs, add the following connected content tag to the body of your message and add the URL to the loyalty endpoint. You can access Braze attributes by using liquid tags. For example, {{${user_id}}} to pass the user id.

    {% 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
    %}
  3. Add the save parameter at the end to store the Talon.One response as a Braze variable and display its value according to the structure of the response sent by Talon.One:

    {% 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 <myProgramName>:
    {{result.loyalty.programs.myProgramName.ledger.currentBalance}}
  4. 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.