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.
Discount Code
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.
Endpoints
- post/admin/api/2024-10/price_
rules/{price_ rule_ id}/batch. json Creates a discount code creation job - post/admin/api/2024-10/price_
rules/{price_ rule_ id}/discount_ codes. json Creates a discount code - get/admin/api/2024-10/discount_
codes/count. json Retrieves a count of discount codes for a shop - get/admin/api/2024-10/discount_
codes/lookup. json?code=SUMMERSALE10OFF Retrieves the location of a discount codedeprecated - get/admin/api/2024-10/price_
rules/{price_ rule_ id}/batch/{batch_ id}. json Retrieves a discount code creation job - get/admin/api/2024-10/price_
rules/{price_ rule_ id}/batch/{batch_ id}/discount_ codes. json Retrieves a list of discount codes for a discount code creation job - get/admin/api/2024-10/price_
rules/{price_ rule_ id}/discount_ codes. json Retrieves a list of discount codes - get/admin/api/2024-10/price_
rules/{price_ rule_ id}/discount_ codes/{discount_ code_ id}. json Retrieves a single discount code - put/admin/api/2024-10/price_
rules/{price_ rule_ id}/discount_ codes/{discount_ code_ id}. json Updates an existing discount code - del/admin/api/2024-10/price_
rules/{price_ rule_ id}/discount_ codes/{discount_ code_ id}. json Deletes a discount code
The DiscountCode resource
Properties
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.
The date and time (ISO 8601 format) when the discount code was created.
The date and time (ISO 8601 format) when the discount code was updated.
The ID for the discount code.
The ID for the price rule that this discount code belongs to.
The number of times that the discount code has been redeemed.
An array of errors that occurred when retrieving a list of discount codes for a discount code creation job.
The DiscountCode resource
Anchor to POST request, Creates a discount code creation jobpostCreates 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"
Create a discount code creation job
Create a discount code creation job
/admin/api/2024-10/price_ rules/507328175/batch. json
Response
examples
Create a discount code creation job
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"
const { admin, session } = await authenticate.admin(request); const discount_code = new admin.rest.resources.DiscountCode({session: session}); discount_code.price_rule_id = 507328175; await discount_code.batch({ body: {"discount_codes": [{"code": "SUMMER1"}, {"code": "SUMMER2"}, {"code": "SUMMER3"}]}, });
# Session is activated via Authentication test_session = ShopifyAPI::Context.active_session discount_code = ShopifyAPI::DiscountCode.new(session: test_session) discount_code.price_rule_id = 507328175 discount_code.batch( session: test_session, body: {"discount_codes" => [{"code" => "SUMMER1"}, {"code" => "SUMMER2"}, {"code" => "SUMMER3"}]}, )
// Session is built by the OAuth process const discount_code = new shopify.rest.DiscountCode({session: session}); discount_code.price_rule_id = 507328175; await discount_code.batch({ body: {"discount_codes": [{"code": "SUMMER1"}, {"code": "SUMMER2"}, {"code": "SUMMER3"}]}, });
response
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 codepostCreates a discount code
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.
Create a discount code
Create a discount code
Show discount_code properties
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.
/admin/api/2024-10/price_ rules/507328175/discount_ codes. json
Response
examples
Create a discount code
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"
const { admin, session } = await authenticate.admin(request); const discount_code = new admin.rest.resources.DiscountCode({session: session}); discount_code.price_rule_id = 507328175; discount_code.code = "SUMMERSALE10OFF"; await discount_code.save({ update: true, });
# Session is activated via Authentication test_session = ShopifyAPI::Context.active_session discount_code = ShopifyAPI::DiscountCode.new(session: test_session) discount_code.price_rule_id = 507328175 discount_code.code = "SUMMERSALE10OFF" discount_code.save!
// Session is built by the OAuth process const discount_code = new shopify.rest.DiscountCode({session: session}); discount_code.price_rule_id = 507328175; discount_code.code = "SUMMERSALE10OFF"; await discount_code.save({ update: true, });
response
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 shopgetRetrieves a count of discount codes for a shop
price_rules
access scope.Retrieves a count of discount codes for a shop
Show discount codes with times used.
Show discount codes used greater than or equal to this value.
Show discount codes used less than or equal to this value.
Retrieve a count of discount codes for a shop
Retrieve a count of discount codes for a shop
/admin/api/2024-10/discount_ codes/count. json
Response
examples
Retrieve a count of discount codes for a shop
curl -X GET "https://your-development-store.myshopify.com/admin/api/2024-10/discount_codes/count.json" \ -H "X-Shopify-Access-Token: {access_token}"
await admin.rest.resources.DiscountCode.count({ session: session, });
# Session is activated via Authentication test_session = ShopifyAPI::Context.active_session ShopifyAPI::DiscountCode.count( session: test_session, )
// Session is built by the OAuth process await shopify.rest.DiscountCode.count({ session: session, });
response
HTTP/1.1 200 OK{"count":2}
Anchor to GET request, Retrieves the location of a discount codegetRetrieves the location of a discount code deprecated
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.
Retrieves the location of a discount code by code name.
Search for a discount code
Search for a discount code
Retrieves the location of a discount code by code name.
/admin/api/2024-10/discount_ codes/lookup. json?code= SUMMERSALE10OFF
Response
examples
Search for a discount code
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}"
await admin.rest.resources.DiscountCode.lookup({ session: session, code: "SUMMERSALE10OFF", });
# Session is activated via Authentication test_session = ShopifyAPI::Context.active_session ShopifyAPI::DiscountCode.lookup( session: test_session, code: "SUMMERSALE10OFF", )
// Session is built by the OAuth process await shopify.rest.DiscountCode.lookup({ session: session, code: "SUMMERSALE10OFF", });
response
HTTP/1.1 303 See Other
Anchor to GET request, Retrieves a discount code creation jobgetRetrieves 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.
Retrieve a discount code creation job
Retrieve a discount code creation job
/admin/api/2024-10/price_ rules/507328175/batch/173232803. json
Response
examples
Retrieve a discount code creation job
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}"
await admin.rest.resources.DiscountCode.get_all({ session: session, price_rule_id: 507328175, batch_id: 173232803, });
# Session is activated via Authentication test_session = ShopifyAPI::Context.active_session ShopifyAPI::DiscountCode.get_all( session: test_session, price_rule_id: 507328175, batch_id: 173232803, )
// Session is built by the OAuth process await shopify.rest.DiscountCode.get_all({ session: session, price_rule_id: 507328175, batch_id: 173232803, });
response
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 jobgetRetrieves 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.
Retrieve a list of discount codes for a discount code creation job
Retrieve a list of discount codes for a discount code creation job
/admin/api/2024-10/price_ rules/507328175/batch/173232803/discount_ codes. json
Response
examples
Retrieve a list of discount codes for a discount code creation job
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}"
await admin.rest.resources.DiscountCode.all({ session: session, price_rule_id: 507328175, batch_id: 173232803, });
# Session is activated via Authentication test_session = ShopifyAPI::Context.active_session ShopifyAPI::DiscountCode.all( session: test_session, price_rule_id: 507328175, batch_id: 173232803, )
// Session is built by the OAuth process await shopify.rest.DiscountCode.all({ session: session, price_rule_id: 507328175, batch_id: 173232803, });
response
HTTP/1.1 200 OK{"discount_codes":[{"id":null,"code":"foo","errors":{}},{"id":null,"code":"","errors":{}},{"id":null,"code":"bar","errors":{}}]}
Anchor to GET request, Retrieves a list of discount codesgetRetrieves a list of discount codes
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.
Retrieve a list of all discount codes
Retrieve a list of all discount codes
/admin/api/2024-10/price_ rules/507328175/discount_ codes. json
Response
examples
Retrieve a list of all discount codes
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}"
await admin.rest.resources.DiscountCode.all({ session: session, price_rule_id: 507328175, });
# Session is activated via Authentication test_session = ShopifyAPI::Context.active_session ShopifyAPI::DiscountCode.all( session: test_session, price_rule_id: 507328175, )
// Session is built by the OAuth process await shopify.rest.DiscountCode.all({ session: session, price_rule_id: 507328175, });
response
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"}]}
Anchor to GET request, Retrieves a single discount codegetRetrieves a single discount code
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.
Retrieve a single discount code
Retrieve a single discount code
/admin/api/2024-10/price_ rules/507328175/discount_ codes/507328175. json
Response
examples
Retrieve a single discount code
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}"
await admin.rest.resources.DiscountCode.find({ session: session, price_rule_id: 507328175, id: 507328175, });
# Session is activated via Authentication test_session = ShopifyAPI::Context.active_session ShopifyAPI::DiscountCode.find( session: test_session, price_rule_id: 507328175, id: 507328175, )
// Session is built by the OAuth process await shopify.rest.DiscountCode.find({ session: session, price_rule_id: 507328175, id: 507328175, });
response
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"}}
Anchor to PUT request, Updates an existing discount codeputUpdates an existing discount code
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.
Update the code for a discount
Update the code for a discount
Show discount_code properties
The ID for the discount code.
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.
/admin/api/2024-10/price_ rules/507328175/discount_ codes/507328175. json
Response
examples
Update the code for a discount
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"
const { admin, session } = await authenticate.admin(request); const discount_code = new admin.rest.resources.DiscountCode({session: session}); discount_code.price_rule_id = 507328175; discount_code.id = 507328175; discount_code.code = "WINTERSALE20OFF"; await discount_code.save({ update: true, });
# Session is activated via Authentication test_session = ShopifyAPI::Context.active_session discount_code = ShopifyAPI::DiscountCode.new(session: test_session) discount_code.price_rule_id = 507328175 discount_code.id = 507328175 discount_code.code = "WINTERSALE20OFF" discount_code.save!
// Session is built by the OAuth process const discount_code = new shopify.rest.DiscountCode({session: session}); discount_code.price_rule_id = 507328175; discount_code.id = 507328175; discount_code.code = "WINTERSALE20OFF"; await discount_code.save({ update: true, });
response
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"}}
Anchor to DELETE request, Deletes a discount codedelDeletes a discount code
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.
Delete a discount code
Delete a discount code
/admin/api/2024-10/price_ rules/507328175/discount_ codes/507328175. json
Response
examples
Delete a discount code
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}"
await admin.rest.resources.DiscountCode.delete({ session: session, price_rule_id: 507328175, id: 507328175, });
# Session is activated via Authentication test_session = ShopifyAPI::Context.active_session ShopifyAPI::DiscountCode.delete( session: test_session, price_rule_id: 507328175, id: 507328175, )
// Session is built by the OAuth process await shopify.rest.DiscountCode.delete({ session: session, price_rule_id: 507328175, id: 507328175, });
response
HTTP/1.1 204 No Content