> ## Documentation Index
> Fetch the complete documentation index at: https://docs.thanx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Reward Template

> Creates a published reward template at your sandbox merchant, with a granted campaign you can pass to Grant Reward right away.

> [!NOTE]
>
> Please review proper request headers [here](https://docs.thanx.com/consumer/usage/headers.md).

<Snippet file="sandbox/auth.mdx" />

Use this endpoint when the reward templates seeded at provisioning don't cover the reward you need to test. Each call creates one template, publishes it, and creates a granted campaign for it. The response's `campaign_id` is the `campaign_id` for [`POST /rewards/grant`](https://docs.thanx.com/consumer/rewards/grant-reward).

Send the body as JSON (`Content-Type: application/json`), with product IDs as JSON arrays.

### Reward types

Pick the reward with `type`, and with `scope` and `bogo_reward` where the type needs them. Send only the fields the table lists for that reward: any other combination, including a `scope` on `free_item` or a `bogo_reward` on a non-bogo type, returns `422`.

| Reward | `type` | `scope` | `bogo_reward` | `discount` |
| - | - | - | - | - |
| Amount off the purchase | `amount_off` | `purchase` | | Cents |
| Amount off an item | `amount_off` | `item` | | Cents |
| Percent off the purchase | `percent_off` | `purchase` | | Whole percent, 1 to 100 |
| Percent off an item | `percent_off` | `item` | | Whole percent, 1 to 100 |
| Free item | `free_item` | | | Not accepted |
| Free modifier | `free_modifier` | | | Not accepted |
| Buy one, get an amount off the purchase | `bogo` | `purchase` | `amount_off` | Cents |
| Buy one, get a percent off the purchase | `bogo` | `purchase` | `percent_off` | Whole percent, 1 to 100 |
| Buy one, get an amount off an item | `bogo` | `item` | `amount_off` | Cents |
| Buy one, get a percent off an item | `bogo` | `item` | `percent_off` | Whole percent, 1 to 100 |
| Buy one, get an item free | `bogo` | `item` | `free_item` | Not accepted |

### Parameters

**name** `string` *required*

The template name. It is also the name of the granted campaign.

**description** `string` *required*

Short description of the reward, up to 48 characters.

**type** `string` *required*

The reward type: `amount_off`, `percent_off`, `free_item`, `free_modifier` or `bogo`. See [Reward types](#reward-types).

**scope** `string`

`purchase` or `item`. Required for `amount_off`, `percent_off` and `bogo`. Leave it out for `free_item` and `free_modifier`.

**bogo\_reward** `string`

What a `bogo` reward gives: `amount_off`, `percent_off`, or `free_item` (item scope only). Send it only with `type: bogo`, where it is required.

**discount** `integer`

The discount: an amount in cents (`500` is $5) or a whole percent (`10` is 10%), per the [Reward types](#reward-types) table. Required for every reward with a value in that table's `discount` column, and must be at least 1. Rewards that give an item for free don't accept it. On purchase-level rewards, an amount can be at most 25000 ($250).

**minimum** `integer`

Minimum purchase amount, in cents. Must be at least 1, and at most 25000 (\$250) on purchase-level rewards. Leave it out for no minimum, except on amount-off purchase-level rewards (`amount_off` with `scope: purchase`, and `bogo` purchase with `amount_off`): there the `discount` is stored as the minimum when it's left out, and `GET /campaigns` shows it as `minimum_spend`.

**maximum** `integer`

The most the reward can discount, in cents. Must be at least 1. **Required** on percent-off purchase-level rewards (`percent_off` with `scope: purchase`, and `bogo` purchase with `percent_off`). Not accepted by amount-off item rewards (`amount_off` with `scope: item`, and `bogo` item with `amount_off`), which return `422`. On purchase-level rewards it can be at most 25000 (\$250), and neither `minimum` nor an amount `discount` can exceed it.

**redemption\_venue** `string` (default: all)

Where the reward can be redeemed: `all`, `online` or `instore`.

**fine\_print** `string`

Terms and conditions, up to 1,000 characters.

**discounted\_product\_ids** `array[string]`

The product IDs the reward discounts. Required for item-level rewards redeemable `all` or `online`. For `free_modifier`, these are the modifier IDs given for free. Not accepted with `scope: purchase`.

**required\_product\_ids** `array[string]`

The product IDs the user must buy. Only for `bogo` with `scope: item`.

**parent\_product\_ids** `array[string]`

The items the free modifier must be added to. Only for `free_modifier`.

### Product IDs

* Product IDs apply to every venue in `redemption_venue`.
* They aren't checked against any menu or catalog. Use the IDs your test orders will send.
* For `bogo` item rewards, the same ID can go in both `required_product_ids` and `discounted_product_ids` (buy one, get a second free). The basket then needs two lines of that item, since one line can't be both the item bought and the item discounted.
* Up to 100 IDs per list, each up to 255 characters.

### Response

Returns `201` with the template in the same format as the Partner API's [Get Reward Template](https://docs.thanx.com/partner/reward-templates/get-reward-template.md), plus two fields:

**reward\_template** `object`

**reward\_template**

**id** `string`

Reward template ID

**name** `string`

Template name

**type** `string`

`automatic` for purchase-level rewards, `manual` for item-level rewards

**subtype** `string`

`purchase`, `item`, `modifier`, `bogo/purchase` or `bogo/item`

**description** `string`

Short description of the reward

**fine\_print** `string`

Terms and conditions

**discount** `hash`

Discount details, as in the Partner API. `value` is not returned for these subtypes; read `configuration` instead. For rewards that give an item for free, `max_value_cents` is the `maximum` you sent, and is left out without one.

**redemption\_venue** `string`

`all`, `online` or `in_store`

**images** `hash`

Image URLs. Empty for templates created here.

**campaign\_id** `string`

The granted campaign. Pass it as `campaign_id` to [Grant Reward](https://docs.thanx.com/consumer/rewards/grant-reward.md).

**configuration** `hash`

The `discount`, `minimum` and `maximum` you sent, in the units you sent them. Fields you left out are `null`.

The new template also appears in [`GET /campaigns`](https://docs.thanx.com/consumer/sandbox/list-campaigns) and in the Partner API's [List Reward Templates](https://docs.thanx.com/partner/reward-templates/list-reward-templates.md).

> [!WARNING]
>
> Templates created with this endpoint don't send the `reward_template.created` webhook. Use the response, or poll the Partner API's reward templates, instead of waiting for the webhook.

### Errors

| Status | Code | When |
| - | - | - |
| `400` | `BAD_REQUEST` | A required parameter is missing or has the wrong type |
| `400` | `CLIENT_ID_HEADER_INVALID` | The `X-ClientId` header is missing or doesn't match an app |
| `403` | `FORBIDDEN` | Called in production, or your `X-ClientId` isn't tied to exactly one merchant |
| `422` | `REWARD_TEMPLATE_INVALID` | The template can't be created. The `message` says why, for example an unsupported `type` combination, a parameter the reward type doesn't accept, a missing `discount`, a missing `maximum` on a percent-off purchase-level reward, an amount below 1 or over \$250 on a purchase-level reward, a percent over 100, or missing `discounted_product_ids` for an online item reward. Model validation messages show amounts in dollars |

A `422` creates nothing: no template and no campaign.

### Not supported yet

Templates are created with the reward builder's default options. These builder options can't be set through this endpoint yet:

* Modifiers discounted together with the item
* Modifiers the qualifying (buy) item must carry, on buy-one-get-one rewards
* The "what's discounted" choice on buy-one-get-one and item rewards
* One / All coverage for selected modifiers

```bash Amount off an item theme={null}
curl https://api.thanxsandbox.com/reward_templates \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Accept-Version: v4.0" \
  -H "Accept: application/json" \
  -H "X-ClientId: ${client_id}" \
  -d '{
    "name": "$2.50 off a coffee",
    "description": "$2.50 off any coffee",
    "type": "amount_off",
    "scope": "item",
    "discount": 250,
    "minimum": 500,
    "discounted_product_ids": ["SBX-COFFEE-001"]
  }'
```

```bash Percent off the purchase theme={null}
curl https://api.thanxsandbox.com/reward_templates \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Accept-Version: v4.0" \
  -H "Accept: application/json" \
  -H "X-ClientId: ${client_id}" \
  -d '{
    "name": "10% off your order",
    "description": "10% off, up to $10",
    "type": "percent_off",
    "scope": "purchase",
    "discount": 10,
    "maximum": 1000
  }'
```

```bash Free modifier theme={null}
curl https://api.thanxsandbox.com/reward_templates \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Accept-Version: v4.0" \
  -H "Accept: application/json" \
  -H "X-ClientId: ${client_id}" \
  -d '{
    "name": "Free extra shot",
    "description": "A free extra shot on any latte",
    "type": "free_modifier",
    "discounted_product_ids": ["SBX-EXTRA-SHOT"],
    "parent_product_ids": ["SBX-LATTE-001"]
  }'
```

```bash Buy one, get one free theme={null}
curl https://api.thanxsandbox.com/reward_templates \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Accept-Version: v4.0" \
  -H "Accept: application/json" \
  -H "X-ClientId: ${client_id}" \
  -d '{
    "name": "Buy a sandwich, get a cookie",
    "description": "Free cookie with any sandwich",
    "type": "bogo",
    "scope": "item",
    "bogo_reward": "free_item",
    "required_product_ids": ["SBX-SANDWICH-001"],
    "discounted_product_ids": ["SBX-COOKIE-001"]
  }'
```

```json 201 theme={null}
{
  "reward_template": {
    "id": "x7pq2m9kd4",
    "name": "$2.50 off a coffee",
    "type": "manual",
    "subtype": "item",
    "description": "$2.50 off any coffee",
    "fine_print": null,
    "discount": {
      "type": "item",
      "applies_to": "basket",
      "item_name": "$2.50 off any coffee"
    },
    "redemption_venue": "all",
    "images": {},
    "campaign_id": "85133c3c1258",
    "configuration": {
      "discount": 250,
      "minimum": 500,
      "maximum": null
    }
  }
}
```

```json 422 theme={null}
{
  "error": {
    "code": "REWARD_TEMPLATE_INVALID",
    "message": "maximum is not supported for amount_off item rewards"
  }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.