Skip to main content

assignProductsToCategory

Requires permission products:product:update.

Assign existing products to a category. Products already in the category are skipped.

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:

mutation AssignProductsToCategory($categoryId: ID!, $productIds: [ID!]!) {
assignProductsToCategory(categoryId: $categoryId, productIds: $productIds) {
changedCount
skippedCount
category {
id
code
name
createdAt
childrenCount
deletedAt
}
}
}

Variables:

{
"categoryId": "id",
"productIds": [
"id"
]
}

Response:

{
"data": {
"assignProductsToCategory": {
"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"
}
}
}
}
assignProductsToCategory(
categoryId: ID!
productIds: [ID!]!
): CategoryProductAssignmentResult!

Arguments​

assignProductsToCategory.categoryId ● ID! non-null scalar​

The ID of the category.

assignProductsToCategory.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.