Anchor to discountCodeBulkDeletediscount
discountCodeBulkDelete
mutation
Requires Apps must have access scope.
Deletes multiple code-based discounts asynchronously using one of the following:
- A search query
- A saved search ID
- A list of discount code IDs
For example, you can delete discounts for all codes that match a search criteria, or delete a predefined set of discount codes.
Anchor to Arguments
Arguments
- •
The IDs of the discounts to delete.
- Anchor to savedSearchIdsaved•
Search Id The ID of the saved search for filtering discounts to delete. Saved searches represent customer segments that merchants have built in the Shopify admin.
- Anchor to searchsearch•
Was this section helpful?
Anchor to DiscountCodeBulkDeletePayload returnsDiscountCodeBulkDeletePayload returns
- •
The asynchronous job that deletes the discounts.
- Anchor to userErrorsuser•
Errors [DiscountUser non-nullError!]! The list of errors that occurred from executing the mutation.
Was this section helpful?
- Asynchronously delete code discounts in bulk using a search filter
- Using more than one targeting argument returns an error
- discountCodeBulkDelete reference
Examples
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation discountCodeBulkDelete($search: String) {
discountCodeBulkDelete(search: $search) {
job {
id
}
userErrors {
code
field
message
}
}
}`,
{
variables: {
"search": "discount_type:percentage ends_at:past_week status:expired"
},
},
);
const data = await response.json();
mutation discountCodeBulkDelete($search: String) {
discountCodeBulkDelete(search: $search) {
job {
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 discountCodeBulkDelete($search: String) { discountCodeBulkDelete(search: $search) { job { id } userErrors { code field message } } }",
"variables": {
"search": "discount_type:percentage ends_at:past_week status:expired"
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation discountCodeBulkDelete($search: String) {
discountCodeBulkDelete(search: $search) {
job {
id
}
userErrors {
code
field
message
}
}
}`,
{
variables: {
"search": "discount_type:percentage ends_at:past_week status:expired"
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation discountCodeBulkDelete($search: String) {
discountCodeBulkDelete(search: $search) {
job {
id
}
userErrors {
code
field
message
}
}
}`,
"variables": {
"search": "discount_type:percentage ends_at:past_week status:expired"
},
},
});
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 discountCodeBulkDelete($search: String) {
discountCodeBulkDelete(search: $search) {
job {
id
}
userErrors {
code
field
message
}
}
}
QUERY
variables = {
"search": "discount_type:percentage ends_at:past_week status:expired"
}
response = client.query(query: query, variables: variables)
Input variables
JSON{
"search": "discount_type:percentage ends_at:past_week status:expired"
}
Response
JSON{
"discountCodeBulkDelete": {
"job": {
"id": "gid://shopify/Job/5c346b2e-979c-4449-ad4e-ac7a1090ecb4"
},
"userErrors": []
}
}