Update Category
This endpoint is used to update the details of an existing category. You can change various fields such as name, description, parent category, and more.
Endpoint
- URL:
/categories/{id} - Method:
PUT
Replace {id} with the specific category ID you want to update.
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) |
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The unique identifier of the category to be updated. |
Request Body
The request body should be a JSON object containing the fields you want to update. Below are the optional and required fields:
Updatable Fields
| Field | Type | Description |
|---|---|---|
name | string | The name of the category. |
url | string | URL path segment for the category. |
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 | Indicates 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. |
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. |
MetaFields Object
Each object in the metaFields array includes:
| Field | Type | Description |
|---|---|---|
code | string | Code for the metadata field. |
value | mixed | Value associated with the metadata (string, number, or array). |
Sample Request Body
{
"name": "Chem"
}
Response
- Status Code: 200 OK
Success Response Fields
| Field | Type | Description |
|---|---|---|
success | boolean | Indicates whether the category was updated successfully. Typically true for success. |
message | string | A message conveying the outcome of the operation, e.g., "Category updated successfully". |
data | object | Contains details about the updated category. See Category Data |
Example Success Response
{
"success": true,
"message": "Category updated successfully",
"data": {
"id": "632ccc741683c8f033d6e163",
"name": "Chem"
// Other potentially included updated fields
}
}
Error Responses
| Status Code | Description |
|---|---|
| 400 | Bad Request: Provided data is invalid or malformed. |
| 401 | Unauthorized: Access token is invalid or missing. |
| 404 | Not Found: Category with specified ID does not exist. |
| 500 | Internal Server Error: An error occurred on the server. |
Notes
- Ensure the ID of the category you wish to update is valid and exists.
- You must provide a valid
accessTokenfor authentication. - The fields you want to update must be included in the request body; omitted fields will remain unchanged.