Skip to main content

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.

FieldTypeRequiredDescription
nameStringYesName of the category.
urlStringYesURL slug of the category page on the storefront.
descriptionStringNoDescription of the category. Can be empty.
parentCategoryStringNoID of the parent category. Leave out or set to null for a top-level category.
pathStringConditionalRequired when parentCategory is set. The final path is generated automatically.
imageStringNoURL of the category image. The image is copied to your store's media library.
sortOrderNumberNoDisplay order. Lower numbers appear first. Default is 0.
isFeaturedBooleanNoWhether the category is featured. Default is false.
isShowBooleanNoWhether the category is visible on the storefront. Default is true.
isShowNavBarBooleanNoWhether the category appears in the navigation bar. Default is false.
seoObjectNoSEO settings for the category page. See below.
metaFieldsArrayNoCustom field values. See below.

SEO Object​

FieldTypeRequiredDescription
pageTitleStringNoPage title for the category.
metaKeywordsStringNoMeta keywords.
metaDescriptionStringNoMeta description.

MetaFields Object​

FieldTypeRequiredDescription
codeStringYesCode of an existing metafield. See Metafields.
valueString, Number, Boolean or ArrayNoValue 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​

FieldTypeDescription
successBooleantrue when the category was created.
messageStringConfirmation message.
dataObjectThe 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 path of the new category, call Get Category.
  • Metafields sent with an empty value are skipped.