# Open Loyalty to Braze

## Inbound webhooks: Open Loyalty → Braze

Send Open Loyalty webhook events to Braze.\
Use a Braze **Data Transformation** to convert the payload into a Braze API call.

This works for any Open Loyalty event.\
Examples: points changes, tier changes, campaign effects, reward redemptions.

### Pick your delivery model in Braze

* **Custom event-based campaigns**\
  Best when you want Braze to record an event.\
  You trigger **Action-Based** campaigns via **Perform Custom Event**.
* **API-triggered campaigns**\
  Best when one Open Loyalty event should send one specific campaign.\
  Braze does not need to store a custom event.\
  The transformation calls Braze “Send Campaigns via API-Triggered Delivery”.

{% hint style="info" %}
In both models, you must map one stable user identifier.\
Most setups use `loyaltyCardNumber` as Braze `external_id` / `external_user_id`, but it solely depends on how you implented identifiers in Open Loyalty.
{% endhint %}

***

### Custom event-based campaigns&#x20;

{% stepper %}
{% step %}

#### Create the Braze Data Transformation

1. In Braze, go to **Data Settings > Data Transformation**.
2. Click **Create transformation**.
3. Set **Transformation name** (example: `Open Loyalty Webhooks → Custom Events`).
4. Set **Select destination** to **POST: Track users**.
5. Click **Create Transformation**.
6. Copy the **Webhook URL**.

{% hint style="warning" %}
Treat the webhook URL like a secret.\
Anyone with it can send data into your Braze workspace.
{% endhint %}
{% endstep %}

{% step %}

#### Create the Open Loyalty webhook subscription

1. In Open Loyalty Admin Panel, go to **General > Webhooks**.
2. Click **Add new webhook**.
3. Configure:
   * **Event Name**: Pick the Open Loyalty event you want to forward.\
     Example: `AvailablePointsAmountChanged`, `CustomerLevelChanged`, `CampaignEffectWasApplied`.
   * **URL**: Paste the Braze webhook URL.
   * **Headers**:
     * `Content-Type: application/json`
     * `User-Agent: partner-OpenLoyalty`
4. Save.
   {% endstep %}

{% step %}

#### Map Open Loyalty → Braze custom event (users/track)

1. In Braze, open your transformation.
2. Trigger the Open Loyalty event once to capture a sample payload.
3. In **Transformation code**, map the payload to a Braze event.

```javascript
// Open Loyalty webhook body is available as `payload`
const data = payload.data;

return {
  events: [
    {
      // Must match a user identifier in Braze
      external_id: data.customer.loyaltyCardNumber,

      // This is the custom event name visible in Braze
      name: "Loyalty Event Triggered",
      time: new Date().toISOString(),

      // These become `event_properties` in Braze
      properties: {
        event_type: payload.type,
        event_time: payload.createdAt,

        // Example fields (adjust per event type)
        new_balance: data.amount,
        change_amount: data.amountChange
      }
    }
  ]
};
```

4. Click **Validate**.
5. Click **Activate**.
   {% endstep %}

{% step %}

#### Create an Action-Based campaign triggered by the custom event

1. Create a campaign (Email, Push, SMS).
2. Under **Schedule Delivery**, pick **Action-Based**.
3. Add trigger **Perform Custom Event**.
4. Select the event name from the transformation.\
   Example: `Loyalty Event Triggered`.
5. Use Liquid to access event properties:
   * `{{event_properties.${new_balance}}}`
   * `{{event_properties.${change_amount}}}`
     {% endstep %}
     {% endstepper %}

***

### Create API-triggered Campaigns

{% stepper %}
{% step %}

#### Create the Braze campaign (API-triggered) and copy Campaign ID

1. Create a campaign (Email, Push, SMS).
2. Under **Schedule Delivery**, pick **API-Triggered**.
3. In **API Trigger Options**, copy the **Campaign ID**.
   {% endstep %}

{% step %}

#### Create the Braze Data Transformation (webhook URL)

1. In Braze, go to **Data Settings > Data Transformation**.
2. Click **Create transformation**.
3. Set **Transformation name** (example: `Open Loyalty Webhooks → API Trigger`).
4. Set **Select destination** to **POST: Send Campaigns via API-Triggered Delivery**.
5. Click **Create Transformation**.
6. Copy the **Webhook URL**.
   {% endstep %}

{% step %}

#### Create the Open Loyalty webhook subscription

1. In Open Loyalty Admin Panel, go to **General > Webhooks**.
2. Click **Add new webhook**.
3. Configure:
   * **Event Name**: Pick the Open Loyalty event you want to forward.
   * **URL**: Paste the Braze webhook URL.
   * **Headers**:
     * `Content-Type: application/json`
     * `User-Agent: partner-OpenLoyalty`
4. Save.
   {% endstep %}

{% step %}

#### Map Open Loyalty → Braze API-triggered send

1. In Braze, open your transformation.
2. Trigger the Open Loyalty event once to capture a sample payload.
3. In **Transformation code**, build the API-trigger request.

```javascript
const data = payload.data;

return {
  // Paste your Braze Campaign ID here
  campaign_id: "YOUR_CAMPAIGN_ID",
  recipients: [
    {
      // Must match a user identifier in Braze
      external_user_id: data.customer.customerId || data.customer.loyaltyCardNumber,

      // Available in messages as `api_trigger_properties`
      trigger_properties: {
        event_type: payload.type,
        event_time: payload.createdAt,

        // Example fields (adjust per event type)
        new_balance: data.amount,
        change_amount: data.amountChange
      },

      // Optional: update profile attributes before sending the campaign
      attributes: {
        loyalty_card_number: data.customer.loyaltyCardNumber
      },

      // Keep `true` if you only want to message users who already exist in Braze
      send_to_existing_only: true
    }
  ]
};
```

4. Click **Validate**.
5. Click **Activate**.
   {% endstep %}

{% step %}

#### Personalize the message with API trigger properties

In your campaign message, reference properties via Liquid:

* `{{api_trigger_properties.${new_balance}}}`
* `{{api_trigger_properties.${change_amount}}}`
  {% 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/open-loyalty-to-braze.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.
