DiscountCode

Version 2019-10

You can use the PriceRule DiscountCode resource to create discount codes that enable specific discounts to be redeemed. Merchants can distribute discount codes to their customers using a variety of means, such as an email or URL, and customers can apply these codes at checkout.

Each discount code belongs to a price rule, which holds the logic for the discount. For more information, see the PriceRule resource.

To create multiple discount codes that use the same price rule logic, use the batch endpoint. For example, you might allow merchants to create a batch of discount codes that belong to the same price rule but are each personalized for a different customer.

What you can do with DiscountCode

The Shopify API lets you do the following with the DiscountCode resource. More detailed versions of these general actions may be available:

DiscountCode properties

code
required
"code": "SUMMERSALE10OFF"

The case-insensitive discount code that customers use at checkout. (maximum: 255 characters)

Use the same value for code as the title property of the associated price rule.

created_at
read-only
"created_at": "2017-03-13T16:09:54-04:00"

The date and time (ISO 8601 format) when the discount code was created.

updated_at
read-only
"updated_at": "2017-03-13T16:09:54-04:00"

The date and time (ISO 8601 format) when the discount code was updated.

id
read-only
"id": 9808080986

The ID for the discount code.

price_rule_id
read-only
"price_rule_id": 423748927342

The ID for the price rule that this discount code belongs to.

usage_count
read-only
"usage_count": 3

The number of times that the discount code has been redeemed.

Endpoints

POST /admin/api/2019-10/price_rules/{price_rule_id}/discount_codes.json
Creates a discount code

Create a discount code

POST /admin/api/2019-10/price_rules/507328175/discount_codes.json
{
  "discount_code": {
    "code": "SUMMERSALE10OFF"
  }
}
View Response
HTTP/1.1 201 Created
{
  "discount_code": {
    "id": 1054381139,
    "price_rule_id": 507328175,
    "code": "SUMMERSALE10OFF",
    "usage_count": 0,
    "created_at": "2021-07-01T14:33:45-04:00",
    "updated_at": "2021-07-01T14:33:45-04:00"
  }
}
PUT /admin/api/2019-10/price_rules/{price_rule_id}/discount_codes/{discount_code_id}.json
Updates an existing discount code

Update the code for a discount

PUT /admin/api/2019-10/price_rules/507328175/discount_codes/507328175.json
{
  "discount_code": {
    "id": 507328175,
    "code": "WINTERSALE20OFF"
  }
}
View Response
HTTP/1.1 200 OK
{
  "discount_code": {
    "id": 507328175,
    "price_rule_id": 507328175,
    "code": "WINTERSALE20OFF",
    "usage_count": 0