---
title: "Create a discount code"
method: POST
path: "/gateway/discount-codes"
tags: ["Discount Codes"]
---

# Create a discount code

`POST /gateway/discount-codes`

## Request

- Base URL: `https://api.agentaos.ai/api/v1`
- URL: `https://api.agentaos.ai/api/v1/gateway/discount-codes`
- Auth: API key in header `x-api-key`

Set at most one of `percentOff` and `amountOffMinor`. Set neither and the code carries no discount at all: the buyer pays full price and you still see who it brought in. A code with no discount cannot carry a `name`, because the code itself is its name. Terms are fixed once created: to change them, archive this code and create another.

## Request body

- CreateDiscountCodeRequest
  - `code` string, required: What the buyer types. Letters, numbers, dashes and underscores.
  - `name` string: Your own label for the code, shown back to you on the single-code route. Not allowed on a code that carries no discount.
  - `percentOff` number: Percentage off the first invoice. A code cannot take the whole price off — set up a free trial for that.
  - `amountOffMinor` integer: Integer minor units. The currency is the plan's, or your settlement currency when the code is not tied to a plan. It comes off the total the buyer pays, VAT included.
  - `maxRedemptions` integer
  - `expiresAt` string, date-time: Must be in the future.
  - `linkId` string, uuid: Restrict the code to one subscription plan.

## Response `201`

Discount code created.

- DiscountCode: Fully camelCase on the wire.
  - `id` string, uuid, required
  - `code` string, required: As you typed it. Buyers may type it in any case.
  - `kind` 'discount' | 'tracking', required: `discount` changes the price. `tracking` changes nothing and only records who used it.
  - `planLinkId` string, uuid, nullable, required: The one plan this code works on; null means every subscription plan you own.
  - `planName` string, nullable, required
  - `archivedAt` string, date-time, nullable, required
  - `createdAt` string, date-time, required
  - `active` boolean, required: Usable as far as this list can tell: not archived, and fully created. Whether the code has since been used up is answered by the single-code route.

## Other responses

- `400`: A required field is missing, out of range, or the wrong type. `ValidationPipe` also rejects any field not in the documented schema.
- `401`: Missing or invalid `x-api-key`.

---

[API](https://skmtc.dev/agentaos/apis/agentaos-gateway-api.md) · [All operations](https://skmtc.dev/agentaos/apis/agentaos-gateway-api/llms.txt) · [OpenAPI document](https://skmtc.dev/agentaos/apis/agentaos-gateway-api/revisions/3a8ad3c6b965?raw)
