Skip to main content
POST
/
api
/
categories
{
  "name": "Technology",
  "description": "Articles about technology and innovation"
}
{
  "message": "Category created successfully",
  "category": {
    "_id": "507f1f77bcf86cd799439011",
    "name": "Technology",
    "slug": "technology",
    "description": "Articles about technology and innovation",
    "createdAt": "2024-01-15T10:30:00.000Z"
  }
}
Creates a new category in the system. 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

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
required
The display name of the category. Must be unique. The slug will be automatically generated from this name.
description
string
Optional description of the category
{
  "name": "Technology",
  "description": "Articles about technology and innovation"
}

Response

message
string
Success message
category
object
The newly created category object
{
  "message": "Category created successfully",
  "category": {
    "_id": "507f1f77bcf86cd799439011",
    "name": "Technology",
    "slug": "technology",
    "description": "Articles about technology and innovation",
    "createdAt": "2024-01-15T10:30:00.000Z"
  }
}

Error Responses

error
string
Error message describing what went wrong

400 - Category Already Exists

Returned when a category with the same name already exists.
{
  "error": "Category already exists"
}

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 POST https://api.vaniyk-empire.com/api/categories \
  -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Technology",
    "description": "Articles about technology and innovation"
  }'

Notes

  • The slug field is automatically generated from the name field by converting to lowercase and replacing spaces/special characters with hyphens
  • Category names must be unique across the system
  • The auto-generated slug must also be unique

Build docs developers (and LLMs) love