Skip to main content
PUT
/
api
/
categories
/
:categoryId
{
  "name": "Tech & Innovation",
  "description": "Updated description for technology articles"
}
{
  "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"
  }
}
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

categoryId
string
required
The unique MongoDB ObjectId of the category to update

Headers

Authorization
string
required
Bearer token with admin privilegesExample: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Content-Type
string
required
Must be set to application/json

Body Parameters

name
string
The new display name of the category. If provided, the slug will be automatically regenerated.
description
string
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

message
string
Success message
category
object
The updated category object
{
  "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
string
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

Build docs developers (and LLMs) love