Skip to main content

GET /api/products

Retrieves a list of all active products in the system, sorted by creation date (newest first).

Authentication

No authentication required - this is a public endpoint.

Query Parameters

No query parameters are currently supported.

Response

count
number
required
The total number of products returned
products
array
required
Array of product objects
_id
string
Unique product identifier
name
string
Product name
description
string
Product description
price
number
Product price (must be >= 0)
stock
number
Available stock quantity (default: 0)
category
string
Product category. One of: digital, physical, service
image
string
Image URL for the product
isActive
boolean
Whether the product is active (default: true)
createdAt
string
ISO 8601 timestamp of when the product was created
updatedAt
string
ISO 8601 timestamp of when the product was last updated

Example Request

curl -X GET https://api.example.com/api/products

Example Response

{
  "count": 2,
  "products": [
    {
      "_id": "507f1f77bcf86cd799439011",
      "name": "Bitcoin Mining Course",
      "description": "Learn how to mine Bitcoin from scratch",
      "price": 99.99,
      "stock": 100,
      "category": "digital",
      "image": "https://example.com/images/bitcoin-course.jpg",
      "isActive": true,
      "createdAt": "2026-03-04T10:30:00.000Z",
      "updatedAt": "2026-03-04T10:30:00.000Z"
    },
    {
      "_id": "507f1f77bcf86cd799439012",
      "name": "Hardware Wallet",
      "description": "Secure your crypto assets",
      "price": 149.99,
      "stock": 50,
      "category": "physical",
      "image": "https://example.com/images/wallet.jpg",
      "isActive": true,
      "createdAt": "2026-03-03T15:20:00.000Z",
      "updatedAt": "2026-03-03T15:20:00.000Z"
    }
  ]
}

Error Responses

error
string
Error message describing what went wrong

500 - Internal Server Error

{
  "error": "Database connection failed"
}

Build docs developers (and LLMs) love