Skip to main content
POST
/
merchant
/
discount
/
batch
/
children
/
generate
Generate Batch Child Codes
curl --request POST \
  --url https://api.unibee.dev/merchant/discount/batch/children/generate \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "codeLength": 123,
  "isAsync": true,
  "quantity": 123,
  "randomStyle": "<string>",
  "templateCode": "<string>",
  "templateId": 123
}
'
{
  "code": 123,
  "data": {
    "existingCount": 123,
    "failedCount": 123,
    "generatedCount": 123,
    "isAsync": true,
    "successCount": 123,
    "templateCode": "<string>",
    "templateId": 123,
    "totalTarget": 123
  },
  "merchantId": 123,
  "message": "<string>",
  "redirect": "<string>",
  "requestId": "<string>"
}

Documentation Index

Fetch the complete documentation index at: https://docs.unibee.dev/llms.txt

Use this file to discover all available pages before exploring further.

Endpoint Overview

POST https://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.
HeaderRequiredDescription
AuthorizationYesBearer <your_api_key>
Content-TypeYesapplication/json (for request body)

Parameters

Parameters for this endpoint are listed below. The schema is also shown in the Try it panel.

Request body

NameTypeRequiredDescription
codeLengthintegerNoOptional. 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.
isAsyncbooleanNoForce async execution. Default is false (synchronous). If quantity > 1000, this must be set to true.
quantityintegerNoNumber 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.
randomStylestringNoOptional. 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.
templateCodestringNoThe template’s code prefix (alternative to templateId)
templateIdintegerNoThe template’s Id (alternative to templateCode)

Request examples

cURL

curl -X POST "https://api.unibee.dev/merchant/discount/batch/children/generate" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "codeLength": 0,
  "isAsync": false,
  "quantity": 0,
  "randomStyle": "",
  "templateCode": "",
  "templateId": 0
}'

Sandbox

curl -X POST "https://api-sandbox.unibee.top/merchant/discount/batch/children/generate" \
  -H "Authorization: Bearer YOUR_SANDBOX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "codeLength": 0,
  "isAsync": false,
  "quantity": 0,
  "randomStyle": "",
  "templateCode": "",
  "templateId": 0
}'

Response

Success responses return a JSON envelope with code, data, message, redirect, and requestId. code 0 indicates success.
FieldTypeDescription
codeintegerResponse code. 0 = success
dataobjectResponse payload
data.existingCountintegerAlready generated count before this operation
data.failedCountintegerFailed count in this operation (only for synchronous execution)
data.generatedCountintegerNewly generated count in this operation (only for synchronous execution)
data.isAsyncbooleanWhether the generation is running asynchronously
data.successCountintegerSuccessfully inserted count in this operation (only for synchronous execution)
data.templateCodestringTemplate code prefix
data.templateIdintegerTemplate ID
data.totalTargetintegerTarget total quantity
messagestringHuman-readable message
requestIdstringRequest ID for support

Error handling

HTTP statusMeaning
400Bad request — invalid or missing parameters. Check message in the body.
401Unauthorized — missing or invalid API key.
404Not found — invalid path or resource.
500Server error — retry with backoff.
When code in the response body is non-zero, check message for details. Use requestId when contacting support.

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json

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.

codeLength
integer<*int>

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<*bool>

Force async execution. Default is false (synchronous). If quantity > 1000, this must be set to true.

quantity
integer<*int64>

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<*string>

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<string>

The template's code prefix (alternative to templateId)

templateId
integer<*int64>

The template's Id (alternative to templateCode)

Response

200 - application/json
code
integer<int>
data
object
merchantId
integer<int64>
message
string<string>
redirect
string<string>
requestId
string<string>