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

# Create Coupon Code

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

Create a new code for the promotion.

**Note:**
The default rate limit for this endpoint is 40 concurrent requests.

Reference: https://docs.bigcommerce.com/developer/api-reference/rest/admin/management/promotions/coupon-codes-single/create-promotion-code

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

- `code` (string, required) — A unique code that can be used to manually apply a discount. Only letters, numbers, white spaces, underscores, and hyphens are allowed.
- `max_uses` (integer, optional) — The maximum number of times you can use this coupon code. The default value is 0, which represents unlimited uses. The parent promotion's `max_uses` field overrides the coupon code's `max_uses` field.
- `max_uses_per_customer` (integer, optional) — The maximum number of times a specific customer can use this coupon code. The default value is 0, which represents unlimited uses.

## Response

### 201

The requested coupon code.

- `data` (CouponCode, optional) — A `CouponCode` object encapsulates attributes of a coupon code.
- `meta` (PromotionsPromotionIdCodesPostResponsesContentApplicationJsonSchemaMeta, optional) — Empty meta object, which may be used at a later time.

## Types

### CouponCode

A `CouponCode` object encapsulates attributes of a coupon code.

- `id` (integer, required) — An auto-generated unique identifier for the coupon code.
- `code` (string, required) — A unique code that can be used to manually apply a discount. Only letters, numbers, white spaces, underscores and hyphens are allowed.
- `current_uses` (integer, required) — A read-only count of the times this coupon code has been used.
- `created` (datetime, required) — The date and time when this coupon code was created.
- `max_uses` (integer, optional) — The maximum number of times you can use this coupon code. The default value is 0, which represents unlimited uses.
- `max_uses_per_customer` (integer, optional) — The maximum number of times a specific customer can use this coupon code. The default value is 0, which represents unlimited uses.
- `schedule` (CouponCodeSchedule, optional, nullable) — The custom validity window of this coupon code. `null` when the code inherits the promotion's schedule. A code is custom-scheduled if and only if `schedule` is non-null. Note: the promotion object also has a field named `schedule`. That field controls on which days of the week the promotion is available, and has no relation to this field.

### PromotionsPromotionIdCodesPostResponsesContentApplicationJsonSchemaMeta

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

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

## Examples

**Request**

```json
{
  "code": "string"
}
```

**Response**

```json
{
  "data": {
    "id": 1,
    "code": "TEST_COUPON",
    "current_uses": 0,
    "created": "2019-01-20T22:00:00+00:00",
    "max_uses": 10,
    "max_uses_per_customer": 5
  },
  "meta": {}
}
```

**SDK Code**

```python example-1
import requests

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

payload = { "code": "string" }
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/codes';
const options = {
  method: 'POST',
  headers: {
    Accept: 'application/json',
    'X-Auth-Token': '<apiKey>',
    'Content-Type': 'application/json'
  },
  body: '{"code":"string"}'
};

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/codes"

	payload := strings.NewReader("{\n  \"code\": \"string\"\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/codes")

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  \"code\": \"string\"\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/codes")
  .header("Accept", "application/json")
  .header("X-Auth-Token", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"code\": \"string\"\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/codes', [
  'body' => '{
  "code": "string"
}',
  '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/codes");
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  \"code\": \"string\"\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 = ["code": "string"] 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/codes")! 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()
```