# Add loyalty points via Braze

> Let's set up Braze to give loyalty points to a customer when Talon.One receives a specific Braze event.

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

To do this, we must send a request to Talon.One from a campaign
or canvas body using the [Track event][trackEvent] endpoint for Braze.

## Talon.One requirements

- You have an [Application](/docs/product/applications/create-and-manage-applications.md) and [campaign](/docs/product/campaigns/create-and-manage-campaigns.md) in Talon.One.
- You have at least one [customer profile](/docs/dev/concepts/entities/customer-profiles.md) in your Application. This profile also exists in Braze.
- You have set up a [loyalty program](/docs/product/loyalty-programs/profile-based/create-pb-programs.md).

## Braze requirements

- You have created a [campaign](https://www.braze.com/docs/user_guide/messaging/campaigns/creating_campaign) or [canvas](https://www.braze.com/docs/user_guide/messaging/canvas) in Braze.
- 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.

## Set up the integration

<StepsContainer>

### Create an API key in Talon.One

In the Campaign Manager, create a Braze-specific API key:

1. In your Application, click <Settings className="icon" /> **Settings** > **Integration API Keys**.
1. Click <Add className="icon" /> **Create API Key**.
1. In the **Create API Key** drawer, if you are asked for a key type, select **Production**.
1. In **Key name**, type a name to identify the key.
1. In **Key expiration date**, select a date.

   :::tip
   Avoid choosing expiration dates that fall at the end of the year or during other
   high-traffic periods.
   :::

1. In **Third-party integration**, select **Yes**.
1. From **Platform**, select **{props.partner}**.
1. Click **Create API Key**.
1. Click <Copy className="icon" /> to copy the key for use.

:::note
You cannot view or copy the API key after closing the drawer.
:::

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

### Create a rule in Talon.One

To act on events sent via Braze:

1. Create a new [custom attribute](/docs/product/account/dev-tools/manage-attributes.md#create-a-custom-attribute)
   that represents the event sent from Braze:

   | Property       | Value            |
   | -------------- | ---------------- |
   | **Entity**     | Event            |
   | **Event type** | `My Braze event` |
   | **Type**       | String           |
   | **API name**   | `myBrazeEvent`   |
   | **Name**       | `My Braze event` |

1. Open your campaign and create a rule to award points:

   | What           | Name                                               | Properties                                                                                                                                                                                          |
   | -------------- | -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
   | **Conditions** | Check for event typesand custom event values | Event type: <code>My Braze event</code><Attribute name="My Braze event (Event)" type="custom" /> is equal to <code>test_string</code>. |
   | **Effects**    | Add loyalty points                                 | Select your profile-based loyalty program and set the amount of points to award.                                                                                                                    |

### Send the event to add loyalty points

To send the event, we call the following endpoint:

```bash title="POST Track event"
https://integration.talon.one/braze/event
```

<Button variant="primary" size="l" href="/third-party-api#tag/Braze/operation/braze/trackEvent">
  See API docs
</Button>

To trigger the endpoint, we must use Braze's
[Connected Content](https://www.braze.com/docs/user_guide/messaging/design_and_edit/personalize/connected_content/making_an_api_call) feature.

:::important
We assume that your customer profile in Braze contains a unique identifier that is equal to the customer integration ID in Talon.One.
In this tutorial, we use `${user_id}`. Ensure the user ID matches the integration ID in Talon.One.
:::

1. Open your Braze campaign or canvas for editing.
1. Add the following Connected Content call to the body of your message, where:
   - `YOUR_API_KEY` is the API key you [created](#create-an-api-key-in-talonone).
   - `YOUR_DEPLOYMENT_URL` is the base URL of your Talon.One deployment.

   ```liquid
   {% capture postbody %}
   {"eventType": "My Braze Event", "identifier": "{{ 'now' | date: '%Y-%m-%d %H:%M:%S.%N' }}",
    "type":"string", "customerProfileId":"{{${user_id}}}",
    "eventAttributes": {"myBrazeEvent": "test_string"}}
   {% endcapture %}

   {% connected_content https://integration.talon.one/braze/event
   :headers {
     "Authorization": "ApiKey-v1 YOUR_API_KEY",
     "destination-hostname": "YOUR_DEPLOYMENT_URL"
   }
   :method post
   :body {{postbody}}
   :content_type application/json
   :save result
   %}

   {% for effect in result.effects %}
   {% if effect.effectType == "addLoyaltyPoints" %}
      You were awarded {{effect.props.value}} loyalty points!
      (Reason: '{{effect.props.name}}')
   {% endif %}
   {% endfor %}

   HTTP response code: {{result.__http_status_code__}}.
   ```
   :::note
   In the example above, we use a timestamp for the `identifier` parameter. This ensures that a new event is sent for each email during testing. In production, consider using one of the available [personalization tags](https://www.braze.com/docs/user_guide/messaging/design_and_edit/personalize/liquid/supported_personalization_tags), for example, the [dispatch ID](https://www.braze.com/docs/help/help_articles/data/dispatch_id).
   :::

1. To test your request:
   1. In the sidebar, click **Preview & Test**.
   1. In **Preview message as user**, select **Search User** and search for an existing user in Braze.

[trackEvent]: /third-party-api#tag/Braze/operation/braze/trackEvent

</StepsContainer>
