Skip to main content
POST
/
subcategories
curl --location --request POST 'https://api.yourapp.com/subcategories' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data-raw '{
  "name": "Smartphones",
  "description": "Mobile phones and related accessories",
  "category_id": 1
}'
{
  "success": true,
  "message": "Subcategory created successfully",
  "data": {
    "subcategory": {
      "id": 1,
      "name": "Smartphones",
      "description": "Mobile phones and related accessories",
      "category": {
        "id": 1,
        "name": "Electronics",
        "description": "Electronic devices and components"
      },
      "created_at": "2024-03-08T09:15:00.000000Z",
      "updated_at": "2024-03-08T09:15:00.000000Z"
    }
  }
}
This endpoint creates a new subcategory with the provided information.

Authentication

This endpoint does not require authentication.

Request Body

name
string
required
Name of the subcategoryValidation:
  • Required
  • Must be a string
  • Maximum length: 255 characters
description
string
Description of the subcategoryValidation:
  • Optional (nullable)
  • Must be a string
  • Maximum length: 1000 characters
category_id
integer
required
ID of the parent categoryValidation:
  • Required
  • Must be a valid category ID that exists in the categories table

Response

success
boolean
Indicates if the request was successful
message
string
A success message confirming the creation
data
object
curl --location --request POST 'https://api.yourapp.com/subcategories' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data-raw '{
  "name": "Smartphones",
  "description": "Mobile phones and related accessories",
  "category_id": 1
}'
{
  "success": true,
  "message": "Subcategory created successfully",
  "data": {
    "subcategory": {
      "id": 1,
      "name": "Smartphones",
      "description": "Mobile phones and related accessories",
      "category": {
        "id": 1,
        "name": "Electronics",
        "description": "Electronic devices and components"
      },
      "created_at": "2024-03-08T09:15:00.000000Z",
      "updated_at": "2024-03-08T09:15:00.000000Z"
    }
  }
}

Build docs developers (and LLMs) love