# Create coupons via Bloomreach Engagement

> In this tutorial, let's set up Bloomreach Engagement to generate coupon codes in Talon.One and deliver them to your customers via email.

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

## 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).
- Your Application contains a running [campaign](/docs/product/campaigns/create-and-manage-campaigns.md) with the **Coupons** feature
  [enabled](/docs/product/campaigns/settings/manage-campaign-features.md).

## Bloomreach requirements

- You have set up an [email provider][email providers].
- You have set up a [consent category][consent category].

:::tip
A good understanding of email marketing can help you tailor your scenarios effectively.
We highly recommend you read the [Bloomreach documentation][email marketing path] first.
:::

## Set up the integration

<StepsContainer>

### Create an Integration API key

An [Integration API key][iapi key] allows authentication for incoming webhook requests in Talon.One.

To create an 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.
:::

### Configure webhook authentication

In Bloomreach Engagement, let's configure the [webhook authentication][webhook auth]
for Talon.One so that data can be passed securely in the webhook request. We will use this
webhook authentication while creating a scenario in a later step.

To configure the webhook authentication:

1. In Bloomreach Engagement, open **Data & Assets** > **Integrations**.
1. Click **Add new integration**.
1. Click **HTTP Authentication Schemas**.
1. In **Endpoint**, type the following endpoint URL:

    ```text title="GET Create coupon"
    https://integration.talon.one/customer_engagement/coupon
    ```

    <Button variant="primary" size="l" href="/third-party-api#tag/Customer-engagement-platforms/operation/cep/createCoupon">See API docs</Button>

1. Click **Custom headers**, and enter the following headers:

    | Key                                 | Value                                                                                                        | Type       |
    | ----------------------------------- | ------------------------------------------------------------------------------------------------------------ | ---------- |
    | `Authorization`                     | `ApiKey-v1 YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you [created](#create-an-integration-api-key). | **public** |
    | `destination-hostname`              | The base URL of your Talon.One deployment, for example, `mycompany.europe-west1.talon.one`.                  | **public** |
    | `customer-engagement-platform-name` | `BloomreachEngagement`                                                                                       | **public** |

1. At the top-left of the page, click the name of the integration to rename it appropriately.
1. Click **Save integration**.

### Create a scenario

In Bloomreach Engagement, let's create [a scenario][scenarios] to create a coupon code
in Talon.One and use it in an email.

For this tutorial, we'll create a simple demo scenario that sends an email one minute after you start the scenario. To do so:

1. In Bloomreach Engagement, open **Campaigns** > **Scenarios** > **New Scenario**.
1. (Optional) At the top-left of the page, click the name of the scenario to rename it appropriately.
1. Add a **Now** trigger and a **Wait** operator and connect them.
1. Double-click the **Wait** operator and set **Specific time period** to `1` **minutes**.
1. Add a **Webhook** [action][actions] and connect it to the **Wait** operator.
1. Double-click the **Webhook** action and configure the following parameters:
   1. In the **Editor** tab:
      1. Click the **POST** dropdown and change it to **GET**.
      1. Enter the following URL:

         ```url
         https://integration.talon.one/customer_engagement/coupon?applicationId=YOUR_APPLICATION_ID&campaignId=YOUR_CAMPAIGN_ID&externalCampaignId={{ scenario.name }}
         ```

         - `YOUR_APPLICATION_ID` is the ID of your Application in Talon.One.
         - `YOUR_CAMPAIGN_ID` is the ID of your campaign in Talon.One.

         :::tip
          To see the Application ID and campaign ID, open your Talon.One campaign and check the URL in your browser.
          For example, if the URL is `https://mycompany.europe-west1.talon.one/applications/198/campaigns/373`,
          the Application ID is `198`, and the campaign ID is `373`.
         :::

      1. Click the **Do not process response** dropdown and change it to **Process response as JSON**.
   1. In the **Settings** tab:
      1. Enable **Authentication** and select the webhook authentication you [created](#configure-webhook-authentication).
      1. In **Other**, select the required [consent category][consent category] for your customers.
   1. Click **Done**.
1. Add an **Email** action and connect it to the **Webhook** action.
1. Double-click the **Email** action, click **HTML builder**, and configure the following parameters:
   1. In the **Editor** tab:
      1. In **Subject line**, enter the title of the email.
      1. Add the following HTML code:

         ```html
         <html>
         <head><meta charset="utf-8" /></head>
         <body>
           Your coupon code: {{ webhook.Value }}
         </body>
         </html>
         ```

   1. In the **Settings** tab:
      1. In **Recipients**, choose **Customers matching campaign** if you already set up a campaign, or **Set recipient manually** to test the scenario with a single recipient.
      1. In **Consent category**, select the required [consent category][consent category] for your customers.
   1. Click **Done**.
1. Click **Save**.

The scenario should now look like this:

:::tip
You can also create a [webhook preset][webhook preset], which is a reusable
webhook template that you can use in your Bloomreach Engagement scenarios.
:::

### Run the scenario

Before you run the scenario you [created](#create-a-scenario), you can test and preview the complete workflow
in the **Test** tab.

To run the scenario, click **Start**. You will see a confirmation window
indicating how many customers will be affected by the scenario run.

After one minute, an email will be sent to the configured recipients, containing the text `Your coupon code:`,
followed by the coupon code generated in Talon.One.

</StepsContainer>

## Related pages

- [Bloomreach Engagement documentation][br docs]
  - [Webhooks][webhook auth]
  - [Scenarios][scenarios]
  - [Managing Email Health][email health]
- [Generic CEP endpoints][cep]
  - [Create coupon endpoint][cep create coupon endpoint]

[actions]: https://documentation.bloomreach.com/engagement/docs/scenarios-1
[br docs]: https://documentation.bloomreach.com/engagement/docs
[cep create coupon endpoint]: /third-party-api#tag/Customer-engagement-platforms/operation/cep/createCoupon
[cep]: /docs/dev/technology-partners/cep/integrate-cep.md
[consent category]: https://documentation.bloomreach.com/engagement/docs/consent-categories
[email health]: https://documentation.bloomreach.com/engagement/docs/managing-email-health
[email marketing path]: https://documentation.bloomreach.com/engagement/docs/email-marketing-metrics
[email providers]: https://documentation.bloomreach.com/engagement/docs/email-providers
[iapi key]: /docs/product/applications/manage-api-keys.md
[scenarios]: https://documentation.bloomreach.com/engagement/docs/scenarios-1
[webhook auth]: https://documentation.bloomreach.com/engagement/docs/webhook-authentication
[webhook preset]: https://documentation.bloomreach.com/engagement/docs/webhook-preset-1
