Skip to main content
GET
/
orders
curl -X GET http://localhost:3000/orders \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
{
  "orders": [
    {
      "_id": "65abc123def456789012345",
      "products": [
        {
          "product": {
            "_id": "507f1f77bcf86cd799439011",
            "name": "Gaming Mouse",
            "price": 49.99,
            "brand": "Logitech"
          },
          "quantity": 2,
          "customName": "Special Edition Mouse"
        },
        {
          "product": {
            "_id": "507f191e810c19729de860ea",
            "name": "Mechanical Keyboard",
            "price": 99.99,
            "brand": "Corsair"
          },
          "quantity": 1,
          "customName": null
        }
      ],
      "total": 199.97,
      "createdAt": "2024-01-15T10:30:00.000Z",
      "updatedAt": "2024-01-15T10:30:00.000Z"
    },
    {
      "_id": "65abc123def456789012346",
      "products": [
        {
          "product": {
            "_id": "507f191e810c19729de860eb",
            "name": "USB-C Cable",
            "price": 12.99,
            "brand": "Anker"
          },
          "quantity": 3,
          "customName": null
        }
      ],
      "total": 38.97,
      "createdAt": "2024-01-14T15:20:00.000Z",
      "updatedAt": "2024-01-14T15:20:00.000Z"
    }
  ]
}
Retrieves all orders sorted by creation date (newest first). Each order includes populated product information.

Authentication

This endpoint requires authentication. Include a valid JWT token in the Authorization header.

Response

orders
array
Array of order objects sorted by creation date (newest first)
_id
string
Unique order identifier
products
array
Array of ordered products with populated details
product
object
Product details
_id
string
Product ID
name
string
Product name
price
number
Product price
brand
string
Product brand
quantity
number
Quantity ordered
customName
string
Custom product name if provided
total
number
Total price of the order
createdAt
string
Timestamp when order was created
updatedAt
string
Timestamp when order was last updated

Error Responses

  • 401 Unauthorized: Missing or invalid authentication token
  • 404 Not Found: No orders exist in the system
  • 500 Internal Server Error: Server error during retrieval
curl -X GET http://localhost:3000/orders \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
{
  "orders": [
    {
      "_id": "65abc123def456789012345",
      "products": [
        {
          "product": {
            "_id": "507f1f77bcf86cd799439011",
            "name": "Gaming Mouse",
            "price": 49.99,
            "brand": "Logitech"
          },
          "quantity": 2,
          "customName": "Special Edition Mouse"
        },
        {
          "product": {
            "_id": "507f191e810c19729de860ea",
            "name": "Mechanical Keyboard",
            "price": 99.99,
            "brand": "Corsair"
          },
          "quantity": 1,
          "customName": null
        }
      ],
      "total": 199.97,
      "createdAt": "2024-01-15T10:30:00.000Z",
      "updatedAt": "2024-01-15T10:30:00.000Z"
    },
    {
      "_id": "65abc123def456789012346",
      "products": [
        {
          "product": {
            "_id": "507f191e810c19729de860eb",
            "name": "USB-C Cable",
            "price": 12.99,
            "brand": "Anker"
          },
          "quantity": 3,
          "customName": null
        }
      ],
      "total": 38.97,
      "createdAt": "2024-01-14T15:20:00.000Z",
      "updatedAt": "2024-01-14T15:20:00.000Z"
    }
  ]
}

Build docs developers (and LLMs) love