createCategory
Requires permission categories:category:create.
Creates a category. The code must not be used by another active category, and a parent, when given, must exist. The level and path follow from the parent. Requires permission to create categories.
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 CreateCategory($input: CreateCategoryInput!) {
createCategory(input: $input) {
id
code
name
createdAt
childrenCount
deletedAt
children {
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 CreateCategory($input: CreateCategoryInput!) {\n createCategory(input: $input) {\n id\n code\n name\n createdAt\n childrenCount\n deletedAt\n children {\n id\n code\n name\n createdAt\n childrenCount\n deletedAt\n }\n }\n}",
"variables": {
"input": {
"code": "string",
"isActive": true,
"name": "string",
"sortOrder": 0
}
}
}
EOF
Variables:
{
"input": {
"code": "string",
"isActive": true,
"name": "string",
"sortOrder": 0
}
}
Response:
{
"data": {
"createCategory": {
"id": "id",
"code": "string",
"name": "string",
"createdAt": "2025-01-15T00:00:00Z",
"childrenCount": 0,
"deletedAt": "2025-01-15T00:00:00Z",
"children": [
{
"id": "id",
"code": "string",
"name": "string",
"createdAt": "2025-01-15T00:00:00Z",
"childrenCount": 0,
"deletedAt": "2025-01-15T00:00:00Z"
}
]
}
}
}
createCategory(
input: CreateCategoryInput!
): Category!
Arguments
createCategory.input ● CreateCategoryInput! non-null input
The details of the category to create.
Type
Category object
A node in the category tree. A root category is an ordinary category.