Discount codes guide
Add discount codes in bulk with the Shopify GraphiQL app
Set up GraphiQL
Install the app from https://shopify-graphiql-app.shopifycloud.com/ and tick read_discounts and write_discounts when it asks for access scopes.
The mutation
Paste this into the query box once.
mutation AddDiscountCodes($discountId: ID!, $codes: [DiscountRedeemCodeInput!]!) {
discountRedeemCodeBulkAdd(discountId: $discountId, codes: $codes) {
bulkCreation {
id
}
userErrors {
code
field
message
}
}
}The variables
Paste one batch into the Variables box and press Run. The tool writes every batch for you.
{
"discountId": "gid://shopify/DiscountCodeNode/123456789",
"codes": [
{
"code": "SPRING-7KQ4-M2XD"
},
{
"code": "SPRING-9FHT-3BWN"
}
]
}Check which codes failed
Each response includes bulkCreation.id. Run this query with that ID to see how many codes were added and the error for any that weren’t.
query CheckDiscountCodeJob($id: ID!) {
discountRedeemCodeBulkCreation(id: $id) {
id
done
codesCount
importedCount
failedCount
codes(first: 250) {
nodes {
code
errors {
field
message
}
}
}
}
}Find the discount ID
If you don’t have the ID handy, this lists your newest code discounts.
query FindCodeDiscounts {
codeDiscountNodes(first: 25, reverse: true) {
nodes {
id
codeDiscount {
__typename
... on DiscountCodeBasic { title status }
... on DiscountCodeBxgy { title status }
... on DiscountCodeFreeShipping { title status }
... on DiscountCodeApp { title status }
}
}
}
}More guides
- How to import discount codes into Shopify from a CSV
- How to create thousands of unique discount codes in Shopify
- Add thousands of discount codes with Shopify CLI
- Shopify discount code rules: length, capitals and limits
Sources: discountRedeemCodeBulkAdd, Shopify CLI store execute, Shopify Help Center: discount codes. Not affiliated with, endorsed by, or sponsored by Shopify Inc. Shopify is a trademark of Shopify Inc.