Skip to main content
POST
/
categories
Create Category
curl --request POST \
  --url https://api.example.com/categories \
  --header 'Content-Type: application/json' \
  --data '
{
  "name": "<string>"
}
'
{
  "id": 123,
  "name": "<string>"
}
Create a new category.

Authentication

This endpoint requires authentication with the admin role.
Authorization: Bearer <admin_token>

Request Body

name
string
required
The name of the category. Cannot be empty. Maximum length: 60 characters.

Response

id
number
The unique identifier of the created category.
name
string
The name of the category.

Example Request

curl -X POST https://api.example.com/categories \
  -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Beverages"
  }'

Example Response

{
  "id": 1,
  "name": "Beverages"
}

Error Responses

400 Bad Request

Returned when the request body is invalid.
{
  "statusCode": 400,
  "message": [
    "The category name cannot be empty."
  ],
  "error": "Bad Request"
}

401 Unauthorized

Returned when authentication credentials are missing or invalid.
{
  "statusCode": 401,
  "message": "Unauthorized"
}

403 Forbidden

Returned when the user does not have admin role.
{
  "statusCode": 403,
  "message": "Forbidden resource",
  "error": "Forbidden"
}

Build docs developers (and LLMs) love