GET /api/orders
Retrieves all orders for the authenticated user with pagination, filtering, and statistics.
Authentication
Requires JWT authentication token in the Authorization header.
Query Parameters
Filter by order status. Valid values: pending, completed, failed, cancelled, refunded
Number of orders per page (default: 10)
Page number for pagination (default: 1)
Response
Indicates if the request was successful
Array of order objects sorted by creation date (newest first)Human-readable order ID (format: #TRX-)
Array of ordered products with details
Sum of all product prices
Blockchain transaction hash (if payment submitted)
Merchant’s wallet address
ISO 8601 timestamp of order creation
ISO 8601 timestamp of last update
Order statistics for the userNumber of completed orders
Number of refunded orders
Number of cancelled orders
Pagination metadataTotal number of orders matching the filter
Example Request
# Get all orders
curl -X GET https://api.cryptoshop.com/api/orders \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
# Get pending orders only
curl -X GET "https://api.cryptoshop.com/api/orders?status=pending" \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
# Get page 2 with 20 orders per page
curl -X GET "https://api.cryptoshop.com/api/orders?limit=20&page=2" \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
Example Response
{
"success": true,
"orders": [
{
"_id": "507f1f77bcf86cd799439011",
"orderId": "#TRX-5",
"userId": "507f191e810c19729de860ea",
"products": [
{
"productId": "507f1f77bcf86cd799439011",
"name": "iPhone 14 Pro",
"price": 999,
"quantity": 1,
"color": "black"
}
],
"subtotal": 999,
"networkFee": -0.01,
"total": 998.99,
"status": "completed",
"transactionHash": "0x1234567890abcdef",
"walletAddress": "TUserWalletAddress123",
"merchantAddress": "TMerchantWalletAddress456",
"createdAt": "2026-03-04T10:30:00.000Z",
"updatedAt": "2026-03-04T10:35:00.000Z"
},
{
"_id": "507f1f77bcf86cd799439012",
"orderId": "#TRX-4",
"userId": "507f191e810c19729de860ea",
"products": [
{
"productId": "507f191e810c19729de860eb",
"name": "AirPods Pro",
"price": 249,
"quantity": 2,
"color": null
}
],
"subtotal": 498,
"networkFee": -0.01,
"total": 497.99,
"status": "pending",
"transactionHash": null,
"walletAddress": "TUserWalletAddress123",
"merchantAddress": "TMerchantWalletAddress456",
"createdAt": "2026-03-03T14:20:00.000Z",
"updatedAt": "2026-03-03T14:20:00.000Z"
}
],
"stats": {
"total": 12,
"pending": 1,
"completed": 8,
"refunded": 1,
"failed": 2,
"cancelled": 0
},
"pagination": {
"total": 12,
"page": 1,
"pages": 2
}
}
Error Responses
500 Internal Server Error
{
"error": "Database connection error"
}
Important Notes
- Orders are returned sorted by creation date (newest first)
- Statistics include counts for all order statuses, regardless of the status filter
- Only the authenticated user’s orders are returned
- Pagination is zero-indexed internally but page numbers start from 1 in the API