Skip to main content

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

status
string
Filter by order status. Valid values: pending, completed, failed, cancelled, refunded
limit
number
default:"10"
Number of orders per page (default: 10)
page
number
default:"1"
Page number for pagination (default: 1)

Response

success
boolean
Indicates if the request was successful
orders
array
Array of order objects sorted by creation date (newest first)
_id
string
Order MongoDB ObjectId
orderId
string
Human-readable order ID (format: #TRX-)
userId
string
User MongoDB ObjectId
products
array
Array of ordered products with details
subtotal
number
Sum of all product prices
networkFee
number
TRC-20 network fee
total
number
Total amount
status
string
Current order status
transactionHash
string
Blockchain transaction hash (if payment submitted)
walletAddress
string
User’s wallet address
merchantAddress
string
Merchant’s wallet address
createdAt
string
ISO 8601 timestamp of order creation
updatedAt
string
ISO 8601 timestamp of last update
stats
object
Order statistics for the user
total
number
Total number of orders
pending
number
Number of pending orders
completed
number
Number of completed orders
refunded
number
Number of refunded orders
failed
number
Number of failed orders
cancelled
number
Number of cancelled orders
pagination
object
Pagination metadata
total
number
Total number of orders matching the filter
page
number
Current page number
pages
number
Total number of pages

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

Build docs developers (and LLMs) love