Add discount codes in bulk
Add up to 250 unique codes per call to an existing code discount with discountRedeemCodeBulkAdd, then check which codes were imported.
- API
- Admin GraphQL API
- Operations
- discountRedeemCodeBulkAdd, discountRedeemCodeBulkCreation
- Access scope
- write_discounts
- Replaces (REST)
- POST /admin/api/price_rules/{id}/batch.json
- API version
- 2026-10
- Last checked
In short
To create many unique discount codes, first create one code discount, then call discountRedeemCodeBulkAdd with its DiscountCodeNode ID and up to 250 codes per call. The codes are added in the background: poll discountRedeemCodeBulkCreation with the returned ID until done is true, then read importedCount, failedCount and each code’s errors, for example a code that already exists.
How to use it
- Create the discount once, in the admin or with a discountCode…Create mutation, and keep its DiscountCodeNode ID.
- Generate your codes and split them into chunks of 250.
- Send AddDiscountCodes per chunk and keep each bulkCreation ID.
- Poll DiscountCodeImport until done is true. Codes with errors were not added; replace them and send them again.
Code
discount-redeem-code-bulk-add.graphqlmutation AddDiscountCodes($discountId: ID!, $codes: [DiscountRedeemCodeInput!]!) {
discountRedeemCodeBulkAdd(discountId: $discountId, codes: $codes) {
bulkCreation {
id
done
codesCount
importedCount
failedCount
}
userErrors {
code
field
message
}
}
}
discount-redeem-code-bulk-add.variables.json{
"discountId": "gid://shopify/DiscountCodeNode/1234567890",
"codes": [
{"code": "WELCOME-7KQ2"},
{"code": "WELCOME-M3XD"},
{"code": "WELCOME-P9TA"}
]
}
discount-redeem-code-bulk-add.response.json{
"data": {
"discountRedeemCodeBulkAdd": {
"bulkCreation": {
"id": "gid://shopify/DiscountRedeemCodeBulkCreation/1234567890",
"done": false,
"codesCount": 3,
"importedCount": 0,
"failedCount": 0
},
"userErrors": []
}
}
}
bulk-creation-status.graphqlquery DiscountCodeImport($id: ID!) {
discountRedeemCodeBulkCreation(id: $id) {
done
codesCount
importedCount
failedCount
codes(first: 250) {
nodes {
code
discountRedeemCode {
id
}
errors {
code
message
}
}
}
}
}
bulk-creation-status.variables.json{
"id": "gid://shopify/DiscountRedeemCodeBulkCreation/1234567890"
}
bulk-creation-status.response.json{
"data": {
"discountRedeemCodeBulkCreation": {
"done": true,
"codesCount": 3,
"importedCount": 2,
"failedCount": 1,
"codes": {
"nodes": [
{"code": "WELCOME-7KQ2", "discountRedeemCode": {"id": "gid://shopify/DiscountRedeemCode/1111111111"}, "errors": []},
{"code": "WELCOME-M3XD", "discountRedeemCode": {"id": "gid://shopify/DiscountRedeemCode/1111111112"}, "errors": []},
{"code": "WELCOME-P9TA", "discountRedeemCode": null, "errors": [{"code": "TAKEN", "message": "Code must be unique. Please try a different code."}]}
]
}
}
}
}
Written by Lintel. MIT license: free to use in your own store and in client work.
Limits and edge cases
- At most 250 codes per call. All codes share the discount’s value, dates and usage limits.
- Codes must be unique across the store; a duplicate fails on its own without stopping the others.
- The codes are added in the background. Wait until done is true before you send them to customers.
Questions
- How do I generate unique discount codes in Shopify with the API?
- Generate the codes in your code, then add them to one code discount with discountRedeemCodeBulkAdd, 250 per call.
- How many discount codes can I add at once?
- Up to 250 per discountRedeemCodeBulkAdd call. Send more calls for larger batches.
- How do I know which codes failed?
- Query discountRedeemCodeBulkCreation with the returned ID. failedCount gives the total, and each code’s errors explain why.
Shopify documentation
- Validated against the Admin or Storefront API schema for version 2026-10 on the date shown. Check the version in your request URL.
- IDs and store addresses in the examples are placeholders. Replace them with your own.
- Admin API calls need an access token from your app. Never put an Admin API token in a storefront or theme.
- MIT license. Use the code in your own store or in client work.
Need this built, tested and maintained for your store? See API integrations.
