Skip to main content

Create New Category

This endpoint is used to create a new category in the system. It requires certain fields to form a valid request body and accepts additional optional details.

Endpoint

  • URL: /categories
  • Method: POST

Authentication

  • Header: accessToken
  • Type: Bearer Token
  • Value: <ACCESS-TOKEN>

Request Headers

HeaderTypeDescription
Content-TypestringMust be application/json.
accessTokenstringAccess token for authentication. (required)

Request Body

The request body should be a JSON object containing the following fields:

Required Fields

FieldTypeDescription
namestringThe name of the category.
urlstringURL path segment for the category.

Optional Fields

FieldTypeDescription
descriptionstringA brief description of the category. Can be empty or omitted.
parentCategorystringID of the parent category. Can be null if not applicable.
pathstringHierarchical path representation of the category. Required if parentCategory is set.
imagesarrayList of image objects associated with the category, each containing url and description.
isParentbooleanWhether the category is a parent category.
seoobjectSEO details including pageTitle, metaKeywords, and metaDescription.
metaFieldsarrayList of metadata objects, each containing a code and a value (string, number, or array).

Image Object (within images)

FieldTypeDescription
urlstringURL of the image.
descriptionstringDescription of the image.

SEO Object (within seo)

FieldTypeDescription
pageTitlestringTitle for the category page.
metaKeywordsstringMeta keywords for SEO.
metaDescriptionstringMeta description for SEO.

Sample Request Body

{
"name": "chemicals",
"url": "test"
}

Response

  • Status Code: 201 Created

Success Response Body

{
"success": true,
"message": "Category created successfully",
"data": {
"id": "new_category_id", // Example ID of the newly created category
"name": "chemicals",
"url": "test"
// Additional fields with their actual values
}
}

Success Response Fields

FieldTypeDescription
successbooleanIndicates whether the category was created successfully. Typically true for success.
messagestringA message conveying the outcome of the operation. E.g., "Category created successfully".
dataobjectContains details about the newly created category. See Category Data.

Error Responses

Status CodeDescription
400Bad Request: Provided data is invalid or missing fields.
401Unauthorized: Access token is invalid or missing.
500Internal Server Error: An error occurred on the server.

Notes

  • Ensure you provide all required fields in the request body.
  • Optionally include other fields to enrich the category details.
  • The accessToken is mandatory and must be valid to authenticate the request.