> ## 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.

# Create Batch Discount Template

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

## 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.

| 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 |
| - | - | - | - |
| `advance` | boolean | No | AdvanceConfig, enable advanced configurations |
| `billingType` | integer | Yes | The billing type of the discount code, 1-one-time, 2-recurring |
| `codePrefix` | string | Yes | The unique code prefix for this batch template, will be used as template identifier and child code prefix, length 1-20 |
| `currency` | string | No | The discount currency, available when discount\_type is fixed\_amount |
| `cycleLimit` | integer | No | The count limitation of subscription cycle, 0-no limit |
| `discountAmount` | integer | No | The discount amount, available when discount\_type is fixed\_amount |
| `discountPercentage` | integer | No | The discount percentage, 100=1%, available when discount\_type is percentage |
| `discountType` | integer | Yes | The discount type of the discount code, 1-percentage, 2-fixed\_amount |
| `endTime` | integer | Yes | The end time of discount code can effect, utc timestamp in seconds |
| `metadata` | object | No | Metadata, custom key-value pairs |
| `name` | string | No | The batch template's display name |
| `planApplyGroup` | string | No | |
| `planApplyType` | integer | No | 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` | array | No | Ids of plan which discount code can effect |
| `quantity` | integer | Yes | Target number of child codes to generate, max 10000 |
| `startTime` | integer | Yes | The start time of discount code can effect, utc timestamp in seconds |
| `subscriptionLimit` | integer | No | The limit of every subscription apply, 0-unlimited |
| `upgradeLongPlanOnly` | boolean | No | AdvanceConfig, true-forbid for all except upgrade to longer plan |
| `upgradeOnly` | boolean | No | AdvanceConfig, true-forbid for all except same interval upgrade action |
| `userLimit` | integer | No | AdvanceConfig, The limit of every customer can apply, 0-unlimited |
| `userScope` | integer | No | AdvanceConfig, Apply user scope, 0-for all, 1-for only new user, 2-for only renewals |

***

## Request examples

### cURL

```bash theme={null}
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

```bash theme={null}
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.

| Field | Type | Description |
| - | - | - |
| `code` | integer | Response code. `0` = success |
| `data` | object | Response payload |
| `data.template` | object | |
| `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. |

When `code` in the response body is non-zero, check `message` for details. Use `requestId` when contacting support.


## OpenAPI

````yaml post /merchant/discount/batch/template/new
openapi: 3.0.0
info:
  description: UniBee Api Server
  license:
    name: Apache-2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
  title: OpenAPI UniBee
  version: daily,buildtime:202607240926
servers:
  - url: https://api.unibee.dev
  - url: https://api-sandbox.unibee.top
security:
  - Authorization: []
paths:
  /merchant/discount/batch/template/new:
    post:
      tags:
        - Batch Discount
      summary: Create Batch Discount Template
      description: >-
        Create a batch discount code template. Template must be activated before
        generating child codes.
      requestBody:
        content:
          application/json:
            schema:
              $ref: >-
                #/components/schemas/unibee.api.merchant.discount.BatchTemplateNewReq
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  code:
                    format: int
                    properties: {}
                    type: integer
                  data:
                    properties:
                      template:
                        $ref: >-
                          #/components/schemas/unibee.api.bean.MerchantBatchDiscountCodeTemplate
                    type: object
                  merchantId:
                    format: int64
                    properties: {}
                    type: integer
                  message:
                    format: string
                    properties: {}
                    type: string
                  redirect:
                    format: string
                    properties: {}
                    type: string
                  requestId:
                    format: string
                    properties: {}
                    type: string
                type: object
          description: ''
components:
  schemas:
    unibee.api.merchant.discount.BatchTemplateNewReq:
      description: >-
        Create a batch discount code template. Template must be activated before
        generating child codes.
      properties:
        advance:
          description: AdvanceConfig, enable advanced configurations
          format: '*bool'
          properties: {}
          type: boolean
        billingType:
          description: The billing type of the discount code, 1-one-time, 2-recurring
          format: int
          properties: {}
          type: integer
        codePrefix:
          description: >-
            The unique code prefix for this batch template, will be used as
            template identifier and child code prefix, length 1-20
          format: string
          properties: {}
          type: string
        currency:
          description: The discount currency, available when discount_type is fixed_amount
          format: string
          properties: {}
          type: string
        cycleLimit:
          description: The count limitation of subscription cycle, 0-no limit
          format: int
          properties: {}
          type: integer
        discountAmount:
          description: The discount amount, available when discount_type is fixed_amount
          format: int64
          properties: {}
          type: integer
        discountPercentage:
          description: >-
            The discount percentage, 100=1%, available when discount_type is
            percentage
          format: int64
          properties: {}
          type: integer
        discountType:
          description: The discount type of the discount code, 1-percentage, 2-fixed_amount
          format: int
          properties: {}
          type: integer
        endTime:
          description: The end time of discount code can effect, utc timestamp in seconds
          format: '*int64'
          properties: {}
          type: integer
        metadata:
          additionalProperties:
            $ref: '#/components/schemas/interface'
          description: Metadata, custom key-value pairs
          format: map[string]interface {}
          properties: {}
          type: object
        name:
          description: The batch template's display name
          format: '*string'
          properties: {}
          type: string
        planApplyGroup:
          $ref: '#/components/schemas/unibee.api.bean.GroupPlanSelector'
        planApplyType:
          description: >-
            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
          format: '*int'
          properties: {}
          type: integer
        planIds:
          description: Ids of plan which discount code can effect
          format: '[]int64'
          items:
            format: int64
            properties: {}
            type: integer
          properties: {}
          type: array
        quantity:
          description: Target number of child codes to generate, max 10000
          format: '*int64'
          properties: {}
          type: integer
        startTime:
          description: The start time of discount code can effect, utc timestamp in seconds
          format: '*int64'
          properties: {}
          type: integer
        subscriptionLimit:
          description: The limit of every subscription apply, 0-unlimited
          format: int
          properties: {}
          type: integer
        upgradeLongPlanOnly:
          description: AdvanceConfig, true-forbid for all except upgrade to longer plan
          format: '*bool'
          properties: {}
          type: boolean
        upgradeOnly:
          description: >-
            AdvanceConfig, true-forbid for all except same interval upgrade
            action
          format: '*bool'
          properties: {}
          type: boolean
        userLimit:
          description: AdvanceConfig, The limit of every customer can apply, 0-unlimited
          format: '*int'
          properties: {}
          type: integer
        userScope:
          description: >-
            AdvanceConfig, Apply user scope, 0-for all, 1-for only new user,
            2-for only renewals
          format: '*int'
          properties: {}
          type: integer
      required:
        - codePrefix
        - billingType
        - discountType
        - startTime
        - endTime
        - quantity
      type: object
    unibee.api.bean.MerchantBatchDiscountCodeTemplate:
      properties:
        advance:
          description: >-
            AdvanceConfig, 0-false,1-true, will enable all advance config if set
            true
          format: bool
          properties: {}
          type: boolean
        billingType:
          description: billing_type, 1-one-time, 2-recurring
          format: int
          properties: {}
          type: integer
        childCodeCount:
          description: Number of generated child codes
          format: int64
          properties: {}
          type: integer
        code:
          description: code
          format: string
          properties: {}
          type: string
        codePrefix:
          description: codePrefix
          format: string
          properties: {}
          type: string
        createTime:
          description: create utc time
          format: int64
          properties: {}
          type: integer
        currency:
          description: currency of discount, available when discount_type is fixed_amount
          format: string
          properties: {}
          type: string
        cycleLimit:
          description: the count limitation of subscription cycle , 0-no limit
          format: int
          properties: {}
          type: integer
        discountAmount:
          description: amount of discount, available when discount_type is fixed_amount
          format: int64
          properties: {}
          type: integer
        discountPercentage:
          description: >-
            percentage of discount, 100=1%, available when discount_type is
            percentage
          format: int64
          properties: {}
          type: integer
        discountType:
          description: discount_type, 1-percentage, 2-fixed_amount
          format: int
          properties: {}
          type: integer
        endTime:
          description: end of discount available utc time, 0-invalid
          format: int64
          properties: {}
          type: integer
        id:
          description: Id
          format: int64
          properties: {}
          type: integer
        isDeleted:
          description: 0-UnDeleted，> 0, Deleted, the deleted utc time
          format: int
          properties: {}
          type: integer
        merchantId:
          description: merchantId
          format: int64
          properties: {}
          type: integer
        metadata:
          additionalProperties:
            $ref: '#/components/schemas/interface'
          format: map[string]interface {}
          properties: {}
          type: object
        name:
          description: name
          format: string
          properties: {}
          type: string
        planApplyGroup:
          $ref: '#/components/schemas/unibee.api.bean.GroupPlanSelector'
        planApplyType:
          description: >-
            plan apply type, 0-apply for all, 1-apply for plans specified,
            2-exclude for plans specified, 3-Apply to Plans by Groups(Billing
            Period Included), 4-Apply to Plans except by Groups(Billing Period
            Included)
          format: int
          properties: {}
          type: integer
        planIds:
          description: >-
            Ids of plan which discount code can effect, default effect all plans
            if not set
          format: '[]int64'
          items:
            format: int64
            properties: {}
            type: integer
          properties: {}
          type: array
        quantity:
          description: quantity of code, 0-no limit
          format: int64
          properties: {}
          type: integer
        startTime:
          description: start of discount available utc time
          format: int64
          properties: {}
          type: integer
        status:
          description: status, 1-editable, 2-active, 3-deactivate, 4-expire, 10-archive
          format: int
          properties: {}
          type: integer
        type:
          description: type, 1-external discount code, 2-batch code template, 3-batch code
          format: int
          properties: {}
          type: integer
        upgradeLongerOnly:
          description: >-
            AdvanceConfig, 0-false,1-true, will forbid for all except upgrade to
            longer plan if set true
          format: bool
          properties: {}
          type: boolean
        upgradeOnly:
          description: >-
            AdvanceConfig, 0-false,1-true, will forbid for all except same
            interval upgrade action if set true
          format: bool
          properties: {}
          type: boolean
        usedChildCodeCount:
          description: Number of used child codes
          format: int64
          properties: {}
          type: integer
        userIds:
          description: >-
            Ids of user which discount code can effect, default effect all users
            if not set
          format: '[]int64'
          items:
            format: int64
            properties: {}
            type: integer
          properties: {}
          type: array
        userLimit:
          description: >-
            AdvanceConfig, The limit of every customer can apply, the recurring
            apply not involved, 0-unlimited
          format: int
          properties: {}
          type: integer
        userScope:
          description: >-
            AdvanceConfig, Apply user scope,0-for all, 1-for only new user,
            2-for only renewals, renewals is upgrade&downgrade&renew
          format: int
          properties: {}
          type: integer
      type: object
    interface:
      properties: {}
      type: object
    unibee.api.bean.GroupPlanSelector:
      properties:
        currency:
          format: '[]string'
          items:
            format: string
            properties: {}
            type: string
          properties: {}
          type: array
        groupPlanIntervalSelector:
          format: '[]*bean.GroupPlanIntervalSelector'
          items:
            $ref: '#/components/schemas/unibee.api.bean.GroupPlanIntervalSelector'
          properties: {}
          type: array
        type:
          description: 1-main plan，2-addon plan,3-onetime
          format: '[]int'
          items:
            format: int
            properties: {}
            type: integer
          properties: {}
          type: array
      type: object
    unibee.api.bean.GroupPlanIntervalSelector:
      properties:
        intervalCount:
          description: 'Number Of IntervalUnit，em: day|month|year|week'
          format: int
          properties: {}
          type: integer
        intervalUnit:
          description: 'Plan Interval Unit，em: day|month|year|week'
          format: string
          properties: {}
          type: string
      type: object
  securitySchemes:
    Authorization:
      bearerFormat: JWT
      scheme: bearer
      type: http

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.