Skip to main content

The REST Admin API is a legacy API as of October 1, 2024. Starting April 1, 2025, all new public apps must be built exclusively with the GraphQL Admin API. For details and migration steps, visit our migration guide.

DiscountCode

Multiple access scopes needed — refer to each endpoint for access scope requirements.
Note

We recommend using the GraphQL Admin API to manage discounts. The Discount types available in the GraphQL Admin API are intended to replace the GraphQL Admin PriceRule object and REST Admin PriceRule and DiscountCode resources.

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.

Was this section helpful?

Anchor to

The DiscountCode resource

Anchor to

Properties


code

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

Caution

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


created_at
read-only

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


updated_at
read-only

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


id
read-only
->
id

The ID for the discount code.


price_rule_id
read-only
->
id

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


usage_count
read-only

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


errors
read-only

An array of errors that occurred when retrieving a list of discount codes for a discount code creation job.


Was this section helpful?
{}

The DiscountCode resource

{
"code": "SUMMERSALE10OFF",
"created_at": "2017-03-13T16:09:54-04:00",
"updated_at": "2017-03-13T16:09:54-04:00",
"id": 9808080986,
"price_rule_id": 423748927342,
"usage_count": 3,
"errors": {
"code": [
"must be unique. Please try a different code."
]
}
}

Anchor to POST request, Creates a discount code creation job
post
Creates a discount code creation job

Creates a discount code creation job.

The batch endpoint can be used to asynchronously create up to 100 discount codes in a single request. It enqueues and returns a discount_code_creation object that can be monitored for completion. You can enqueue a single creation job per a shop and you can't enqueue more until the job completes.

The price_rule_id path parameter is the ID of the price rule that the discount code will belong to. This is required because each discount code must belong to a price rule.

Response fields that are specific to the batch endpoint include:

  • status: The state of the discount code creation job. Possible values are:
    • queued: The job is acknowledged, but not started.
    • running: The job is in process.
    • completed: The job has finished.
  • codes_count: The number of discount codes to create.
  • imported_count: The number of discount codes created successfully.
  • failed_count: The number of discount codes that were not created successfully. Unsuccessful attempts will retry up to three times.
  • logs: A report that specifies when no discount codes were created because the provided data was invalid. Example responses:
    • "Price rule target selection can't be blank"
    • "Price rule allocation method can't be blank"

Anchor to Parameters of Creates a discount code creation jobParameters


api_version
string
required

price_rule_id
string
required

Was this section helpful?

Anchor to post-price-rules-price-rule-id-batch-examplesExamples

Create a discount code creation job

Path parameters
price_rule_id=507328175
string
required
Was this section helpful?
post

/admin/api/2024-10/price_rules/507328175/batch.json

curl -d '{"discount_codes":[{"code":"SUMMER1"},{"code":"SUMMER2"},{"code":"SUMMER3"}]}' \
-X POST "https://your-development-store.myshopify.com/admin/api/2024-10/price_rules/507328175/batch.json" \
-H "X-Shopify-Access-Token: {access_token}" \
-H "Content-Type: application/json"

{}

Response

JSON
HTTP/1.1 201 Created
{
"discount_code_creation": {
"id": 989355119,
"price_rule_id": 507328175,
"started_at": null,
"completed_at": null,
"created_at": "2025-07-01T14:41:17-04:00",
"updated_at": "2025-07-01T14:41:17-04:00",
"status": "queued",
"codes_count": 3,
"imported_count": 0,
"failed_count": 0,
"logs": []
}
}

Anchor to POST request, Creates a discount code
post
Creates a discount code

Requires price_rules access scope.

Creates a discount code.

The price_rule_id path parameter is the ID of the price rule that the discount code will belong to. This is required because each discount code must belong to a price rule.

Anchor to Parameters of Creates a discount codeParameters


api_version
string
required

price_rule_id
string
required

Was this section helpful?

Anchor to post-price-rules-price-rule-id-discount-codes-examplesExamples

Create a discount code

Path parameters
price_rule_id=507328175
string
required
Request body
discount_code
Discount_code resource
Show discount_code properties
discount_code.code:"SUMMERSALE10OFF"

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

Caution

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

Was this section helpful?
post

/admin/api/2024-10/price_rules/507328175/discount_codes.json

curl -d '{"discount_code":{"code":"SUMMERSALE10OFF"}}' \
-X POST "https://your-development-store.myshopify.com/admin/api/2024-10/price_rules/507328175/discount_codes.json" \
-H "X-Shopify-Access-Token: {access_token}" \
-H "Content-Type: application/json"

{}

Response

JSON
HTTP/1.1 201 Created
{
"discount_code": {
"id": 1057371196,
"price_rule_id": 507328175,
"code": "SUMMERSALE10OFF",
"usage_count": 0,
"created_at": "2025-07-01T14:41:10-04:00",
"updated_at": "2025-07-01T14:41:10-04:00"
}
}

Anchor to GET request, Retrieves a count of discount codes for a shop
get
Retrieves a count of discount codes for a shop

Requires price_rules access scope.

Retrieves a count of discount codes for a shop


api_version
string
required

times_used

Show discount codes with times used.


times_used_max

Show discount codes used greater than or equal to this value.


times_used_min

Show discount codes used less than or equal to this value.


Was this section helpful?

Retrieve a count of discount codes for a shop

Was this section helpful?
get

/admin/api/2024-10/discount_codes/count.json

curl -X GET "https://your-development-store.myshopify.com/admin/api/2024-10/discount_codes/count.json" \
-H "X-Shopify-Access-Token: {access_token}"

{}

Response

JSON
HTTP/1.1 200 OK
{
"count": 2
}

Anchor to GET request, Retrieves the location of a discount code
get
Retrieves the location of a discount code
deprecated

Requires price_rules access scope.

Retrieves the location of a discount code.

The discount code's location is returned in the location header, not in the DiscountCode object itself. Depending on your HTTP client, the location of the discount code might follow the location header automatically.


api_version
string
required

code
required
≤ 100

Retrieves the location of a discount code by code name.


Was this section helpful?

Was this section helpful?
get

/admin/api/2024-10/discount_codes/lookup.json?code=SUMMERSALE10OFF

curl -X GET "https://your-development-store.myshopify.com/admin/api/2024-10/discount_codes/lookup.json?code=SUMMERSALE10OFF" \
-H "X-Shopify-Access-Token: {access_token}"

{}

Response

JSON
HTTP/1.1 303 See Other


Anchor to GET request, Retrieves a discount code creation job
get
Retrieves a discount code creation job

Retrieves a discount code creation job

The price_rule_id path parameter is the ID of the price rule that the discount code creation job was ran for. This is required because each discount code creation job is associated to a price rule.

The batch_id path parameter is the ID of the discount code creation job for the associated price rule.


api_version
string
required

batch_id
string
required

price_rule_id
string
required

Was this section helpful?

Retrieve a discount code creation job

Was this section helpful?
get

/admin/api/2024-10/price_rules/507328175/batch/173232803.json

curl -X GET "https://your-development-store.myshopify.com/admin/api/2024-10/price_rules/507328175/batch/173232803.json" \
-H "X-Shopify-Access-Token: {access_token}"

{}

Response

JSON
HTTP/1.1 200 OK
{
"discount_code_creation": {
"id": 173232803,
"price_rule_id": 507328175,
"started_at": null,
"completed_at": null,
"created_at": "2025-07-01T14:37:24-04:00",
"updated_at": "2025-07-01T14:37:24-04:00",
"status": "queued",
"codes_count": 3,
"imported_count": 0,
"failed_count": 0,
"logs": []
}
}

Anchor to GET request, Retrieves a list of discount codes for a discount code creation job
get
Retrieves a list of discount codes for a discount code creation job

Retrieves a list of discount codes for a discount code creation job.

The price_rule_id path parameter is the ID of the price rule that the discount code creation job was ran for. This is required because each discount code creation job is associated to a price rule.

The batch_id path parameter is the ID of the discount code creation job for the associated price rule.

Discount codes that have been successfully created include a populated id field. Discount codes that encountered errors during the creation process include a populated errors field.


api_version
string
required

batch_id
string
required

price_rule_id
string
required

Was this section helpful?

Retrieve a list of discount codes for a discount code creation job

Was this section helpful?
get

/admin/api/2024-10/price_rules/507328175/batch/173232803/discount_codes.json

curl -X GET "https://your-development-store.myshopify.com/admin/api/2024-10/price_rules/507328175/batch/173232803/discount_codes.json" \
-H "X-Shopify-Access-Token: {access_token}"

{}

Response

JSON
HTTP/1.1 200 OK
{
"discount_codes": [
{
"id": null,
"code": "foo",
"errors": {}
},
{
"id": null,
"code": "",
"errors": {}
},
{
"id": null,
"code": "bar",
"errors": {}
}
]
}

Requires price_rules access scope.

Retrieve a list of discount codes. Note: This endpoint implements pagination by using links that are provided in the response header. To learn more, refer to Make paginated requests to the REST Admin API.

The price_rule_id path parameter is the ID of the price rule that the discount codes belongs to.


api_version
string
required

price_rule_id
string
required

Was this section helpful?

Retrieve a list of all discount codes

Path parameters
price_rule_id=507328175
string
required
Was this section helpful?
get

/admin/api/2024-10/price_rules/507328175/discount_codes.json

curl -X GET "https://your-development-store.myshopify.com/admin/api/2024-10/price_rules/507328175/discount_codes.json" \
-H "X-Shopify-Access-Token: {access_token}"

{}

Response

JSON
HTTP/1.1 200 OK
{
"discount_codes": [
{
"id": 507328175,
"price_rule_id": 507328175,
"code": "SUMMERSALE10OFF",
"usage_count": 0,
"created_at": "2025-07-01T14:37:24-04:00",
"updated_at": "2025-07-01T14:37:24-04:00"
}
]
}

Requires price_rules access scope.

Retrieves a single discount code.

The price_rule_id path parameter is the ID of the price rule that the discount code belongs to. This is required because each discount code must belong to a price rule.

The discount_code_id path parameter is the ID of the discount code to retrieve for the associated price rule.


api_version
string
required

discount_code_id
string
required

price_rule_id
string
required

Was this section helpful?
Was this section helpful?
get

/admin/api/2024-10/price_rules/507328175/discount_codes/507328175.json

curl -X GET "https://your-development-store.myshopify.com/admin/api/2024-10/price_rules/507328175/discount_codes/507328175.json" \
-H "X-Shopify-Access-Token: {access_token}"

{}

Response

JSON
HTTP/1.1 200 OK
{
"discount_code": {
"id": 507328175,
"price_rule_id": 507328175,
"code": "SUMMERSALE10OFF",
"usage_count": 0,
"created_at": "2025-07-01T14:37:24-04:00",
"updated_at": "2025-07-01T14:37:24-04:00"
}
}

Requires price_rules access scope.

Updates an existing discount code.

The price_rule_id path parameter is the ID of the price rule that the discount code belongs to. This is required because each discount code must belong to a price rule.

The discount_code_id path parameter is the ID of the discount code to update for the associated price rule.


api_version
string
required

discount_code_id
string
required

price_rule_id
string
required

Was this section helpful?

Update the code for a discount

Request body
discount_code
Discount_code resource
Show discount_code properties
discount_code.id:507328175
read-only

The ID for the discount code.

discount_code.code:"WINTERSALE20OFF"

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

Caution

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

Was this section helpful?
put

/admin/api/2024-10/price_rules/507328175/discount_codes/507328175.json

curl -d '{"discount_code":{"id":507328175,"code":"WINTERSALE20OFF"}}' \
-X PUT "https://your-development-store.myshopify.com/admin/api/2024-10/price_rules/507328175/discount_codes/507328175.json" \
-H "X-Shopify-Access-Token: {access_token}" \
-H "Content-Type: application/json"

{}

Response

JSON
HTTP/1.1 200 OK
{
"discount_code": {
"id": 507328175,
"price_rule_id": 507328175,
"code": "WINTERSALE20OFF",
"usage_count": 0,
"created_at": "2025-07-01T14:37:24-04:00",
"updated_at": "2025-07-01T14:41:15-04:00"
}
}

Requires price_rules access scope.

Deletes a discount code.

The price_rule_id path parameter is the ID of the price rule that the discount code belongs to. This is required because each discount code must belong to a price rule.

The discount_code_id path parameter is the ID of the discount code to delete for the associated price rule.


api_version
string
required

discount_code_id
string
required

price_rule_id
string
required

Was this section helpful?
Was this section helpful?
del

/admin/api/2024-10/price_rules/507328175/discount_codes/507328175.json

curl -X DELETE "https://your-development-store.myshopify.com/admin/api/2024-10/price_rules/507328175/discount_codes/507328175.json" \
-H "X-Shopify-Access-Token: {access_token}"

{}

Response

JSON
HTTP/1.1 204 No Content