removeProductsFromCategory
Requires permission products:product:update.
Detach products from a category. Only products currently in this category are affected; the product's other categories are untouched.
Errors: a failed call returns a GraphQL errors entry, not a field on the result, and data may be null or partial. Read the entry's extensions.code and message; every shape and code is in the Error reference.
Example:
- GraphQL
- cURL
mutation RemoveProductsFromCategory($categoryId: ID!, $productIds: [ID!]!) {
removeProductsFromCategory(categoryId: $categoryId, productIds: $productIds) {
changedCount
skippedCount
category {
id
code
name
createdAt
childrenCount
deletedAt
}
}
}
curl -X POST "https://<api-host>/graphql" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
--data @- <<'EOF'
{
"query": "mutation RemoveProductsFromCategory($categoryId: ID!, $productIds: [ID!]!) {\n removeProductsFromCategory(categoryId: $categoryId, productIds: $productIds) {\n changedCount\n skippedCount\n category {\n id\n code\n name\n createdAt\n childrenCount\n deletedAt\n }\n }\n}",
"variables": {
"categoryId": "id",
"productIds": [
"id"
]
}
}
EOF
Variables:
{
"categoryId": "id",
"productIds": [
"id"
]
}
Response:
{
"data": {
"removeProductsFromCategory": {
"changedCount": 0,
"skippedCount": 0,
"category": {
"id": "id",
"code": "string",
"name": "string",
"createdAt": "2025-01-15T00:00:00Z",
"childrenCount": 0,
"deletedAt": "2025-01-15T00:00:00Z"
}
}
}
}
removeProductsFromCategory(
categoryId: ID!
productIds: [ID!]!
): CategoryProductAssignmentResult!
Arguments
removeProductsFromCategory.categoryId ● ID! non-null scalar
The ID of the category.
removeProductsFromCategory.productIds ● [ID!]! non-null scalar
The IDs of the products.
Type
CategoryProductAssignmentResult object
The result of adding existing products to a category, or removing them.