Anchor to discountCodeBulkDeletediscount
discount Code Bulk Delete
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?
- •
The asynchronous job that deletes the discounts.
- Anchor to userErrorsuser•
Errors [DiscountUser Error!]!non-null The list of errors that occurred from executing the mutation.
Was this section helpful?
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation discountCodeBulkDelete($search: String) {6 discountCodeBulkDelete(search: $search) {7 job {8 id9 }10 userErrors {11 code12 field13 message14 }15 }16 }`,17 {18 variables: {19 "search": "discount_type:percentage ends_at:past_week status:expired"20 },21 },22);2324const data = await response.json();25
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
JSON1{2 "search": "discount_type:percentage ends_at:past_week status:expired"3}
Response
JSON1{2 "discountCodeBulkDelete": {3 "job": {4 "id": "gid://shopify/Job/5c346b2e-979c-4449-ad4e-ac7a1090ecb4"5 },6 "userErrors": []7 }8}