# Segment Updates

### Integration Overview

This integration uses **Braze Webhooks** to send data *to* Open Loyalty. When a user enters a specific segment in Braze, we trigger a webhook that sends a `PATCH` request to the Open Loyalty Member API. This updates the member's **Labels** (custom attributes), which can then be used to define segments within Open Loyalty.

#### Prerequisites

| Prerequisite           | Description                                                                             |
| ---------------------- | --------------------------------------------------------------------------------------- |
| Open Loyalty API Token | A permanent token (`X-AUTH-TOKEN`) with permission to modify members.                   |
| Tenant ID              | Your Open Loyalty Tenant ID (e.g., `KHO`).                                              |
| Matching IDs           | The user's `external_id` in Braze must match their `loyaltyCardNumber` in Open Loyalty. |

***

## Setting up the integration

{% stepper %}
{% step %}

#### Prepare Open Loyalty

Before sending data, ensure Open Loyalty is ready to utilize the incoming label.

1. Decide on the **Label Key** you will use (e.g., `braze_vip_segment` or `braze_optedIn`).&#x20;
2. In Open Loyalty, create a **Segment** that filters members based on this label. \
   \* **Condition:** Member has custom attribute value `braze_vip_segment` equal to `optedIn`.
   {% endstep %}

{% step %}

#### Create Braze Webhook Campaign

We will configure Braze to send the API request whenever a user qualifies for the segment.

1. In Braze, create a new **Webhook Campaign** (or use a Webhook within a Canvas).
2. Click on **Compose Webhook**
3. **Webhook URL:** Construct the URL using your Open Loyalty instance, Tenant ID, and the Braze Liquid variable for the user ID.&#x20;
   1. **Format:** `https://<YOUR_OL_INSTANCE>/api/<TENANT_ID>/member/loyaltyCardNumber={{${user_id}}}`&#x20;
   2. **Request Method:** `PATCH`&#x20;
   3. **Request Headers:**&#x20;
      * `Content-Type`: `application/json`
      * `X-AUTH-TOKEN`: `<YOUR_PERMANENT_TOKEN>`
      * `User-Agent: Braze`&#x20;
   4. **Request Body:** Select `Raw text` and paste the payload. You can customize the `key` and `value` to match your segment strategy.

```json
{
  "customer": {
    "labels": [
      {
        "key": "braze_vip_segment",
        "value": "optedIn"
      }
    ]
  }
}
```

{% endstep %}

{% step %}

#### Configure the Trigger

1. Navigate to the **Delivery** or **Entry Schedule** tab.
2. **Delivery Method**: Action-Based.
3. **Trigger**: Define Relevant Trigger
4. **Launch**: Activate the campaign.
   {% endstep %}

{% step %}

#### Testing the Setup

1. Trigger the Sync:
   * Identify a test user in Braze who is not currently in the target segment (e.g., "VIP Users").
   * Manually perform the action that qualifies them for the segment.
     * *Example:* If the segment logic is "Custom Attribute `spend_amount > 500`", go to the user's profile in Braze and manually edit their `spend_amount` to `501`.
   * This forces the user to enter the segment, triggering the webhook campaign.
2. Verify in Braze:
   * Go to Settings > Message Activity Log.
   * Look for the recent webhook event for your campaign.
   * Confirm the status is `200 OK`. If it failed, check the log for error messages (e.g., 401 Unauthorized often means an invalid API token).
3. Verify in Open Loyalty:
   * Log in to the Open Loyalty Admin Panel.
   * Navigate to Members > All Members and search for the test user by their `loyaltyCardNumber`.
   * Open their profile and check the Labels (or Custom Attributes) section.
   * Success: You should see the new label (e.g., `braze_brazeSegmentId: "optedIn"`).
   * *Optional:* If you created a Segment in Open Loyalty based on this label, confirm the user now appears in that segment.
     {% 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/segment-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.
