Create New Category
Creates a new category and returns it. To create a subcategory, set parentCategory to the ID of the parent category.
HTTP Request
- URL:
/categories - Method:
POST - Headers:
accessToken: Required. Your API access token.Content-Type:application/json
- Required scope:
READ_WRITE_CATEGORY
Request Body
Send a JSON object with the following fields.
| Field | Type | Required | Description |
|---|---|---|---|
name | String | Yes | Name of the category. |
url | String | Yes | URL slug of the category page on the storefront. |
description | String | No | Description of the category. Can be empty. |
parentCategory | String | No | ID of the parent category. Leave out or set to null for a top-level category. |
path | String | Conditional | Required when parentCategory is set. The final path is generated automatically. |
image | String | No | URL of the category image. The image is copied to your store's media library. |
sortOrder | Number | No | Display order. Lower numbers appear first. Default is 0. |
isFeatured | Boolean | No | Whether the category is featured. Default is false. |
isShow | Boolean | No | Whether the category is visible on the storefront. Default is true. |
isShowNavBar | Boolean | No | Whether the category appears in the navigation bar. Default is false. |
seo | Object | No | SEO settings for the category page. See below. |
metaFields | Array | No | Custom field values. See below. |
SEO Object
| Field | Type | Required | Description |
|---|---|---|---|
pageTitle | String | No | Page title for the category. |
metaKeywords | String | No | Meta keywords. |
metaDescription | String | No | Meta description. |
MetaFields Object
| Field | Type | Required | Description |
|---|---|---|---|
code | String | Yes | Code of an existing metafield. See Metafields. |
value | String, Number, Boolean or Array | No | Value to store for this metafield. |
cURL Example
curl --location '<BASE_URL>/categories' \
--header 'accessToken: <ACCESS_TOKEN>' \
--header 'Content-Type: application/json' \
--data '{
"name": "Cordless Drills",
"url": "cordless-drills",
"description": "Battery-powered drills and drivers.",
"parentCategory": "663a0cbe516313e5bc94aa87",
"path": "/663a0cbe516313e5bc94aa87/",
"seo": {
"pageTitle": "Cordless Drills",
"metaDescription": "Shop cordless drills."
}
}'
Response
- 200 OK: The category was created successfully.
- 400 Bad Request: The access token is missing, invalid or lacks the required scope, or the request body is not valid (for example, a required field is missing).
Sample JSON Response
{
"success": true,
"message": "Category added Successfully",
"data": {
"id": "66acedf2bf8641f96544253b",
"name": "Cordless Drills",
"url": "cordless-drills",
"description": "Battery-powered drills and drivers.",
"parentCategory": "663a0cbe516313e5bc94aa87",
"path": "/663a0cbe516313e5bc94aa87/",
"hasParent": true,
"hasChildren": false,
"productCount": 0,
"sortOrder": 0,
"isFeatured": false,
"isShow": true,
"isShowNavBar": false,
"seo": {
"pageTitle": "Cordless Drills",
"metaDescription": "Shop cordless drills."
},
"metaFields": [],
"createdAt": "2024-08-02T14:32:18.344Z",
"updatedAt": "2024-08-02T14:32:18.344Z"
}
}
Response Details
| Field | Type | Description |
|---|---|---|
success | Boolean | true when the category was created. |
message | String | Confirmation message. |
data | Object | The new category. See Get Category for its fields. |
Notes
- When you create a subcategory, the parent category is marked as having subcategories.
- To see the generated
pathof the new category, call Get Category. - Metafields sent with an empty value are skipped.