> For the complete documentation index, see [llms.txt](https://apidocs.akinon.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://apidocs.akinon.com/commerce-openapis/admin/bulk-voucher-codes/generate-voucher-codes-in-bulk.md).

# Generate voucher codes in bulk

Generates `count` random voucher codes for a basket offer. Each code is the `prefix` followed by `length` characters randomly drawn from `alphabet`. All generated codes are created in `active` status.

Generation runs **asynchronously**: the endpoint returns `201 Created` immediately with an empty body, and the codes appear in the list endpoint once the background job completes.

Validation rules:

* The target basket offer must be of type `bulk_voucher_code` and in `active` status.
* The alphabet and length must allow at least `count` distinct codes (`len(alphabet) ^ length >= count`).
* The overall code length (`prefix` + `length`) must not exceed 32 characters.
* No previously generated batch may exist with the same prefix and the same overall length.

```json
{"openapi":"3.1.0","info":{"title":"Admin API","version":"1.0.0"},"tags":[{"name":"Bulk Voucher Codes","description":"Administrative endpoints for **bulk voucher codes** — the individually generated, single-use codes that belong to a basket offer of type `bulk_voucher_code`. Typical integrations include distributing campaign codes to customers and redeeming or managing codes from external systems such as in-store checkout (POS) applications. The parent campaigns themselves are managed with the **Basket Offers** endpoints (`/basket_offers/`).\n\n## Core Capabilities\n\n**1. Code Listing & Filtering**\n* Retrieve a paginated list of voucher codes, newest first.\n* Filter by the parent basket offer, code value, status, and assigned user — the filters behind the code list of the management panel (e.g. `?basket_offer=35763&status=active&limit=20&page=1`).\n\n**2. Code Lifecycle Management**\n* Add a single code manually and optionally assign it to a user.\n* Activate or deactivate a code by updating its `status` (used codes are immutable).\n\n**3. Bulk Code Generation**\n* Generate any number of random codes for a campaign from a prefix, alphabet, and length; generation runs asynchronously in the background.\n\n## Code Statuses\n\nA voucher code shares the status vocabulary of basket offers.\n\n| Value | Description |\n|-------|-------------|\n| `active` | The code can be redeemed. Newly created and generated codes always start in this status. |\n| `passive` | The code is disabled and cannot be redeemed. |\n| `used` | The code has been redeemed. A used code can no longer be updated. |\n| `revoked` | The code has been withdrawn. |\n\n## Dynamic Settings & Environment Variables\n\nNo dynamic settings (`dj_dynamic_settings`) are read by these endpoints: listing, creation, update, bulk generation, and the import/export flows are not influenced by any management-panel setting. Note that whether a code is *redeemable on the storefront* is governed by the parent basket offer (its status, dates, conditions) and by the promotion-application settings documented in the **Basket Offers** section — not by these administrative endpoints.\n\n**Environment variables:** No environment variables affect these endpoints."}],"servers":[{"description":"Omnitron Remote Proxy (external access — recommended)","url":"https://{omnitron_url}/api/remote/{channel_id}","variables":{"omnitron_url":{"default":"sandbox.akinon.com","description":"Omnitron server URL (e.g., {omnitron.akinon.com})"},"channel_id":{"default":"1","description":"The channel identifier the remote request is routed through"}}},{"description":"Commerce API Server (internal / direct access only)","url":"https://{commerce_url}/api/v1","variables":{"commerce_url":{"default":"sandbox.akinon.com","description":"Internal commerce server URL, reachable only from within the Omnitron network"}}}],"security":[{"tokenAuth":[]}],"components":{"securitySchemes":{"tokenAuth":{"type":"apiKey","in":"header","name":"Authorization","description":"Token credential sent in the Authorization header, in the form: `Token <your-token>`. Requires a staff (admin) account."}},"schemas":{"BulkVoucherCodeBulkCreateRequest":{"type":"object","description":"The payload of a bulk code generation request.","required":["prefix","count","basket_offer"],"properties":{"basket_offer":{"type":"integer","description":"Identifier of the target basket offer. The offer must be of type `bulk_voucher_code` and in `active` status."},"count":{"type":"integer","minimum":1,"description":"The number of codes to generate."},"prefix":{"type":"string","minLength":2,"description":"The fixed prefix every generated code starts with."},"alphabet":{"type":"string","minLength":1,"default":"ABCDEF0123456789","description":"The characters the random part of the codes is drawn from. Only uppercase English letters and digits are allowed; duplicate characters are collapsed."},"length":{"type":"integer","minimum":1,"default":8,"description":"The length of the random part appended to the prefix. `prefix` + `length` must not exceed 32 characters."}}},"ValidationError":{"type":"object","description":"Returned when the request contains invalid or missing data. Errors are grouped by the field they apply to: each key is the name of a field from the request and its value is a list of one or more messages describing what is wrong with that field. Messages that do not belong to any single field are grouped under `non_field_errors`.","properties":{"non_field_errors":{"type":"array","description":"Error messages that apply to the request as a whole rather than to a specific field.","items":{"type":"string"}}},"additionalProperties":{"type":"array","description":"The list of error messages for the field named by the key.","items":{"type":"string"}}},"Error":{"type":"object","description":"An error response.","properties":{"detail":{"type":"string","description":"A human-readable description of the error."}},"additionalProperties":true}},"responses":{"ValidationError":{"description":"The request contains invalid or missing data.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}},"Unauthorized":{"description":"Authentication credentials were not provided or are invalid.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"Forbidden":{"description":"The authenticated user does not have administrator privileges.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"paths":{"/bulk_voucher_codes/bulk_create/":{"post":{"tags":["Bulk Voucher Codes"],"operationId":"bulkCreateBulkVoucherCodes","summary":"Generate voucher codes in bulk","description":"Generates `count` random voucher codes for a basket offer. Each code is the `prefix` followed by `length` characters randomly drawn from `alphabet`. All generated codes are created in `active` status.\n\nGeneration runs **asynchronously**: the endpoint returns `201 Created` immediately with an empty body, and the codes appear in the list endpoint once the background job completes.\n\nValidation rules:\n* The target basket offer must be of type `bulk_voucher_code` and in `active` status.\n* The alphabet and length must allow at least `count` distinct codes (`len(alphabet) ^ length >= count`).\n* The overall code length (`prefix` + `length`) must not exceed 32 characters.\n* No previously generated batch may exist with the same prefix and the same overall length.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/BulkVoucherCodeBulkCreateRequest"}}}},"responses":{"201":{"description":"The generation job was queued. The response body is empty."},"400":{"$ref":"#/components/responses/ValidationError"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://apidocs.akinon.com/commerce-openapis/admin/bulk-voucher-codes/generate-voucher-codes-in-bulk.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
