Skip to main content
POST
/
merchant
/
discount
/
batch
/
template
/
new
Create Batch Discount Template
curl --request POST \
  --url https://api.unibee.dev/merchant/discount/batch/template/new \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "billingType": 123,
  "codePrefix": "<string>",
  "discountType": 123,
  "endTime": 123,
  "quantity": 123,
  "startTime": 123,
  "advance": true,
  "currency": "<string>",
  "cycleLimit": 123,
  "discountAmount": 123,
  "discountPercentage": 123,
  "metadata": {},
  "name": "<string>",
  "planApplyGroup": {
    "currency": [
      "<string>"
    ],
    "groupPlanIntervalSelector": [
      {
        "intervalCount": 123,
        "intervalUnit": "<string>"
      }
    ],
    "type": [
      123
    ]
  },
  "planApplyType": 123,
  "planIds": [
    123
  ],
  "subscriptionLimit": 123,
  "upgradeLongPlanOnly": true,
  "upgradeOnly": true,
  "userLimit": 123,
  "userScope": 123
}
'
{
  "code": 123,
  "data": {
    "template": {
      "advance": true,
      "billingType": 123,
      "childCodeCount": 123,
      "code": "<string>",
      "codePrefix": "<string>",
      "createTime": 123,
      "currency": "<string>",
      "cycleLimit": 123,
      "discountAmount": 123,
      "discountPercentage": 123,
      "discountType": 123,
      "endTime": 123,
      "id": 123,
      "isDeleted": 123,
      "merchantId": 123,
      "metadata": {},
      "name": "<string>",
      "planApplyGroup": {
        "currency": [
          "<string>"
        ],
        "groupPlanIntervalSelector": [
          {
            "intervalCount": 123,
            "intervalUnit": "<string>"
          }
        ],
        "type": [
          123
        ]
      },
      "planApplyType": 123,
      "planIds": [
        123
      ],
      "quantity": 123,
      "startTime": 123,
      "status": 123,
      "type": 123,
      "upgradeLongerOnly": true,
      "upgradeOnly": true,
      "usedChildCodeCount": 123,
      "userLimit": 123,
      "userScope": 123
    }
  },
  "merchantId": 123,
  "message": "<string>",
  "redirect": "<string>",
  "requestId": "<string>"
}

Endpoint Overview

POST https://api.unibee.dev/merchant/discount/batch/template/new Create a batch discount code template. Template must be activated before generating child codes.

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
advancebooleanNoAdvanceConfig, enable advanced configurations
billingTypeintegerYesThe billing type of the discount code, 1-one-time, 2-recurring
codePrefixstringYesThe unique code prefix for this batch template, will be used as template identifier and child code prefix, length 1-20
currencystringNoThe discount currency, available when discount_type is fixed_amount
cycleLimitintegerNoThe count limitation of subscription cycle, 0-no limit
discountAmountintegerNoThe discount amount, available when discount_type is fixed_amount
discountPercentageintegerNoThe discount percentage, 100=1%, available when discount_type is percentage
discountTypeintegerYesThe discount type of the discount code, 1-percentage, 2-fixed_amount
endTimeintegerYesThe end time of discount code can effect, utc timestamp in seconds
metadataobjectNoMetadata, custom key-value pairs
namestringNoThe batch template’s display name
planApplyGroupstringNo
planApplyTypeintegerNoPlan apply type, 0-apply for all, 1-apply for plans specified, 2-exclude for plans specified, 3-Apply to Plans by Groups, 4-Apply to Plans except by Groups
planIdsarrayNoIds of plan which discount code can effect
quantityintegerYesTarget number of child codes to generate, max 10000
startTimeintegerYesThe start time of discount code can effect, utc timestamp in seconds
subscriptionLimitintegerNoThe limit of every subscription apply, 0-unlimited
upgradeLongPlanOnlybooleanNoAdvanceConfig, true-forbid for all except upgrade to longer plan
upgradeOnlybooleanNoAdvanceConfig, true-forbid for all except same interval upgrade action
userLimitintegerNoAdvanceConfig, The limit of every customer can apply, 0-unlimited
userScopeintegerNoAdvanceConfig, Apply user scope, 0-for all, 1-for only new user, 2-for only renewals

Request examples

cURL

curl -X POST "https://api.unibee.dev/merchant/discount/batch/template/new" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "advance": false,
  "billingType": 0,
  "codePrefix": "",
  "currency": "",
  "cycleLimit": 0,
  "discountAmount": 0,
  "discountPercentage": 0,
  "discountType": 0,
  "endTime": 0,
  "metadata": {},
  "name": "",
  "planApplyGroup": "",
  "planApplyType": 0,
  "planIds": [],
  "quantity": 0,
  "startTime": 0,
  "subscriptionLimit": 0,
  "upgradeLongPlanOnly": false,
  "upgradeOnly": false,
  "userLimit": 0,
  "userScope": 0
}'

Sandbox

curl -X POST "https://api-sandbox.unibee.top/merchant/discount/batch/template/new" \
  -H "Authorization: Bearer YOUR_SANDBOX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "advance": false,
  "billingType": 0,
  "codePrefix": "",
  "currency": "",
  "cycleLimit": 0,
  "discountAmount": 0,
  "discountPercentage": 0,
  "discountType": 0,
  "endTime": 0,
  "metadata": {},
  "name": "",
  "planApplyGroup": "",
  "planApplyType": 0,
  "planIds": [],
  "quantity": 0,
  "startTime": 0,
  "subscriptionLimit": 0,
  "upgradeLongPlanOnly": false,
  "upgradeOnly": false,
  "userLimit": 0,
  "userScope": 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.templateobject
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

Create a batch discount code template. Template must be activated before generating child codes.

billingType
integer<int>
required

The billing type of the discount code, 1-one-time, 2-recurring

codePrefix
string<string>
required

The unique code prefix for this batch template, will be used as template identifier and child code prefix, length 1-20

discountType
integer<int>
required

The discount type of the discount code, 1-percentage, 2-fixed_amount

endTime
integer<*int64>
required

The end time of discount code can effect, utc timestamp in seconds

quantity
integer<*int64>
required

Target number of child codes to generate, max 10000

startTime
integer<*int64>
required

The start time of discount code can effect, utc timestamp in seconds

advance
boolean<*bool>

AdvanceConfig, enable advanced configurations

currency
string<string>

The discount currency, available when discount_type is fixed_amount

cycleLimit
integer<int>

The count limitation of subscription cycle, 0-no limit

discountAmount
integer<int64>

The discount amount, available when discount_type is fixed_amount

discountPercentage
integer<int64>

The discount percentage, 100=1%, available when discount_type is percentage

metadata
object

Metadata, custom key-value pairs

name
string<*string>

The batch template's display name

planApplyGroup
object
planApplyType
integer<*int>

Plan apply type, 0-apply for all, 1-apply for plans specified, 2-exclude for plans specified, 3-Apply to Plans by Groups, 4-Apply to Plans except by Groups

planIds
integer<int64>[]

Ids of plan which discount code can effect

subscriptionLimit
integer<int>

The limit of every subscription apply, 0-unlimited

upgradeLongPlanOnly
boolean<*bool>

AdvanceConfig, true-forbid for all except upgrade to longer plan

upgradeOnly
boolean<*bool>

AdvanceConfig, true-forbid for all except same interval upgrade action

userLimit
integer<*int>

AdvanceConfig, The limit of every customer can apply, 0-unlimited

userScope
integer<*int>

AdvanceConfig, Apply user scope, 0-for all, 1-for only new user, 2-for only renewals

Response

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