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
| Header | Type | Description |
|---|---|---|
Content-Type | string | Must be application/json. |
accessToken | string | Access token for authentication. (required) |
Request Body
The request body should be a JSON object containing the following fields:
Required Fields
| Field | Type | Description |
|---|---|---|
name | string | The name of the category. |
url | string | URL path segment for the category. |
Optional Fields
| Field | Type | Description |
|---|---|---|
description | string | A brief description of the category. Can be empty or omitted. |
parentCategory | string | ID of the parent category. Can be null if not applicable. |
path | string | Hierarchical path representation of the category. Required if parentCategory is set. |
images | array | List of image objects associated with the category, each containing url and description. |
isParent | boolean | Whether the category is a parent category. |
seo | object | SEO details including pageTitle, metaKeywords, and metaDescription. |
metaFields | array | List of metadata objects, each containing a code and a value (string, number, or array). |
Image Object (within images)
| Field | Type | Description |
|---|---|---|
url | string | URL of the image. |
description | string | Description of the image. |
SEO Object (within seo)
| Field | Type | Description |
|---|---|---|
pageTitle | string | Title for the category page. |
metaKeywords | string | Meta keywords for SEO. |
metaDescription | string | Meta 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
| Field | Type | Description |
|---|---|---|
success | boolean | Indicates whether the category was created successfully. Typically true for success. |
message | string | A message conveying the outcome of the operation. E.g., "Category created successfully". |
data | object | Contains details about the newly created category. See Category Data. |
Error Responses
| Status Code | Description |
|---|---|
| 400 | Bad Request: Provided data is invalid or missing fields. |
| 401 | Unauthorized: Access token is invalid or missing. |
| 500 | Internal 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
accessTokenis mandatory and must be valid to authenticate the request.