Skip to main content

Create Rule Promotion Codes

POST 

https://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.
note

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

    promotionID stringrequired

    The unique identifier of the rule promotion.

Header Parameters

    Authorization Bearerrequired

    The Bearer token required to get access to the API.

Bodyrequired

    data object
    typestring

    Possible values: [promotion_codes]

    codes object[]

    Specifies the code details in an array of objects.

  • Array [
  • codestring

    Specifies the string to use as a code for the promotion.

    usesinteger

    Specifies the number of times the code can be used. If no value is set, the customer can use the code any number of times.

    userstring

    Specifies the customer ID of the shopper who can use the code. For more information, see the Create a customer section.

    consume_unitstring

    Specifies whether the code is consumed per application or per checkout. With per_checkout, the code is used once for each checkout, regardless of the number of items in the cart. When set to per_application, the code is used per application. For cart discounts, each application counts as one usage. For item discounts, each application to either a single quantity or a bundle is counted as one usage. For example, in a store that offers 50% off on SKU1, SKU2, and SKU3, and limits the maximum usage of the promotion code to two, a shopper can apply the promotion up to two quantities. If the cart contains two or more quantities of SKU1, the promotion is applied 2 times to SKU1, and other quantities and items are at the regular price. If the cart contains one quantity of SKU1, one quantity of SKU2, and one quantity of SKU3, the promotion is applied once to SKU1 and once to SKU2. The code usage is applied at checkout and the code is considered consumed at that point.

    Possible values: [per_application, per_checkout]

    max_users_per_shopper object

    Object for setting max uses per shopper. Only include this object, when you want to set limit per shopper.

    max_usesinteger

    Sets max number of times the code can be used by a shopper. NOTE - This cannot be set with per_application consume unit.

    includes_guestsboolean

    The flag to include guest shoppers for the discount with max use restriction. If this field is provided, the max_uses value is required. When set to true, guest shoppers must have an email associated with the cart to use the code. A guest cart without an email cannot use the code. When set to false, guest shoppers cannot use the promo code, even if the cart has an associated guest email.

    Default value: false
    is_for_new_shopperboolean

    A flag indicating whether the coupon is for first-time shoppers. If set to true, the discount will only apply if the shopper has never made a payment on any order in the store. If set to false or left unset, it will be a regular discount that applies to all shoppers. When this flag is set to true, the coupon cannot have usage limitations or be assigned to specific users.

  • ]

Responses

Created

Schema
    data object[]
  • Array [
  • typestring

    Possible values: [promotion_codes]

    codestring
    usesinteger
    userstring
    consume_unitstring

    Possible values: [per_application, per_checkout]

    max_usesinteger
    max_users_per_shopper object

    Object for setting max uses per shopper. Only include this object, when you want to set limit per shopper.

    max_usesinteger

    Sets max number of times the code can be used by a shopper. NOTE - This cannot be set with per_application consume unit.

    includes_guestsboolean

    The flag to include guest shoppers for the discount with max use restriction. If this field is provided, the max_uses value is required. When set to true, guest shoppers must have an email associated with the cart to use the code. A guest cart without an email cannot use the code. When set to false, guest shoppers cannot use the promo code, even if the cart has an associated guest email.

    Default value: false
    is_for_new_shopperboolean
  • ]
  • messages object[]
  • Array [
  • source object

    Information about the affected promotion codes.

    typestring

    Indicates that the affected entity is a promotion code.

    Possible values: [promotion_codes]

    Example: promotion_codes
    codesstring[]

    A list of promotion codes that triggered the message.

    titlestring

    A brief title summarizing the message.

    Example: Duplicate code names
    descriptionstring

    A detailed explanation of the message.

    Example: Code names duplicated in other promotions
  • ]

Authorization: http

name: BearerAuthtype: httpscheme: bearer
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());
Request Collapse all
Base URL
https://useast.api.elasticpath.com
Auth
Parameters
— pathrequired
— headerrequired
Body required
{
  "data": {
    "type": "promotion_codes",
    "codes": [
      {
        "code": "string",
        "uses": 0,
        "user": "string",
        "consume_unit": "per_application",
        "max_users_per_shopper": {
          "max_uses": 0,
          "includes_guests": false
        },
        "is_for_new_shopper": true
      }
    ]
  }
}
ResponseClear

Click the Send API Request button above and see the response here!

We use cookies to enhance your experience. By continuing to visit this site you agree to our use of cookies.