> This page is for Developer.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.bigcommerce.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.bigcommerce.com/_mcp/server.

# Generate Multiple Coupon Codes

POST https://api.bigcommerce.com/stores/{store_hash}/v3/promotions/{promotion_id}/codegen
Content-Type: application/json

Generate a batch of coupon codes for a particular bulk coupon promotion.

**Note:**
* batch_size (number of codes generated per request) is limited to 250. If batch_size is not an integer or larger than 250, it will return a 422 error code.
* The default rate limit for this endpoint is 10 concurrent requests.

Reference: https://docs.bigcommerce.com/developer/api-reference/rest/admin/management/promotions/coupon-codes-bulk/generate-promotion-codes-batch

## Authentication

- `X-Auth-Token` header (required) — ### OAuth scopes | UI Name | Permission | Parameter | |:--------|:-----------|:----------| | Marketing | modify | `store_v2_marketing` | | Marketing | read-only | `store_v2_marketing_read_only` | ### Authentication header | Header | Argument | Description | |:-------|:---------|:------------| | `X-Auth-Token` | `access_token` | For more about API accounts that generate `access_token`s, see [API Accounts and OAuth Scopes](/developer/docs/overview/api-fundamentals/api-accounts#api-accounts). | ### Further reading For example requests and more information about authenticating BigCommerce APIs, see [Authentication and Example Requests](/developer/docs/overview/api-fundamentals/api-accounts). For more about BigCommerce OAuth scopes, see [API Accounts and OAuth Scopes](/developer/docs/overview/api-fundamentals/api-accounts#api-accounts). For a list of API status codes, see [API Status Codes](/developer/api-reference/rest/overview#rest-http-status-codes).

## Request

### Path parameters

- `promotion_id` (string, required) — The ID of the associated promotion.
- `store_hash` (string, required) — Permanent ID of the BigCommerce store.

### Headers

- `Accept` (string, required, default: application/json) — The [MIME type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) of the response body.

### Body (application/json)

This endpoint expects an object.

- `batch_size` (integer, required) — The number of coupon codes to generate in each batch. The maximum value is 250.
- `max_uses` (integer, optional) — The maximum number of times each coupon code can be used. The default value is 1. The value 0 means unlimited usage.
- `max_uses_per_customer` (integer, optional) — The maximum number of times a specific customer can use each coupon code. The default value is 1. The value 0 means unlimited usage.
- `prefix` (string, optional) — The fixed text that will appear at the beginning of every generated coupon code. Only capital letters, numbers, underscores and hyphens are allowed.
- `suffix` (string, optional) — The fixed text that will appear at the end of every generated coupon code. Only capital letters, numbers, underscores and hyphens are allowed.
- `delimiter` (string, optional) — An optional single character (_ or -) that will be placed between the prefix and the randomly generated code, and again between the randomly generated code and the suffix. It will only be applied if a valid prefix or suffix is present.
- `exclude_characters` (list of string, optional) — An optional array of single length string elements to exclude from the randomly generated part. Only capital letters and numbers are allowed. The default value is an empty array [].
- `code_length` (integer, optional) — The length of the random string to be generated for each coupon code. The value must be between 6 and 16. The default length is 16. The total length of each generated coupon code is calculated as `:` code_length + length of prefix with delimiter + length of suffix with delimiter. The maximum total length of a coupon code is 50.
- `schedule` (CouponCodeSchedule, optional, nullable) — Optional custom schedule applied to every code generated in the batch. Omitted or `null` means the codes inherit the promotion's schedule.

## Response

### 201

The result of the bulk coupon code request.

- `data` (PromotionsPromotionIdCodegenPostResponsesContentApplicationJsonSchemaData, required)
- `meta` (PromotionsPromotionIdCodegenPostResponsesContentApplicationJsonSchemaMeta, optional) — Empty meta object, which may be used at a later time.

## Errors

### 400 Bad Request Error

Invalid request.

- `status` (string, optional) — Bad request.
- `title` (string, optional) — The error title describing the particular error.
- `type` (string, optional) — Error payload for the BigCommerce API.
- `detail` (string, optional) — Detailed summary describing the particular error.

### 403 Forbidden Error

Forbidden.

- `status` (string, optional) — Forbidden.
- `title` (string, optional) — The error title describing the particular error.
- `error` (string, optional) — Error payload for the BigCommerce API.

### 405 Method Not Allowed Error

Method not allowed. Bulk code generation is only supported for promotions with redemption_type of 'COUPON' and coupon_type of 'BULK'.

- `status` (string, optional) — Method not allowed.
- `title` (string, optional) — The error title describing the particular error.
- `error` (string, optional) — Error payload for the BigCommerce API.

### 422 Unprocessable Entity Error

The request payload is invalid.

- `errors` (list of Error, optional)

## Types

### CouponCodeSchedule

A custom validity window for a coupon code, independent of (but fully contained within) the parent promotion's schedule.

- `valid_from` (datetime, required) — The date and time from which the code can be redeemed (RFC3339 UTC). Must be within the promotion's schedule.
- `valid_until` (datetime, required, nullable) — The date and time until which the code can be redeemed (RFC3339 UTC). Must be after `valid_from` and within the promotion's schedule. `null` means no end, and is only allowed if the parent promotion does not have an end date. Must not be `null` if the parent promotion has an end date.

### PromotionsPromotionIdCodegenPostResponsesContentApplicationJsonSchemaData

- `created` (datetime, optional) — The date and time when the codes were created.
- `max_uses` (integer, optional) — The maximum number of times each code can be used.
- `max_uses_per_customer` (integer, optional) — The maximum number of times each customer can use a code.
- `batch_size` (integer, optional) — The number of codes generated in the batch.
- `codes` (list of BulkCouponCode, optional)
- `schedule` (CouponCodeSchedule, optional, nullable) — The custom schedule applied to every code in the batch, or `null` when the codes inherit the promotion's schedule.

### PromotionsPromotionIdCodegenPostResponsesContentApplicationJsonSchemaMeta

Empty meta object, which may be used at a later time.

### Error

- `status` (integer, optional)
- `title` (string, optional)
- `type` (string, optional)

### BulkCouponCode

- `code` (string, optional) — A unique, 16-character code that can be used to manually apply a discount. The code consists of randomly generated capital letters and numbers.

## Examples

### example-1

**Request**

```json
{
  "batch_size": 5
}
```

**Response**

```json
{
  "data": {
    "created": "2019-01-20T22:00:00+00:00",
    "max_uses": 10,
    "max_uses_per_customer": 5,
    "batch_size": 5,
    "codes": [
      {
        "code": "WFYUYQM1W1ZYGK7S"
      },
      {
        "code": "TQ4PBBEK9SCZ212Z"
      },
      {
        "code": "B2YKV43O18LPJGNS"
      },
      {
        "code": "OSGJJBV3WBRC3G7X"
      },
      {
        "code": "XA8JS9T2N0C2TGS3"
      }
    ]
  },
  "meta": {}
}
```

**SDK Code**

```python example-1
import requests

url = "https://api.bigcommerce.com/stores/store_hash/v3/promotions/promotion_id/codegen"

payload = { "batch_size": 5 }
headers = {
    "Accept": "application/json",
    "X-Auth-Token": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript example-1
const url = 'https://api.bigcommerce.com/stores/store_hash/v3/promotions/promotion_id/codegen';
const options = {
  method: 'POST',
  headers: {
    Accept: 'application/json',
    'X-Auth-Token': '<apiKey>',
    'Content-Type': 'application/json'
  },
  body: '{"batch_size":5}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go example-1
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.bigcommerce.com/stores/store_hash/v3/promotions/promotion_id/codegen"

	payload := strings.NewReader("{\n  \"batch_size\": 5\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Accept", "application/json")
	req.Header.Add("X-Auth-Token", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby example-1
require 'uri'
require 'net/http'

url = URI("https://api.bigcommerce.com/stores/store_hash/v3/promotions/promotion_id/codegen")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Accept"] = 'application/json'
request["X-Auth-Token"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"batch_size\": 5\n}"

response = http.request(request)
puts response.read_body
```

```java example-1
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.bigcommerce.com/stores/store_hash/v3/promotions/promotion_id/codegen")
  .header("Accept", "application/json")
  .header("X-Auth-Token", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"batch_size\": 5\n}")
  .asString();
```

```php example-1
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.bigcommerce.com/stores/store_hash/v3/promotions/promotion_id/codegen', [
  'body' => '{
  "batch_size": 5
}',
  'headers' => [
    'Accept' => 'application/json',
    'Content-Type' => 'application/json',
    'X-Auth-Token' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp example-1
using RestSharp;

var client = new RestClient("https://api.bigcommerce.com/stores/store_hash/v3/promotions/promotion_id/codegen");
var request = new RestRequest(Method.POST);
request.AddHeader("Accept", "application/json");
request.AddHeader("X-Auth-Token", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"batch_size\": 5\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift example-1
import Foundation

let headers = [
  "Accept": "application/json",
  "X-Auth-Token": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["batch_size": 5] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.bigcommerce.com/stores/store_hash/v3/promotions/promotion_id/codegen")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### example-2 - custom schedule

**Request**

```json
{
  "batch_size": 5
}
```

**Response**

```json
{
  "data": {
    "created": "2026-08-28T22:00:00+00:00",
    "max_uses": 10,
    "max_uses_per_customer": 5,
    "batch_size": 3,
    "codes": [
      {
        "code": "WFYUYQM1W1ZYGK7S"
      },
      {
        "code": "TQ4PBBEK9SCZ212Z"
      },
      {
        "code": "B2YKV43O18LPJGNS"
      }
    ],
    "schedule": {
      "valid_from": "2026-09-01T00:00:00+00:00",
      "valid_until": "2026-09-30T23:59:59+00:00"
    }
  },
  "meta": {}
}
```

**SDK Code**

```python example-2 - custom schedule
import requests

url = "https://api.bigcommerce.com/stores/store_hash/v3/promotions/promotion_id/codegen"

payload = { "batch_size": 5 }
headers = {
    "Accept": "application/json",
    "X-Auth-Token": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript example-2 - custom schedule
const url = 'https://api.bigcommerce.com/stores/store_hash/v3/promotions/promotion_id/codegen';
const options = {
  method: 'POST',
  headers: {
    Accept: 'application/json',
    'X-Auth-Token': '<apiKey>',
    'Content-Type': 'application/json'
  },
  body: '{"batch_size":5}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go example-2 - custom schedule
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.bigcommerce.com/stores/store_hash/v3/promotions/promotion_id/codegen"

	payload := strings.NewReader("{\n  \"batch_size\": 5\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Accept", "application/json")
	req.Header.Add("X-Auth-Token", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby example-2 - custom schedule
require 'uri'
require 'net/http'

url = URI("https://api.bigcommerce.com/stores/store_hash/v3/promotions/promotion_id/codegen")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Accept"] = 'application/json'
request["X-Auth-Token"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"batch_size\": 5\n}"

response = http.request(request)
puts response.read_body
```

```java example-2 - custom schedule
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.bigcommerce.com/stores/store_hash/v3/promotions/promotion_id/codegen")
  .header("Accept", "application/json")
  .header("X-Auth-Token", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"batch_size\": 5\n}")
  .asString();
```

```php example-2 - custom schedule
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.bigcommerce.com/stores/store_hash/v3/promotions/promotion_id/codegen', [
  'body' => '{
  "batch_size": 5
}',
  'headers' => [
    'Accept' => 'application/json',
    'Content-Type' => 'application/json',
    'X-Auth-Token' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp example-2 - custom schedule
using RestSharp;

var client = new RestClient("https://api.bigcommerce.com/stores/store_hash/v3/promotions/promotion_id/codegen");
var request = new RestRequest(Method.POST);
request.AddHeader("Accept", "application/json");
request.AddHeader("X-Auth-Token", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"batch_size\": 5\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift example-2 - custom schedule
import Foundation

let headers = [
  "Accept": "application/json",
  "X-Auth-Token": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["batch_size": 5] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.bigcommerce.com/stores/store_hash/v3/promotions/promotion_id/codegen")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```