Anchor to collectionRemoveProductscollection
collection Remove Products
mutation
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.
Anchor to Arguments
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.
Was this section helpful?
- •
The asynchronous job removing the products.
- Anchor to userErrorsuser•
Errors [UserError!]!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 collectionRemoveProducts($id: ID!, $productIds: [ID!]!) {6 collectionRemoveProducts(id: $id, productIds: $productIds) {7 job {8 done9 id10 }11 userErrors {12 field13 message14 }15 }16 }`,17 {18 variables: {19 "id": "gid://shopify/Collection/1007901140",20 "productIds": [21 "gid://shopify/Product/20995642"22 ]23 },24 },25);2627const data = await response.json();28
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)
Input variables
JSON1{2 "id": "gid://shopify/Collection/1007901140",3 "productIds": [4 "gid://shopify/Product/20995642"5 ]6}
Response
JSON1{2 "collectionRemoveProducts": {3 "job": {4 "done": false,5 "id": "gid://shopify/Job/0d9c63ab-d903-4f1e-b9b1-6ddf55948dfb"6 },7 "userErrors": []8 }9}