Generate Batch Child Codes
Generate child codes for a batch template. Template must be in active status. Supports initial generation, retry on failure, and incremental expansion. Either templateId or templateCode must be provided. If quantity > 1000, isAsync must be set to true. Default is synchronous execution.
Endpoint Overview
POSThttps://api.unibee.dev/merchant/discount/batch/children/generate
Generate child codes for a batch template. Template must be in active status. Supports initial generation, retry on failure, and incremental expansion. Either templateId or templateCode must be provided. If quantity > 1000, isAsync must be set to true. Default is synchronous execution.
Authorization
All UniBee Merchant API requests require authentication via API key.| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer <your_api_key> |
Content-Type | Yes | application/json (for request body) |
Parameters
Parameters for this endpoint are listed below. The schema is also shown in the Try it panel.Request body
| Name | Type | Required | Description |
|---|---|---|---|
codeLength | integer | No | Optional. Total length of generated child code (prefix + random part). Must be > len(templateCode) and < 190. The random part length must be sufficient to support the template’s target quantity. |
isAsync | boolean | No | Force async execution. Default is false (synchronous). If quantity > 1000, this must be set to true. |
quantity | integer | No | Number of child codes to generate. If not provided, generates up to the template’s quantity limit minus existing count. Must not exceed the remaining available quantity. |
randomStyle | string | No | Optional. Random part style: auto|numeric|lower|upper. Default is auto, which infers style from templateCode: all digits -> numeric, all lowercase (with optional digits) -> lower, otherwise upper. |
templateCode | string | No | The template’s code prefix (alternative to templateId) |
templateId | integer | No | The template’s Id (alternative to templateCode) |
Request examples
cURL
Sandbox
Response
Success responses return a JSON envelope withcode, data, message, redirect, and requestId. code 0 indicates success.
| Field | Type | Description |
|---|---|---|
code | integer | Response code. 0 = success |
data | object | Response payload |
data.existingCount | integer | Already generated count before this operation |
data.failedCount | integer | Failed count in this operation (only for synchronous execution) |
data.generatedCount | integer | Newly generated count in this operation (only for synchronous execution) |
data.isAsync | boolean | Whether the generation is running asynchronously |
data.successCount | integer | Successfully inserted count in this operation (only for synchronous execution) |
data.templateCode | string | Template code prefix |
data.templateId | integer | Template ID |
data.totalTarget | integer | Target total quantity |
message | string | Human-readable message |
requestId | string | Request ID for support |
Error handling
| HTTP status | Meaning |
|---|---|
| 400 | Bad request — invalid or missing parameters. Check message in the body. |
| 401 | Unauthorized — missing or invalid API key. |
| 404 | Not found — invalid path or resource. |
| 500 | Server error — retry with backoff. |
code in the response body is non-zero, check message for details. Use requestId when contacting support.Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
Generate child codes for a batch template. Template must be in active status. Supports initial generation, retry on failure, and incremental expansion. Either templateId or templateCode must be provided. If quantity > 1000, isAsync must be set to true. Default is synchronous execution.
Optional. Total length of generated child code (prefix + random part). Must be > len(templateCode) and <= 190. The random part length must be sufficient to support the template's target quantity.
Force async execution. Default is false (synchronous). If quantity > 1000, this must be set to true.
Number of child codes to generate. If not provided, generates up to the template's quantity limit minus existing count. Must not exceed the remaining available quantity.
Optional. Random part style: auto|numeric|lower|upper. Default is auto, which infers style from templateCode: all digits -> numeric, all lowercase (with optional digits) -> lower, otherwise upper.
The template's code prefix (alternative to templateId)
The template's Id (alternative to templateCode)

