Anchor to productVariantsBulkDeleteproduct
productVariantsBulkDelete
mutation
Requires access scope. Also: The user must have a permission to delete product variants.
Deletes multiple variants in a single product. This mutation can be called directly or via the bulkOperation.
Anchor to Arguments
Arguments
- Anchor to productIdproduct•
Id ID!required The ID of the product with the variants to update.
- Anchor to variantsIdsvariants•
Ids [ID!]!required An array of product variants IDs to delete.
Was this section helpful?
Anchor to ProductVariantsBulkDeletePayload returnsProductVariantsBulkDeletePayload returns
- Anchor to productproduct•
The updated product object.
- Anchor to userErrorsuser•
Errors The list of errors that occurred from executing the mutation.
Was this section helpful?
- Bulk delete multiple product variants.
- Remove an existing Product Variant
- Returns an error if any of the product variants does not belong to the product.
- productVariantsBulkDelete reference
Examples
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation bulkDeleteProductVariants($productId: ID!, $variantsIds: [ID!]!) {
productVariantsBulkDelete(productId: $productId, variantsIds: $variantsIds) {
product {
id
title
}
userErrors {
field
message
}
}
}`,
{
variables: {
"productId": "gid://shopify/Product/20995642",
"variantsIds": [
"gid://shopify/ProductVariant/30322695",
"gid://shopify/ProductVariant/113711323"
]
},
},
);
const data = await response.json();
mutation bulkDeleteProductVariants($productId: ID!, $variantsIds: [ID!]!) {
productVariantsBulkDelete(productId: $productId, variantsIds: $variantsIds) {
product {
id
title
}
userErrors {
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 bulkDeleteProductVariants($productId: ID!, $variantsIds: [ID!]!) { productVariantsBulkDelete(productId: $productId, variantsIds: $variantsIds) { product { id title } userErrors { field message } } }",
"variables": {
"productId": "gid://shopify/Product/20995642",
"variantsIds": [
"gid://shopify/ProductVariant/30322695",
"gid://shopify/ProductVariant/113711323"
]
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation bulkDeleteProductVariants($productId: ID!, $variantsIds: [ID!]!) {
productVariantsBulkDelete(productId: $productId, variantsIds: $variantsIds) {
product {
id
title
}
userErrors {
field
message
}
}
}`,
{
variables: {
"productId": "gid://shopify/Product/20995642",
"variantsIds": [
"gid://shopify/ProductVariant/30322695",
"gid://shopify/ProductVariant/113711323"
]
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation bulkDeleteProductVariants($productId: ID!, $variantsIds: [ID!]!) {
productVariantsBulkDelete(productId: $productId, variantsIds: $variantsIds) {
product {
id
title
}
userErrors {
field
message
}
}
}`,
"variables": {
"productId": "gid://shopify/Product/20995642",
"variantsIds": [
"gid://shopify/ProductVariant/30322695",
"gid://shopify/ProductVariant/113711323"
]
},
},
});
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 bulkDeleteProductVariants($productId: ID!, $variantsIds: [ID!]!) {
productVariantsBulkDelete(productId: $productId, variantsIds: $variantsIds) {
product {
id
title
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"productId": "gid://shopify/Product/20995642",
"variantsIds": ["gid://shopify/ProductVariant/30322695", "gid://shopify/ProductVariant/113711323"]
}
response = client.query(query: query, variables: variables)
Input variables
JSON{
"productId": "gid://shopify/Product/20995642",
"variantsIds": [
"gid://shopify/ProductVariant/30322695",
"gid://shopify/ProductVariant/113711323"
]
}
Response
JSON{
"productVariantsBulkDelete": {
"product": {
"id": "gid://shopify/Product/20995642",
"title": "Element"
},
"userErrors": []
}
}