Categories
Categories organize Products into hierarchical structures. They enable creating multiple classifications of Products for shop navigation and other purposes.
Products can be in any number of Categories and there can be multiple Category hierarchies for different purposes or Channels. Categories are embedded in the Product search so that you can filter Products by their assignment to Categories, including Products in child Categories. Categories are also an own, customizable resource that can be extended with your own content, workflow, and metadata. Relevant search engine optimization fields are built-in, for example, uniqueness-checked and internationalizable URL components ("slugs"). Since they are an API resource per Category, they scale well into very large numbers of Categories and the Merchant Center is also well prepared for managing such large classifications. Finally, a full text search with autosuggest over all Categories and their content is available via the GraphQL API.
Deciding how to model your categories for navigation and other purposes is an important part of working with the API. For more information, see the Product Modeling Guide.
Representations
Category
idString | Unique identifier of the Category. |
versionInt | Current version of the Category. |
keyString | User-defined unique identifier of the Category. MinLength:2MaxLength: 256Pattern: ^[A-Za-z0-9_-]+$ |
externalIdString | Additional identifier for external systems like Customer Relationship Management (CRM) or Enterprise Resource Planning (ERP). |
name | Name of the Category. |
slug | User-defined identifier used as a deep-link URL to the related Category per Locale.
A Category can have the same slug for different Locales, but they are unique across the Project.
Valid slugs match the pattern |
description | Description of the Category. |
ancestorsArray of CategoryReference | Contains the parent path towards the root Category. |
parent | Parent Category of this Category. |
orderHintString | Decimal value between 0 and 1 used to order Categories that are on the same level in the Category tree. |
metaTitle | Name of the Category used by external search engines for improved search engine performance. |
metaDescription | Description of the Category used by external search engines for improved search engine performance. |
metaKeywords | Keywords related to the Category for improved search engine performance. |
assetsArray of Asset | Media related to the Category. |
custom | Custom Fields for the Category. |
createdAt | Date and time (UTC) the Category was initially created. |
createdByBETA | Present on resources created after 1 February 2019 except for events not tracked. |
lastModifiedAt | Date and time (UTC) the Category was last updated. |
lastModifiedByBETA | Present on resources updated after 1 February 2019 except for events not tracked. |
CategoryDraft
keyString | User-defined unique identifier for the Category. MinLength:2MaxLength: 256Pattern: ^[A-Za-z0-9_-]+$ |
externalIdString | Additional identifier for external systems like Customer Relationship Management (CRM) or Enterprise Resource Planning (ERP). |
name | Name of the Category. |
slug | |
description | Description of the Category. |
parent | Parent Category of the Category.
The parent can be set by its |
orderHintString | Decimal value between 0 and 1 used to order Categories that are on the same level in the Category tree. If not set, a random value will be assigned. |
metaTitle | Name of the Category used by external search engines for improved search engine performance. |
metaDescription | Description of the Category used by external search engines for improved search engine performance. |
metaKeywords | Keywords related to the Category for improved search engine performance. |
assetsArray of AssetDraft | Media related to the Category. |
custom | Custom Fields for the Category. |
CategoryPagedQueryResponse
PagedQueryResult with results containing an array of Category.
limitInt | Number of results requested. |
offsetInt | Number of elements skipped. |
countInt | Actual number of results returned. |
totalInt | Total number of results matching the query.
This number is an estimation that is not strongly consistent.
This field is returned by default.
For improved performance, calculating this field can be deactivated by using the query parameter |
resultsArray of Category | Category matching the query. |
CategoryReference
CategoryResourceIdentifier
ResourceIdentifier to a Category.
Get Category
Get Category by ID
Either the scope view_products:{projectKey} or view_categories:{projectKey} is required.
view_products:{projectKey}, view_categories:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
idString |
|
expand | The parameter can be passed multiple times. |
200Category
curl -X GET https://api.{region}.commercetools.com/{projectKey}/categories/{id} -i \--header 'Authorization: Bearer ${BEARER_TOKEN}'
{"id" : "c2f93298-c967-44af-8c2a-d2220bf39eb2","version" : 1,"name" : {"en" : "Hats"},"slug" : {"en" : "hats"},"parent" : {"typeId" : "category","id" : "123456"},"ancestors" : [ ],"orderHint" : "0.1","createdAt" : "1970-01-01T00:00:00.001Z","lastModifiedAt" : "1970-01-01T00:00:00.001Z"}
Get Category by Key
Either the scope view_products:{projectKey} or view_categories:{projectKey} is required.
view_products:{projectKey}, view_categories:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
keyString |
|
expand | The parameter can be passed multiple times. |
200Category
curl -X GET https://api.{region}.commercetools.com/{projectKey}/categories/key={key} -i \--header 'Authorization: Bearer ${BEARER_TOKEN}'
{"id" : "c2f93298-c967-44af-8c2a-d2220bf39eb2","version" : 1,"name" : {"en" : "Hats"},"slug" : {"en" : "hats"},"parent" : {"typeId" : "category","id" : "123456"},"ancestors" : [ ],"orderHint" : "0.1","createdAt" : "1970-01-01T00:00:00.001Z","lastModifiedAt" : "1970-01-01T00:00:00.001Z"}
Query Categories
Either the scope view_products:{projectKey} or view_categories:{projectKey} is required.
view_products:{projectKey}, view_categories:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
where | The parameter can be passed multiple times. |
/^var[.][a-zA-Z0-9]+$/Any string parameter matching this regular expression | Predicate parameter values. The parameter can be passed multiple times. |
sort | The parameter can be passed multiple times. |
expand | The parameter can be passed multiple times. |
limitInt | Number of results requested. |
offsetInt | Number of elements skipped. |
withTotalBoolean | Controls the calculation of the total number of query results. Set to |
curl -X GET https://api.{region}.commercetools.com/{projectKey}/categories -i \--header 'Authorization: Bearer ${BEARER_TOKEN}'
{"limit" : 20,"offset" : 0,"count" : 2,"total" : 2,"results" : [ {"id" : "c2f93298-c967-44af-8c2a-d2220bf39eb2","version" : 1,"name" : {"en" : "Hats"},"slug" : {"en" : "hats"},"ancestors" : [ {"typeId" : "category","id" : "123456"} ],"orderHint" : "0.1","createdAt" : "1970-01-01T00:00:00.001Z","lastModifiedAt" : "1970-01-01T00:00:00.001Z"}, {"id" : "1bae3aa3-1e02-49d2-b719-4c5020f50638","version" : 1,"name" : {"en" : "Long sleeves"},"slug" : {"en" : "long-sleeves"},"ancestors" : [ ],"orderHint" : "0.2","createdAt" : "1970-01-01T00:00:00.001Z","lastModifiedAt" : "1970-01-01T00:00:00.001Z"} ]}
Create Category
Either the scope manage_products:{projectKey} or manage_categories:{projectKey} is required.
Creating a Category produces the CategoryCreated Message.
manage_products:{projectKey}, manage_categories:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
expand | The parameter can be passed multiple times. |
201Category
curl -X POST https://api.{region}.commercetools.com/{projectKey}/categories -i \--header 'Authorization: Bearer ${BEARER_TOKEN}' \--header 'Content-Type: application/json' \--data-binary @- << DATA{"name" : {"en" : "Hats"},"slug" : {"en" : "hats"},"parent" : {"typeId" : "category","id" : "123456"},"orderHint" : "0.1"}DATA
{"id" : "c2f93298-c967-44af-8c2a-d2220bf39eb2","version" : 1,"name" : {"en" : "Hats"},"slug" : {"en" : "hats"},"parent" : {"typeId" : "category","id" : "123456"},"ancestors" : [ ],"orderHint" : "0.1","createdAt" : "1970-01-01T00:00:00.001Z","lastModifiedAt" : "1970-01-01T00:00:00.001Z"}
Update Category
Update Category by ID
Either the scope manage_products:{projectKey} or manage_categories:{projectKey} is required.
manage_products:{projectKey}, manage_categories:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
idString |
|
expand | The parameter can be passed multiple times. |
versionInt | Expected version of the Category on which the changes should be applied. If the expected version does not match the actual version, a 409 Conflict will be returned. |
actionsArray of CategoryUpdateAction | Update actions to be performed on the Category. |
200Category
curl -X POST https://api.{region}.commercetools.com/{projectKey}/categories/{id} -i \--header 'Authorization: Bearer ${BEARER_TOKEN}' \--header 'Content-Type: application/json' \--data-binary @- << DATA{"version" : 1,"actions" : [ {"action" : "changeName","name" : {"en" : "New Name"}} ]}DATA
{"id" : "c2f93298-c967-44af-8c2a-d2220bf39eb2","version" : 1,"name" : {"en" : "Hats"},"slug" : {"en" : "hats"},"parent" : {"typeId" : "category","id" : "123456"},"ancestors" : [ ],"orderHint" : "0.1","createdAt" : "1970-01-01T00:00:00.001Z","lastModifiedAt" : "1970-01-01T00:00:00.001Z"}
Update Category by Key
Either the scope manage_products:{projectKey} or manage_categories:{projectKey} is required.
manage_products:{projectKey}, manage_categories:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
keyString |
|
expand | The parameter can be passed multiple times. |
versionInt | Expected version of the Category on which the changes should be applied. If the expected version does not match the actual version, a 409 Conflict will be returned. |
actionsArray of CategoryUpdateAction | Update actions to be performed on the Category. |
200Category
curl -X POST https://api.{region}.commercetools.com/{projectKey}/categories/key={key} -i \--header 'Authorization: Bearer ${BEARER_TOKEN}' \--header 'Content-Type: application/json' \--data-binary @- << DATA{"version" : 1,"actions" : [ {"action" : "changeName","name" : {"en" : "New Name"}} ]}DATA
{"id" : "c2f93298-c967-44af-8c2a-d2220bf39eb2","version" : 1,"name" : {"en" : "Hats"},"slug" : {"en" : "hats"},"parent" : {"typeId" : "category","id" : "123456"},"ancestors" : [ ],"orderHint" : "0.1","createdAt" : "1970-01-01T00:00:00.001Z","lastModifiedAt" : "1970-01-01T00:00:00.001Z"}
Update actions
Set Key
actionString | "setKey" |
keyString | Value to set. If empty, any existing value will be removed. MinLength:2MaxLength: 256Pattern: ^[A-Za-z0-9_-]+$ |
{"action" : "setKey","key" : "myNewKey"}
Change Name
actionString | "changeName" |
name | New value to set. Must not be empty. |
{"action" : "changeName","name" : {"de" : "neuer Category Name","en" : "new category name"}}
Change Slug
Changing the slug produces the CategorySlugChanged Message.
actionString | "changeSlug" |
slug |
{"action" : "changeSlug","slug" : {"de" : "meine-kategorie","en" : "my-category"}}
Set Description
actionString | "setDescription" |
description | Value to set. If empty, any existing value will be removed. |
{"action" : "setDescription","description" : {"de" : "This is a category description","en" : "Dies ist eine Kategorie-Beschreibung"}}
Change Parent
Changing parents should not be done concurrently. Concurrent changes of parent categories might lead to corrupted ancestor lists (paths).
actionString | "changeParent" |
parent | New value to set as parent. |
{"action" : "changeParent","parent" : {"typeId" : "category","id" : "{{category-id}}"}}
Change OrderHint
actionString | "changeOrderHint" |
orderHintString | New value to set. Must be a decimal value between 0 and 1. |
{"action" : "changeOrderHint","orderHint" : "0.1"}
Set External ID
This update action sets a new ID that can be used as an additional identifier for external systems like Customer Relationship Management (CRM) or Enterprise Resource Planning (ERP).
actionString | "setExternalId" |
externalIdString | Value to set. If empty, any existing value will be removed. |
{"action" : "setExternalId","externalId" : "externalIdString"}
Set Meta Title
actionString | "setMetaTitle" |
metaTitle | Value to set. |
{"action" : "setMetaTitle","metaTitle" : {"de" : "Dies ist mein Meta-Title","en" : "This is my meta title"}}
Set Meta Description
actionString | "setMetaDescription" |
metaDescription | Value to set. |
{"action" : "setMetaDescription","metaDescription" : {"de" : "Dies ist meine MetaDecription","en" : "this is my meta description"}}
Set Meta Keywords
actionString | "setMetaKeywords" |
metaKeywords | Value to set. |
{"action" : "setMetaKeywords","metaKeywords" : {"de" : "commercetools, genial","en" : "commercetools, aweseome"}}
Set Custom Type
actionString | "setCustomType" |
type | Defines the Type that extends the Category with Custom Fields. If absent, any existing Type and Custom Fields are removed from the Category. |
fields | Sets the Custom Fields fields for the Category. |
{"action" : "setCustomType","type" : {"id" : "{{type-id}}","typeId" : "type"},"fields" : {"examplaryStringTypeField" : "TextString"}}
Set CustomField
actionString | "setCustomField" |
nameString | Name of the Custom Field. |
value | If |
{"action" : "setCustomField","name" : "ExamplaryStringTypeField","value" : "TextString"}
Add Asset
actionString | "addAsset" |
asset | Value to append. |
positionInt | Position in the array at which the Asset should be put. When specified, the value must be between |
{"action" : "addAsset","asset" : {"sources" : [ {"uri" : "https://www.commercetools.de/ct-logo.svg","key" : "vector"} ],"name" : {"de" : "commercetools Logo","en" : "commercetools logo"}}}
Remove Asset
actionString | "removeAsset" |
assetIdString | Value to remove. Either |
assetKeyString | Value to remove. Either |
{"action" : "removeAsset","assetId" : "{{assetId}}"}
Set Asset Key
Set or remove the key of an Asset.
actionString | "setAssetKey" |
assetIdString | Value to set. |
assetKeyString | Value to set. If empty, any existing value will be removed. |
{"action" : "setAssetKey","assetId" : "{{assetId}}"}
Change Asset Order
This update action changes the order of the assets array. The new order is defined by listing the ids of the Assets.
actionString | "changeAssetOrder" |
assetOrderArray of String | New value to set. Must contain all Asset |
{"action" : "changeAssetOrder","assetOrder" : [ "{{assetId1}}", "{{assetId2}}" ]}
Change Asset Name
actionString | "changeAssetName" |
assetIdString | New value to set. Either |
assetKeyString | New value to set. Either |
name | New value to set. Must not be empty. |
{"action" : "changeAssetName","assetId" : "{{assetId}}","name" : {"de" : "Mein Asset","en" : "My asset"}}
Set Asset Description
actionString | "setAssetDescription" |
assetIdString | New value to set. Either |
assetKeyString | New value to set. Either |
description | Value to set. If empty, any existing value will be removed. |
{"action" : "setAssetDescription","assetId" : "{{assetId}}","description" : {"de" : "Dies ist eine Asset-Beschreibung","en" : "This is an asset description"}}
Set Asset Sources
actionString | "setAssetSources" |
assetIdString | New value to set. Either |
assetKeyString | New value to set. Either |
sourcesArray of AssetSource | Must not be empty. At least one entry is required. |
{"action" : "setAssetSources","assetId" : "{{assetId}}","sources" : [ {"uri" : "https://www.commercetools.de/ct-logo.svg","key" : "vector"} ]}
Set Asset Custom Type
actionString | "setAssetCustomType" |
assetIdString | New value to set. Either |
assetKeyString | New value to set. Either |
type | Defines the Type that extends the Asset with Custom Fields. If absent, any existing Type and Custom Fields are removed from the Asset. |
fields | Sets the Custom Fields fields for the Asset. |
{"action" : "setAssetCustomType","assetId" : "{{assetId}}","type" : {"id" : "{{type-id}}","typeId" : "type"},"fields" : {"examplaryStringTypeField" : "TextString"}}
Set Asset CustomField
actionString | "setAssetCustomField" |
assetIdString | New value to set. Either |
assetKeyString | New value to set. Either |
nameString | Name of the Custom Field. |
value | If |
{"action" : "setAssetCustomField","assetId" : "{{assetId}}","name" : "ExamplaryStringTypeField","value" : "TextString"}
Delete Category
The deleted Category will be removed from all the Products that had the Category assigned in their ProductData.
Deleting a root Category deletes the whole Category tree.
Delete Category by ID
Either the scope manage_products:{projectKey} or manage_categories:{projectKey} is required.
manage_products:{projectKey}, manage_categories:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
idString |
|
versionInt | Last seen version of the resource. |
expand | The parameter can be passed multiple times. |
200Category
curl -X DELETE https://api.{region}.commercetools.com/{projectKey}/categories/{id}?version={version} -i \--header 'Authorization: Bearer ${BEARER_TOKEN}'
{"id" : "c2f93298-c967-44af-8c2a-d2220bf39eb2","version" : 1,"name" : {"en" : "Hats"},"slug" : {"en" : "hats"},"parent" : {"typeId" : "category","id" : "123456"},"ancestors" : [ ],"orderHint" : "0.1","createdAt" : "1970-01-01T00:00:00.001Z","lastModifiedAt" : "1970-01-01T00:00:00.001Z"}
Delete Category by Key
Either the scope manage_products:{projectKey} or manage_categories:{projectKey} is required.
manage_products:{projectKey}, manage_categories:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
keyString |
|
versionInt | Last seen version of the resource. |
expand | The parameter can be passed multiple times. |
200Category
curl -X DELETE https://api.{region}.commercetools.com/{projectKey}/categories/key={key}?version={version} -i \--header 'Authorization: Bearer ${BEARER_TOKEN}'
{"id" : "c2f93298-c967-44af-8c2a-d2220bf39eb2","version" : 1,"name" : {"en" : "Hats"},"slug" : {"en" : "hats"},"parent" : {"typeId" : "category","id" : "123456"},"ancestors" : [ ],"orderHint" : "0.1","createdAt" : "1970-01-01T00:00:00.001Z","lastModifiedAt" : "1970-01-01T00:00:00.001Z"}