# 生成优惠券码

生成优惠券码。

兑换码生成指南：

* 每个促销活动的兑换码总数没有上限，但单次请求最多只能生成50,000个兑换码。如果请求的数量超过该限制，将返回422 Unprocessable Entity错误。如需生成超过50,000个兑换码，请发送多次请求。

* 为提高可靠性，建议分批生成兑换码，每次请求最多生成10,000个。例如，如需创建100,000个代码，请发送10次"count": 10000的请求，而不是发送2次"count": 50000的请求。请等待每次请求成功响应后，再发送下一次请求。

* 请注意，速率限制为每秒15个请求。批量生成大量券码时，请按顺序发送请求，避免超过速率限制并触发429错误。

* 如需获取代码列表，请调用获取优惠券码方法。

| 参数 | 值 |
|---|---|
| 每次请求的最小券码数量。| 1 |
| 每次请求的最大券码数量。仅在需要尽可能大的单次批量生成时使用。| 50,000 |
| 每次请求的建议券码数量。| 最多10,000个。如需创建更多券码，请按顺序发送多次请求。|

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

## Path parameters:

  - `project_id` (integer, required)
    项目ID。您可以在发布商帐户的项目名称旁找到此参数；使用项目时，也可以在浏览器地址栏中找到此参数。URL格式如下：https://publisher.xsolla.com//projects/。
    Example: 44056

  - `external_id` (integer, required)
    促销活动外部ID。项目内的唯一促销活动标识符。
    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"


