# Generate coupon codes

Generates coupon codes.

Guidelines on code generation:

* There is no maximum total number of codes per promotion, but each request is limited to 50,000 codes. Requests with a higher count returns a 422 Unprocessable Entity error. If you need more than 50,000 codes, send multiple requests.

* For better reliability, we recommend generating codes in smaller batches, up to 10,000 per request. E.g., to create 100,000 codes, send 10 requests with "count": 10000 instead of 2 requests with "count": 50000. Wait for a successful response for each request before sending the next one.

* Keep in mind rate limits that are set to 15 requests per second. When generating large volumes, send requests sequentially to avoid exceeding the rate limit and getting a 429 error.

* To retrieve the list of codes, call the Get coupon codes method.

| Parameter | Value |
|---|---|
| Minimum number of codes per request. | 1 |
| Maximum number of codes per request. Use it only when you need the largest possible single batch. | 50,000 |
| Recommended number of codes per request. | Up to 10,000. If you need to create more, send multiple sequential requests. |

Endpoint: PUT /v2/project/{project_id}/admin/coupon/{external_id}/code/generate
Version: 2.0.0
Security: basicAuth

## Path parameters:

  - `project_id` (integer, required)
    Project ID. You can find this parameter in your Publisher Account next to the project name and in the browser address bar when working with a project. The URL has the following format: https://publisher.xsolla.com//projects/.
    Example: 44056

  - `external_id` (integer, required)
    Promotion external ID. Unique promotion identifier within the project.
    Example: "coupon_44056_1"

## Request fields (application/json):

  - `count` (integer, required)

## Response 200 fields (application/json):

  - `count` (integer)

## Response 401 fields (application/json):

  - `statusCode` (integer)
    Example: 401

  - `errorCode` (integer)
    Example: 1020

  - `errorMessage` (string)
    Example: "[0401-1020]: Error in Authentication method occurred"

## Response 404 fields (application/json):

  - `statusCode` (integer)
    Example: 404

  - `errorCode` (integer)
    Example: 4001

  - `errorMessage` (string)
    Example: "[0401-9802]: Promocode not found"

  - `transactionId` (string)
    Example: "x-x-x-x-transactionId-mock-x-x-x"


