---
title: "Create a coupon code"
method: POST
path: "/shop/coupons/{couponId}/codes"
tags: ["CouponCodes"]
---

# Create a coupon code

`POST /shop/coupons/{couponId}/codes`

Generates a new `CouponCode` under the parent `Coupon`. All body
fields are optional — pass `code` to set a specific string, omit
to auto-generate. Set `valid_from_date`/`valid_to_date` to
time-limit the code, `multi_use` to allow multiple redemptions,
and `customer_credit_id` + `customer_id` to pre-allocate it.

Requires the `SETTINGS_MANAGE` permission on the coupon's site.
Returns 422 if `code` collides with another code under the same
coupon (codes are unique per coupon, not globally).

## Request body

- object
  - `code` string, nullable — The redemption code customers type. Omitted = auto-generated. Must be unique within the coupon.
  - `valid_from_date` string, date-time, nullable — ISO 8601 timestamp from which the code is redeemable. Null = valid immediately.
  - `valid_to_date` string, date-time, nullable — ISO 8601 timestamp after which the code expires. Must be after `valid_from_date` if both are set.
  - `multi_use` boolean, nullable — When true, the code can be redeemed multiple times (once per customer). When false / omitted, the code is single-use.
  - `customer_credit_id` string, nullable — If set, pre-allocates the code to a specific `CustomerCredit`. Requires `customer_id`.
  - `customer_id` string, uuid, nullable — ID of the customer this code is pre-allocated to. **Required** when `customer_credit_id` is set.
  - `revenue` integer, nullable — Override revenue in the smallest currency unit. Null = use the coupon's default.

## Response `201`

A single `CouponCode`.

- object
  - `data` CouponCode, required — A `CouponCode` is a redeemable code attached to a `Coupon`. The coupon defines the credit-issue rules; the code is what a customer types at checkout to claim it. Codes can be single- or multi-use, time-limited, and optionally pre-allocated to a specific customer.
    - `id` string, object-id, required — Unique identifier for this coupon code.
    - `code` string, required — The redemption code customers type at checkout. Auto-generated when not specified on create.
    - `coupon_id` string, object-id, required — ID of the parent `Coupon` this code belongs to.
    - `valid_from_date` string, date-time, nullable — ISO 8601 timestamp from which the code is redeemable. Null = valid immediately.
    - `valid_to_date` string, date-time, nullable — ISO 8601 timestamp after which the code expires. Null = no expiry.
    - `multi_use` boolean, required — When true, the same code can be redeemed multiple times (once per customer). When false, the code is single-use and burns after the first redemption.
    - `customer_credit_id` string, nullable — If set, the code is pre-allocated to a specific `CustomerCredit` record — typically used to issue targeted promotional credits to a known customer.
    - `customer_id` string, uuid, nullable — ID of the customer this code is pre-allocated to. Required when `customer_credit_id` is set.
    - `revenue` integer, nullable — Override revenue value in the smallest currency unit (e.g. pence/cents) for this code's redemption. When null, the parent coupon's revenue rules apply.

## Other responses

- `401` — The user is unauthenticated
- `403` — The authenticated user does not have permission.
- `404` — The resource couldn't be found
- `422` — The request didn't pass validation

---

[API](https://skmtc.dev/try/apis/trybe-api.md) · [All operations](https://skmtc.dev/try/apis/trybe-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/try/trybe-api/revisions/f37f92702da5/schema)
