# Tier Updates

In this tutorial, let's set up Braze to receive loyalty notifications from Open Loyalty and use them to trigger an email campaign. This way, we can inform customers immediately when their tier updates (upgrade or downgrade).

Because the schema of Open Loyalty's webhook requests doesn't match the schema of Braze's API endpoints, we can't send requests to Braze directly. Instead, we rely on Braze's Data Transformation feature to transform the Open Loyalty payload into valid Braze API calls.

#### Open Loyalty Requirements

* You are an admin user.
* You have a Tenant.
* You have at least one Member profile in Tenant. This profile should also exist in Braze (identified by their e.g. loyaltyCardNumber).
* You have configured a tier set and defined different tiers.

#### Braze Requirements

* You are an account or workspace admin.
* Access to the "Data Settings" tab in Braze to configure webhook listeners.

***

## Setting up the integration

{% stepper %}
{% step %}

#### Generate the Webhook URL

First, we must generate a webhook URL to which Open Loyalty can send the notification requests. Braze automatically generates a webhook URL when you create a **data transformation**.

1. In Braze, open **Data Settings > Data Transformation**.
2. Click **Create transformation** and configure the following parameters:
   1. **Transformation name**: Type a name (e.g., "Open Loyalty Tier Update").
   2. **Editing experience:** Select **Start from scratch**.
   3. **Select destination**: Select **POST: Track users**. (This is the endpoint used to trigger user events).
3. Click **Create Transformation**.
4. Next to **Webhook URL**, click **Copy**.

{% hint style="warning" %}
**Note**: Keep this URL safe; you will need it for the next step.
{% endhint %}
{% endstep %}

{% step %}

#### Create the Webhook Subscription

You must configure Open Loyalty to send data to the Braze URL you just generated whenever a member's tier changes. We will use the `CustomerLevelChanged` event.

1. Log in to your Open Loyalty Admin Panel.
2. Navigate to **General > Webhooks**.
3. Click **Add new webhook** and configure the subscription:
   1. **eventName**: Set this to `CustomerLevelChanged`. This event triggers whenever the tier is changed.
   2. **url**: Paste the Braze webhook URL you copied in Step 1.
   3. Add the following headers:&#x20;
      1. `Content-Type: application/json`
      2. `User-Agent: partner-OpenLoyalty`
4. Save the webhook subscription.
   {% endstep %}

{% step %}

#### Configure the Data Transformation

Now that Open Loyalty is linked to Braze, you must write the JavaScript logic in Braze to translate the Open Loyalty payload into a Braze User Track event.

* In Braze, open the data transformation you created in Step 1.
* Trigger a points change in Open Loyalty (e.g., add points to a test member) to generate a sample payload under **Webhook details**.

{% hint style="info" %}
The Open Loyalty payload contains a `data` object with `amountChange`, `amountChangeType`, and `customer` details.
{% endhint %}

* Under **Transformation code**, enter the following JavaScript. This maps Open Loyalty data to Braze properties:

```javascript
let brazecall = {
  // Update the user's profile attribute with the new tier name
  "attributes": [
    {
      "external_id": payload.data.customer.loyaltyCardNumber,
      "loyalty_tier": payload.data.level.name
    }
  ],
  // Trigger a custom event for the campaign
  "events": [
    {
      "external_id": payload.data.customer.loyaltyCardNumber,
      "name": "Loyalty Tier Changed",
      "time": new Date().toISOString(),
      "properties": {
        "new_tier_name": payload.data.level.name,
        "is_upgrade": payload.data.level.levelMoveUp,
        "is_downgrade": payload.data.level.levelMoveDown
      }
    }
  ]
};

return brazecall;
```

* Click **Validate** to ensure the code runs against your sample payload.
* Click **Activate**.
  {% endstep %}

{% step %}

#### Trigger the Email Campaign

You can now use the custom Braze event (Loyalty Tier Changed) to trigger an email.

1. In Braze, click **Campaigns > Create campaign > Email**.
2. In **Campaign Name**, type a name for your campaign.
3. In **Email Variants**, select **HTML Editor** and click **Blank Template**.
4. Click **Edit Sending Info** and enter a subject line.
5. Click the **Body** tab and insert the following HTML code. This uses Liquid logic to display dynamic text based on whether points were added or spent:

```html
{% if event_properties.${is_upgrade} == true %}
  <h1>Congratulations!</h1>
  <p>You've leveled up to <strong>{{event_properties.${new_tier_name}}}</strong> status!</p>
  <p>Check out your new perks in the app.</p>
{% elsif event_properties.${is_downgrade} == true %}
  <p>Your tier status has changed to {{event_properties.${new_tier_name}}}.</p>
  <p>Earn more points to get back to the top!</p>
{% endif %}
```

6. Click **Done**.
7. In the **Schedule Delivery** tab, select **Action-Based** as the delivery type.
8. In **New Trigger Action**, select **Perform Custom Event** and click **Add Trigger**.
9. In **Choose a custom event**, select **Loyalty Tier Changed**.
10. Ensure your **Target Audience** includes the users you are testing with.
11. Click **Launch Campaign**.
    {% endstep %}

{% step %}

#### Testing the Setup

To test the setup, manually change a member's tier in Open Loyalty (e.g., via the Admin Panel)

1. This triggers the `CustomerLevelChanged` webhook.
2. Braze receives the data, transforms it using your JavaScript, and records the `Loyalty Tier Changed` event.
3. The email campaign is triggered, sending the user an update with their new tier.
   {% endstep %}
   {% endstepper %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.openloyalty.io/technical-guide/integration/braze/tier-updates.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
