# Use notifications with Braze

> In this tutorial, let's set up Braze to receive loyalty notifications from Talon.One and use them to trigger an email campaign. This way, we can inform customers when they earn or redeem loyalty points.

> For the complete documentation index, see [llms.txt](https://docs.talon.one/llms.txt).

Because the [schema](/outbound-notifications) of Talon.One's notification requests doesn't
match the schema of Braze's API endpoints, we can't send our requests to Braze directly.
Instead, we rely on Braze's [Data Transformation](https://www.braze.com/docs/user_guide/data/unification/data_transformation) feature
to transform the requests into valid Braze API calls.

## Talon.One requirements

- You are an [admin](/docs/product/account/account-settings/manage-roles.md#admin-role) user.
- You have set up an [Application](/docs/product/applications/create-and-manage-applications.md).
- You have at least one [customer profile](/docs/dev/concepts/entities/customer-profiles.md) in your Application.
  This profile also exists in Braze, and contains a valid email address.
- You have set up a card-based or profile-based [loyalty program](/docs/product/loyalty-programs/overview.md).

## Braze requirements

- You are an account or workspace [admin](https://www.braze.com/docs/user_guide/administer/global/user_management/permissions#nuances-of-user-permissions).

## Set up the integration

<StepsContainer>

### Generate the webhook URL

First, we must generate a webhook URL to which we can send the loyalty notification requests.

Braze automatically generates a webhook URL when you create a [data transformation](https://www.braze.com/docs/user_guide/data/unification/data_transformation).
So let's do that:

1. In Braze, open **Data Settings** > **Data Transformation**.
1. Click **Create transformation** and configure the following parameters:
   - In **Transformation name**, type a name for the transformation.
   - In **Editing experience**, select **Start from scratch**.
   - In **Select destination**, select **POST: Track users**.
     This is the [endpoint](https://www.braze.com/docs/api/endpoints/user_data/post_user_track)
     we will use to trigger the email campaign.
1. Click **Create Transformation**.
1. Next to **Webhook URL**, click **Copy**.

The webhook URL is copied to the clipboard.

### Create the notification

Any of Talon.One's [notifications](/outbound-notifications) can be used to trigger actions in Braze.
In this tutorial, we want to inform customers when they earn or redeem loyalty points,
so let's create an **Added/deducted points** notification:

1. In <Loyalty className="icon"/> **Loyalty**, select your loyalty program.
1. On the left-side menu of the loyalty program, click <Notification className="icon"/> **Notifications**.
1. Click <Add className="icon"/> **Create Notification**.
1. In the **Create Notification** drawer, select **Added/deducted points**.
1. In **Notification name**, type a name for the notification.
1. In the **Request** section, specify the details of the webhook request:
   - In **URL**, paste the Braze webhook URL you [created](#generate-the-webhook-url).
   - In **Header**, add the following header: `Content-Type: application/json`.
1. Send a test request to Braze by clicking <Compass className="icon" /> **Test Notification**.
1. Click **Create Notification**.

### Configure the data transformation

Now that we sent a test request to Braze, we can configure the data transformation to transform
the request into a valid Braze API call:

1. In Braze, close and reopen the data transformation you [created](#generate-the-webhook-url).
   Under **Webhook details**, you should see the payload of the test request you sent from Talon.One.
1. Under **Transformation code**, [write](https://www.braze.com/docs/user_guide/data/unification/data_transformation/creating_a_transformation#step-4-write-transformation-code) your transformation code.
   The code must transform the payload into a valid call to Braze's
   [Track users](https://www.braze.com/docs/api/endpoints/user_data/post_user_track) endpoint.
   For example, you can use the following code:

   ```js
   let brazecall = {
   "events": [
     {
       "external_id": payload.ProfileIntegrationID,
       "name": "Loyalty points changed",
       "time": new Date().toISOString(),
       "properties": {
         "points_amount": payload.Amount,
         "operation": payload.Operation
       }
     }
   ]
   };
   return brazecall;
   ```

   This code creates a new event called `Loyalty points changed` with the following properties:
     - `points_amount`: The amount of added or deducted loyalty points.
     - `operation`: The operation performed (`addition` or `deduction`).

   The event is assigned to the user identified by their integration ID in Talon.One.

1. Click **Validate** to check the code for errors.
1. Click **Activate**.
1. In Talon.One, reopen the notification you created and click **Test Notification**.
   This creates a new event in Braze named `Loyalty points changed`.

### Trigger the email campaign

We can now use the Braze event to trigger an email campaign:

1. In Braze, click **Messaging** > **Campaigns** > **Create campaign** > **Email**.
1. In **Campaign Name**, type a name for your campaign.
1. In **Email Variants**, select **HTML Editor** and click **Blank Template**.
1. Click **Edit Sending Info** and enter a subject line for the email.
1. Click the **Body** tab and insert the following HTML code:

   ```html
   Hey! Here's an update on your loyalty points:

   {% if event_properties.${operation} == "addition" %}
   You have earned {{event_properties.${points_amount}}} loyalty points.
   {% elsif event.properties.operation == "deduction" %}
   You have spent {{event_properties.${points_amount}}} loyalty points.
   {% endif %}

   Have a great day!
   ```

   This code does the following:
   - It reads the `operation` property to check whether points have been added or deducted, and displays a message accordingly.
   - It reads the `points_amount` property to show the amount of loyalty points added or deducted.
1. Click **Done**.
1. In the **Schedule Delivery** tab, select **Action-Based** as the delivery type.
1. In **New Trigger Action**, select **Perform Custom Event** and click **Add Trigger**.
1. In **Choose a custom event**, select **Loyalty points changed**.
1. In the **Target Audiences** tab, ensure that the targeted segment includes
   the email address of the user you want to send the loyalty information to.
1. Enter the remaining required campaign details, and click **Launch Campaign**.

</StepsContainer>

## Test the setup

To test the setup, change the loyalty balance of a customer profile in Talon.One, for example,
by [manually adding loyalty points](/docs/product/loyalty-programs/profile-based/manage-pb-lp-data.md#manually-add-loyalty-points).

This triggers the notification you [created](#create-the-notification), which in turn
[triggers the email campaign](#trigger-the-email-campaign) in Braze
and sends an email to the customer with the updated loyalty points information.
