DiscountCode

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

For more information about the PriceRule resource, see PriceRule.

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

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

Date and time when the discount code was created. The API returns this value in ISO 8601 format.

id
"id": 9808080986

Unique numeric identifier for the discount code.

code
"code": "SUMMERSALE10OFF"

Case-insensitive discount code that customers use at checkout. Required when creating a discount. Maximum length of 255 characters.

Caution

It is recommended to use the same value for code as the associated price rule title since only the title is searchable in the Shopify admin. For example: price_rule.title = ABC123 and discount_code.code = ABC123

price_rule_id
"price_rule_id": 423748927342

Unique numeric identifier for the price rule.

usage_count
"usage_count": 3

Number of times the discount code has been redeemed.

Endpoints

POST /admin/price_rules/507328175/discount_codes.json
Create a discount code

Create a discount with code SUMMERSALE10OFF

POST /admin/price_rules/#{id}/discount_codes.json
{
  "discount_code": {
    "code": "SUMMERSALE10OFF"
  }
}
View Response
HTTP/1.1 201 Created
{
  "discount_code": {
    "id": 1054381141,
    "price_rule_id": 507328175,
    "code": "SUMMERSALE10OFF",
    "usage_count": 0,
    "created_at": "2017-09-12T16:23:35-04:00",
    "updated_at": "2017-09-12T16:23:35-04:00"
  }
}
PUT /admin/price_rules/507328175/discount_codes/507328175.json
Change DiscountCode attributes

Update the code for a discount

PUT /admin/price_rules/#{id}/discount_codes/#{id}.json
{
  "discount_code": {
    "id": 507328175,
    "code": "WINTERSALE20OFF",
    "usage_count": 0,
    "created_at": "2017-09-12T16:23:01-04:00",
    "updated_at": "2017-09-12T16:23:01-04:00"
  }
}
View Response
HTTP/1.1 200 OK
{
  "discount_code": {
    "id": 507328175,
    "price_rule_id": 507328175,
    "code": "WINTERSALE20OFF",
    "usage_count": 0,
    "created_at": "2017-09-12T16:23:01-04:00",
    "updated_at": "2017-09-12T16:23:36-04:00"
  }
}
GET /admin/price_rules/507328175/discount_codes.json
Retrieve a list of discount codes

List all discount codes

GET /admin/price_rules/#{id}/discount_codes.json
View Response
HTTP/1.1 200 OK
{
  "discount_codes": [
    {
      "id": 507328175,
      "price_rule_id": 507328175,
      "code": "SUMMERSALE10OFF",
      "usage_count": 0,
      "created_at": "2017-09-12T16:23:01-04:00",
      "updated_at": "2017-09-12T16:23:01-04:00"
    }
  ]
}
GET /admin/price_rules/507328175/discount_codes/507328175.json
Retrieve a single discount code

Retrieve a single discount code

GET /admin/price_rules/#{id}/discount_codes/#{id}.json
View Response
HTTP/1.1 200 OK
{
  "discount_code": {
    "id": 507328175,
    "price_rule_id": 507328175,
    "code": "SUMMERSALE10OFF",
    "usage_count": 0,
    "created_at": "2017-09-12T16:23:01-04:00",
    "updated_at": "2017-09-12T16:23:01-04:00"
  }
}
GET /admin/discount_codes/lookup.json
Look up a discount code.

Note

The lookup endpoint returns the location of the DiscountCode in the location header, not the DiscountCode object itself. Depending on your HTTP client, the location of the discount code might follow the location header automatically.

Search by discount code

GET /admin/discount_codes/lookup.json?code=SUMMERSALE10OFF
View Response
HTTP/1.1 303 See Other
location: https://apple.myshopify.com/admin/price_rules/507328175/discount_codes/507328175
DELETE /admin/price_rules/507328175/discount_codes/507328175.json
Delete a discount code

Permanently delete a discount code

DELETE /admin/price_rules/#{id}/discount_codes/#{id}.json
View Response
HTTP/1.1 204 No Content