Create Rule Promotion Codes
POSThttps://useast.api.elasticpath.com/v2/rule-promotions/:promotionID/codes
Creates new promotion codes for a specific rule promotion, allowing customers to redeem discounts based on predefined conditions.
- Supports bulk creation of multiple promotion codes in a single request.
- Each code can have individual usage limits.
- Can optionally assign codes to specific users to enforce targeted promotions.
- The promotion codes are case-insensitive.
Regarding first time shopper limitations:
- Orders without payment transactions do not count as completed purchases.
- Canceling or refunding an order does not reinstate first-time shopper status.
- A first-time shopper coupon code cannot have limited uses or be assigned to specific users, meaning the code cannot be restricted by the number of times it can be used or tied to a specific customer ID.
A successful request returns a 201 Created
response with details of the generated promotion codes.
Duplicate Codes
Duplicate promotion codes are supported across different promotions in the store, regardless of their statuses and validity dates. However, duplicate codes cannot be created within the same promotion. This means that shoppers can apply a single coupon code to trigger multiple promotions if those promotions share common coupon codes.
Codes that share the same name can serve different purposes. For example, one code may have per_application
with a limited number of uses, while another identical code can have per_checkout
with unlimited use.
Duplicate Code Handling:
- If a duplicate code is detected within the same promotion, the request will return a
422 Duplicate code
error. - When creating duplicate codes, a message appears with the successful response indicating the duplication.
Please refer to the OpenAPI examples section on this page for sample request structures.
Request
Path Parameters
The unique identifier of the rule promotion.
Header Parameters
The Bearer token required to get access to the API.
- application/json
Bodyrequired
data object
Responses
- 201
- 400
- 422
Created
- application/json
- Schema
- Example (auto)
- PromotionCodeCreatedResponse
- FullyConsumedPromotionCodeResponse
- DuplicateCodeNameResponse
Schema
data object[]
messages object[]
{
"data": [
{
"type": "promotion_codes",
"code": "string",
"uses": 0,
"user": "string",
"consume_unit": "per_application",
"max_uses": 0,
"max_users_per_shopper": {
"max_uses": 0,
"includes_guests": false
},
"is_for_new_shopper": true
}
],
"messages": [
{
"source": {
"type": "promotion_codes",
"codes": [
"spring2024"
]
},
"title": "Duplicate code names",
"description": "Code names duplicated in other promotions"
}
]
}
Response When a Promotion Code is Successfully Created
{
"data": [
{
"id": "8a1c73bc-7c15-41c3-a3ed-a0aa398c3984",
"code": "one_per_shopper",
"user": "5abb8d4e-57c0-459b-91d5-c4e6f77e9c5e",
"max_uses_per_shopper": {
"max_uses": 1,
"includes_guests": false
},
"consume_unit": "per_checkout"
}
]
}
Response When a Promotion Code Has Been Fully Used
{
"messages": [
{
"source": {
"type": "rule_promotion",
"id": "38861a5c-81bb-43bc-8934-e30cde108579",
"code": "one_per_shopper"
},
"title": "Fully Consumed",
"description": "You've already fully consumed this promotion code"
}
]
}
Message Response When Creating a Duplicate Promotion Code Name
{
"messages": [
{
"source": {
"type": "promotion_codes",
"codes": [
"duplicate-code"
]
},
"title": "Duplicate code names",
"description": "Code names duplicated in other promotions"
}
]
}
Bad Request
- application/json
- Schema
- Example (auto)
- MissingMaxUsesDependencyError
- FirstTimeShopperCodeError
Schema
errors object[]
{
"errors": [
{
"status": 400,
"source": "data.codes.0.max_uses_per_shopper",
"title": "missing_dependency",
"detail": "Has a dependency on max_uses"
}
]
}
Error When max_uses_per_shopper.includes_guests
is Provided Without max_uses
{
"errors": [
{
"status": 400,
"source": "data.codes.0.max_uses_per_shopper",
"title": "missing_dependency",
"detail": "Has a dependency on max_uses"
}
]
}
Error When Setting Usage Limits While Assigning First-Time Shopper Codes
{
"errors": [
{
"status": 400,
"source": "",
"title": "Invalid Code",
"detail": "Code - first_time_uses can't have limited uses or assigned to users since it's for first-time shoppers."
}
]
}
Unprocessable Entity
- application/json
- Schema
- Example (auto)
- UnsupportedConsumeUnitError
- NoCodesAllowedForAutomaticPromotion
- DuplicatePromotionCodeError
Schema
errors object[]
{
"errors": [
{
"status": 422,
"source": "",
"title": "Unsupported consume unit",
"detail": "Consume unit 'per_application' is not supported when using 'max_uses_per_shopper' features."
}
]
}
Error When max_uses_per_shopper.max_uses
is Used with per_application
{
"errors": [
{
"status": 422,
"source": "",
"title": "Unsupported consume unit",
"detail": "Consume unit 'per_application' is not supported when using 'max_uses_per_shopper' features."
}
]
}
Error When Attempting to Create Promotion Codes for Automatic Promotions
{
"errors": [
{
"status": 422,
"title": "No codes allowed",
"detail": "Cannot add codes to automatic promotion"
}
]
}
Error When Creating a Promotion Code That Already Exists
{
"errors": [
{
"status": 422,
"title": "Duplicate code",
"detail": "Promotion code already in use"
}
]
}
Authorization: http
name: BearerAuthtype: httpscheme: bearer
- csharp
- curl
- dart
- go
- http
- java
- javascript
- kotlin
- c
- nodejs
- objective-c
- ocaml
- php
- powershell
- python
- r
- ruby
- rust
- shell
- swift
- HTTPCLIENT
- RESTSHARP
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://useast.api.elasticpath.com/v2/rule-promotions/:promotionID/codes");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer <token>");
var content = new StringContent("{\n \"data\": {\n \"type\": \"promotion_codes\",\n \"codes\": [\n {\n \"code\": \"string\",\n \"uses\": 0,\n \"user\": \"string\",\n \"consume_unit\": \"per_application\",\n \"max_users_per_shopper\": {\n \"max_uses\": 0,\n \"includes_guests\": false\n },\n \"is_for_new_shopper\": true\n }\n ]\n }\n}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());