collectionRemoveProducts
Requires access scope. Also: The user must have a permission to remove products from a collection.
Removes a set of products from a given collection. The mutation can take a long time to run. Instead of returning an updated collection the mutation returns a job, which should be polled. For use with manual collections only.
Arguments
- •ID!required
The ID of the collection to remove products from. The ID must reference an existing manual collection.
- Anchor to productIdsproduct•
Ids [ID!]!required The IDs of products to remove from the collection. The mutation doesn't validate that the products belong to the collection or whether the products exist.
Anchor to CollectionRemoveProductsPayload returnsCollectionRemoveProductsPayload returns
- •
The asynchronous job removing the products.
- Anchor to userErrorsuser•
Errors [UserError!]! non-null The list of errors that occurred from executing the mutation.
- Remove a product from a manual collection
- Remove a product from a non-existent collection
- Remove a product from a smart collection
- Removes a product from a collection
- collectionRemoveProducts reference
Examples
mutation collectionRemoveProducts($id: ID!, $productIds: [ID!]!) {
collectionRemoveProducts(id: $id, productIds: $productIds) {
job {
done
id
}
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 collectionRemoveProducts($id: ID!, $productIds: [ID!]!) { collectionRemoveProducts(id: $id, productIds: $productIds) { job { done id } userErrors { field message } } }",
"variables": {
"id": "gid://shopify/Collection/1007901140",
"productIds": [
"gid://shopify/Product/20995642"
]
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation collectionRemoveProducts($id: ID!, $productIds: [ID!]!) {
collectionRemoveProducts(id: $id, productIds: $productIds) {
job {
done
id
}
userErrors {
field
message
}
}
}`,
{
variables: {
"id": "gid://shopify/Collection/1007901140",
"productIds": [
"gid://shopify/Product/20995642"
]
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation collectionRemoveProducts($id: ID!, $productIds: [ID!]!) {
collectionRemoveProducts(id: $id, productIds: $productIds) {
job {
done
id
}
userErrors {
field
message
}
}
}`,
"variables": {
"id": "gid://shopify/Collection/1007901140",
"productIds": [
"gid://shopify/Product/20995642"
]
},
},
});
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 collectionRemoveProducts($id: ID!, $productIds: [ID!]!) {
collectionRemoveProducts(id: $id, productIds: $productIds) {
job {
done
id
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"id": "gid://shopify/Collection/1007901140",
"productIds": ["gid://shopify/Product/20995642"]
}
response = client.query(query: query, variables: variables)