# createCouponBatch

mutation · in the family [Pricing](/reference/pricing/)

## What it does

Mint a batch of unique single-use codes (up to 48) that all unlock one existing coupon’s terms.

Mint a batch of UNIQUE SINGLE-USE child codes under one existing Coupon: ONE atomic transaction (48 codes max — bigger campaigns mint more batches); the codes are SERVER-GENERATED (<prefix>-<random tail>, the org-group code namespace — a collision refuses CONFLICT/COUPON_CODE_TAKEN, retry-able) and each unlocks the PARENT coupon's terms with ONE extra law: single use (the place transaction stamps it once-only). The coupon must be same-tenant + non-doomed (CONFLICT/REF_STATE). Requires the unrestricted capability. Template class (the coupon-authoring class — v79).

## What happens

Creates the batch and its codes in one step; the codes are generated for you.

## Who may call it

Capability area: **Pricing** — Prices, price schedules, promotions, coupons and the money rules of selling.

- Owner
- Manager
- An API key whose scope allows `api:createCouponBatch`

## Arguments

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `couponId` | [ID](/types/#scalars) `ID!` | yes | No further notes. |
| `count` | [Int](/types/#scalars) `Int!` | yes | No further notes. |
| `codePrefix` | [String](/types/#scalars) `String!` | yes | No further notes. |
| `caption` | [String](/types/#scalars) | no | No further notes. |

## Returns

[CouponBatchMint](/types/CouponBatchMint/) `CouponBatchMint!` — The createCouponBatch result — the batch + its minted codes (also listable later via couponBatchCodes).

## Example request

```graphql
mutation ExampleCreateCouponBatch($couponId: ID!, $count: Int!, $codePrefix: String!, $caption: String) {
  createCouponBatch(couponId: $couponId, count: $count, codePrefix: $codePrefix, caption: $caption) {
    couponBatch {
      id
      sysId
      type
      caption
      status
      parentId
      rootId
      createdAt
      updatedAt
      revisionNum
      revision
      codePrefix
      codeCount
    }
  }
}
```

Variables:

```json
{
  "couponId": "01900000-0000-7000-8000-d21413c60000",
  "count": 1,
  "codePrefix": "<code prefix>",
  "caption": "Blue jeans"
}
```

Send it with the envelope naming the version: `"extensions": {"at": {"version": {"name":"genesis","number":0}}}`.

## Example response

```json
{
  "data": {
    "createCouponBatch": {
      "couponBatch": {
        "id": "01900000-0000-7000-8000-37386ae00000",
        "sysId": "CB-EXMP-0000-000F",
        "type": "CouponBatch",
        "caption": "Blue jeans",
        "status": "active",
        "parentId": "01900000-0000-7000-8000-065235280000",
        "rootId": "01900000-0000-7000-8000-a093dd800000",
        "createdAt": "2027-01-31T00:00:00.000Z",
        "updatedAt": "2027-01-31T00:00:00.000Z",
        "revisionNum": 1,
        "revision": "01900000-0000-7000-8000-b7960e180000",
        "codePrefix": "<code prefix>",
        "codeCount": 1
      }
    }
  },
  "extensions": {
    "at": {
      "callId": "01EXAMPLE-CALL-ID",
      "version": {
        "requested": {
          "name": "genesis",
          "number": 0
        },
        "serviced": {
          "name": "genesis",
          "number": 0
        }
      }
    }
  }
}
```

## Errors this call can answer

- `VALIDATION/INVALID` — Something in the request is not valid. ([VALIDATION](/errors/VALIDATION/))
- `AUTHN/REQUIRED` — Sign in to do this. ([AUTHN](/errors/AUTHN/))
- `AUTHZ/FORBIDDEN` — Your role does not allow this action. ([AUTHZ](/errors/AUTHZ/))
- `RATE_LIMIT/THROTTLED` — Too many requests in a short time. ([RATE_LIMIT](/errors/RATE_LIMIT/))
- `NOT_FOUND/*` — That record could not be found. ([NOT_FOUND](/errors/NOT_FOUND/))
- `CONFLICT/*` — The record’s state, or a change made in the meantime, does not allow this; the codes are on the CONFLICT page. ([CONFLICT](/errors/CONFLICT/))
- `VALIDATION/VERSION_REQUIRED` — The request did not say which app version it came from. ([VALIDATION](/errors/VALIDATION/))

## Used in

- [Issue coupon codes — one code or a batch](/use-cases/issue-coupons/)
