http://localhost:8000/api/category
All routes below are prefixed with this base URL.
Fetch all categories with their subcategories.
{
"success": true,
"count": 1,
"data": [
{
"_id": "69a5b5e4930e55ca0f4c92d0",
"name": "Plastic",
"icon": "📦",
"description": "Plastic bottles, containers, bags, and other plastic items",
"subcategories": [
{
"name": "Bottles",
"_id": "69a5b5f2930e55ca0f4c92d7"
}
],
"createdAt": "2026-03-02T16:08:04.877Z",
"updatedAt": "2026-03-02T16:08:18.609Z",
"__v": 1
}
]
}
Create a new category with optional subcategories.
{ "name": "Paper", "icon": "📄", "description": "All types of paper waste including newspapers, books, cardboard", "subcategories": [] }
{
"success": true,
"message": "Category created successfully",
"data": {
"name": "Paper",
"icon": "📄",
"description": "All types of paper waste including newspapers, books, cardboard",
"subcategories": [],
"_id": "69abcdb6dd4ab4f2eea9048a",
"createdAt": "2026-03-07T07:03:18.620Z",
"updatedAt": "2026-03-07T07:03:18.620Z",
"__v": 0
}
}
Update an existing category by its ID. All fields are optional except _id.
{
"_id": "6720a8d8f1c2b3a5e4d90123",
"name": "Paper",
"icon": "📄",
"description": "Updated description",
"subcategories": [
{ "_id": "6720a8e6f1c2b3a5e4d90124", "name": "Newspaper" },
{ "_id": "6720a8f3f1c2b3a5e4d90125", "name": "Books" },
{ "name": "CardBoard" }
]
}
{
"success": true,
"message": "Category updated successfully",
"data": {
"_id": "6720a8d8f1c2b3a5e4d90123",
"name": "Paper",
"icon": "📄",
"description": "Updated description",
"subcategories": [
{ "_id": "6720a8e6f1c2b3a5e4d90124", "name": "Newspaper" },
{ "_id": "6720a8f3f1c2b3a5e4d90125", "name": "Books" },
{ "_id": "6720a9a1f1c2b3a5e4d90126", "name": "CardBoard" }
],
"createdAt": "2024-10-28T10:15:00.000Z",
"updatedAt": "2024-10-28T10:20:00.000Z",
"__v": 1
}
}
Delete a category by its ID.
{
"id": "6720a8d8f1c2b3a5e4d90123"
}
{
"success": true,
"message": "Category deleted successfully"
}
Add a new subcategory to an existing category.
{
"id": "6720a8d8f1c2b3a5e4d90123", // Category ID
"name": "Smart Watches" // SubCategory name
}
{
"success": true,
"message": "SubCategory added successfully",
"data": {
"_id": "6720a8d8f1c2b3a5e4d90123",
"name": "Paper",
"icon": "📄",
"description": "Electronic waste items",
"subcategories": [
{ "_id": "6720a8e6f1c2b3a5e4d90124", "name": "Newspaper" },
{ "_id": "6720a8f3f1c2b3a5e4d90125", "name": "Books" },
{ "_id": "6720aa11f1c2b3a5e4d90127", "name": "Smart Watches" }
]
}
}
Update a single subcategory inside a category.
{
"categoryId": "6720a8d8f1c2b3a5e4d90123",
"id": "6720a8e6f1c2b3a5e4d90124", // SubCategory _id
"name": "Smart Phones"
}
{
"success": true,
"message": "SubCategory updated successfully",
"data": {
"_id": "6720a8d8f1c2b3a5e4d90123",
"name": "Paper",
"icon": "📄",
"description": "Electronic waste items",
"subcategories": [
{ "_id": "6720a8e6f1c2b3a5e4d90124", "name": "Smart Phones" }
]
}
}
Delete a subcategory from a category.
{
"categoryId": "6720a8d8f1c2b3a5e4d90123",
"id": "6720a8e6f1c2b3a5e4d90124" // SubCategory _id
}
{
"success": true,
"message": "SubCategory deleted successfully",
"data": {
"_id": "6720a8d8f1c2b3a5e4d90123",
"name": "Paper",
"icon": "📄",
"description": "Electronic waste items",
"subcategories": [
// remaining subcategories
]
}
}