Skip to main content

Create Category

Create a new category. You can create either a main category (by omitting parentId) or a subcategory (by providing a parentId).

Endpoint

POST /api/v1/categories

Request Body

name
string
required
The category name
description
string
Detailed description of the category
parentId
integer
ID of the parent category. Omit this field or set to null to create a main category
isActive
boolean
default:"true"
Whether the category should be active upon creation

Response

Returns the created category object with a Location header pointing to the new resource.
id
integer
Unique identifier for the newly created category
name
string
The category name
description
string
Detailed description of the category
parentId
integer
ID of the parent category (null for main categories)
isActive
boolean
Whether the category is currently active
product_ids
array
List of product IDs (empty for new categories)
subcategory_ids
array
List of subcategory IDs (empty for new categories)

Status Codes

  • 201 - Category successfully created
  • 400 - Invalid request body or validation error

Examples

Create a Main Category

curl -X POST "https://api.example.com/api/v1/categories" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Living Room",
    "description": "Furniture for living spaces",
    "isActive": true
  }'

Response

{
  "id": 1,
  "name": "Living Room",
  "description": "Furniture for living spaces",
  "parentId": null,
  "isActive": true,
  "product_ids": [],
  "subcategory_ids": []
}

Create a Subcategory

curl -X POST "https://api.example.com/api/v1/categories" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Sofas",
    "description": "Comfortable seating furniture",
    "parentId": 1,
    "isActive": true
  }'

Response

{
  "id": 10,
  "name": "Sofas",
  "description": "Comfortable seating furniture",
  "parentId": 1,
  "isActive": true,
  "product_ids": [],
  "subcategory_ids": []
}

Build docs developers (and LLMs) love