Updates an existing category’s details. This endpoint requires admin authentication.
This endpoint requires admin privileges. You must include a valid JWT token with admin role in the Authorization header.
Request
Path Parameters
The unique MongoDB ObjectId of the category to update
Bearer token with admin privilegesExample: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Must be set to application/json
Body Parameters
The new display name of the category. If provided, the slug will be automatically regenerated.
The new description of the category. Can be set to an empty string to clear the description.
{
"name": "Tech & Innovation",
"description": "Updated description for technology articles"
}
Response
The updated category object
Unique identifier for the category
Display name of the category
URL-friendly identifier (regenerated if name was changed)
Description of the category
ISO 8601 timestamp of when the category was created
{
"message": "Category updated successfully",
"category": {
"_id": "507f1f77bcf86cd799439011",
"name": "Tech & Innovation",
"slug": "tech-innovation",
"description": "Updated description for technology articles",
"createdAt": "2024-01-15T10:30:00.000Z"
}
}
Error Responses
Error message describing what went wrong
404 - Category Not Found
Returned when no category exists with the specified ID.
{
"error": "Category not found"
}
401 - Unauthorized
Returned when the authentication token is missing or invalid.
{
"error": "No token provided"
}
403 - Forbidden
Returned when the authenticated user is not an admin.
{
"error": "Admin access required"
}
500 - Internal Server Error
{
"error": "Database connection failed"
}
Example Request
curl -X PUT https://api.vaniyk-empire.com/api/categories/507f1f77bcf86cd799439011 \
-H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Tech & Innovation",
"description": "Updated description for technology articles"
}'
Notes
- All body parameters are optional - you can update just the name, just the description, or both
- If you update the
name, the slug will be automatically regenerated
- To clear the description, pass an empty string
- The
categoryId parameter must be a valid MongoDB ObjectId