Skip to main content
GET
/
categories
/
{id}
Get Category
curl --request GET \
  --url https://api.example.com/categories/{id}
{
  "id": 123,
  "name": "<string>",
  "products": [
    {
      "id": 123,
      "name": "<string>",
      "price": 123,
      "stock": 123,
      "categoryId": 123
    }
  ]
}
Retrieve a specific category by ID.

Authentication

This endpoint is public and does not require authentication.

Path Parameters

id
integer
required
The unique identifier of the category.

Query Parameters

products
boolean
Include the list of products associated with this category. When set to true, the response will include a products array ordered by product ID in ascending order.

Response

id
number
The unique identifier of the category.
name
string
The name of the category.
products
array
Array of products in this category. Only included when products=true query parameter is set.

Example Request

Basic Request

curl -X GET https://api.example.com/categories/1

With Products

curl -X GET https://api.example.com/categories/1?products=true

Example Response

Basic Response

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

Response with Products

{
  "id": 1,
  "name": "Beverages",
  "products": [
    {
      "id": 1,
      "name": "Coffee",
      "price": 4.99,
      "stock": 50,
      "categoryId": 1
    },
    {
      "id": 3,
      "name": "Tea",
      "price": 3.99,
      "stock": 30,
      "categoryId": 1
    }
  ]
}

Error Responses

400 Bad Request

Returned when the ID parameter is invalid.
{
  "statusCode": 400,
  "message": "Validation failed (numeric string is expected)",
  "error": "Bad Request"
}

404 Not Found

Returned when the category with the specified ID does not exist.
{
  "statusCode": 404,
  "message": "Category not found",
  "error": "Not Found"
}

Build docs developers (and LLMs) love