discountRedeemCodeBulkAdd
Requires Apps must have access scope.
Asynchronously add
discount codes
in bulk that customers can use to redeem a discount. You can use the mutation
to automate the distribution of discount codes through emails or other
marketing channels.
Arguments
- Anchor to codescodes•[Discount
Redeem requiredCode Input!]! The list of codes to associate with the code discount. Maximum: 100 codes.
- Anchor to discountIddiscount•
Id ID!required The ID of the
object that the codes will be added to. For example,
. You can use the
query to retrieve the ID.
Anchor to DiscountRedeemCodeBulkAddPayload returnsDiscountRedeemCodeBulkAddPayload returns
- Anchor to bulkCreationbulk•
Creation The ID of bulk operation that creates multiple unique discount codes. You can use the
query to track the status of the bulk operation.
- Anchor to userErrorsuser•
Errors [DiscountUser non-nullError!]! The list of errors that occurred from executing the mutation.
- Asynchronously add redeem codes to a code discount
- Creates a discount code
- Creates a discount code creation job
- discountRedeemCodeBulkAdd reference
Examples
mutation discountRedeemCodeBulkAdd($discountId: ID!, $codes: [DiscountRedeemCodeInput!]!) {
discountRedeemCodeBulkAdd(discountId: $discountId, codes: $codes) {
bulkCreation {
id
}
userErrors {
code
field
message
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation discountRedeemCodeBulkAdd($discountId: ID!, $codes: [DiscountRedeemCodeInput!]!) { discountRedeemCodeBulkAdd(discountId: $discountId, codes: $codes) { bulkCreation { id } userErrors { code field message } } }",
"variables": {
"discountId": "gid://shopify/DiscountCodeNode/2429471",
"codes": [
{
"code": "DISCOUNT_1"
},
{
"code": "DISCOUNT_2"
},
{
"code": "DISCOUNT_3"
}
]
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation discountRedeemCodeBulkAdd($discountId: ID!, $codes: [DiscountRedeemCodeInput!]!) {
discountRedeemCodeBulkAdd(discountId: $discountId, codes: $codes) {
bulkCreation {
id
}
userErrors {
code
field
message
}
}
}`,
{
variables: {
"discountId": "gid://shopify/DiscountCodeNode/2429471",
"codes": [
{
"code": "DISCOUNT_1"
},
{
"code": "DISCOUNT_2"
},
{
"code": "DISCOUNT_3"
}
]
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation discountRedeemCodeBulkAdd($discountId: ID!, $codes: [DiscountRedeemCodeInput!]!) {
discountRedeemCodeBulkAdd(discountId: $discountId, codes: $codes) {
bulkCreation {
id
}
userErrors {
code
field
message
}
}
}`,
"variables": {
"discountId": "gid://shopify/DiscountCodeNode/2429471",
"codes": [
{
"code": "DISCOUNT_1"
},
{
"code": "DISCOUNT_2"
},
{
"code": "DISCOUNT_3"
}
]
},
},
});
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
mutation discountRedeemCodeBulkAdd($discountId: ID!, $codes: [DiscountRedeemCodeInput!]!) {
discountRedeemCodeBulkAdd(discountId: $discountId, codes: $codes) {
bulkCreation {
id
}
userErrors {
code
field
message
}
}
}
QUERY
variables = {
"discountId": "gid://shopify/DiscountCodeNode/2429471",
"codes": [{"code"=>"DISCOUNT_1"}, {"code"=>"DISCOUNT_2"}, {"code"=>"DISCOUNT_3"}]
}
response = client.query(query: query, variables: variables)