Skip to main content

Overview

This endpoint retrieves a specific order by its ID. The user must be authenticated and the order must belong to the authenticated user for the specified shop.

Endpoint

GET /api/v1/orders/:id

Authentication

This endpoint requires authentication. Include the user’s JWT token in the Authorization header.

Headers

HeaderRequiredDescription
AuthorizationYesBearer token for authentication
x-shop-idYesShop ID for context

Path Parameters

ParameterTypeRequiredDescription
idstringYesThe ID of the order to retrieve

Response

Success Response (200)

{
    "status": 200,
    "success": true,
    "message": "Order retrieved",
    "data": {
        "_id": "64a1b2c3d4e5f6789012345",
        "user": "64a1b2c3d4e5f6789012346",
        "shop": "64a1b2c3d4e5f6789012347",
        "status": "pending",
        "total": 2500000,
        "items": [
            {
                "product": "64a1b2c3d4e5f6789012348",
                "quantity": 1,
                "price": 2500000,
                "variant": "64a1b2c3d4e5f6789012349"
            }
        ],
        "shippingAddress": "64a1b2c3d4e5f678901234a",
        "paymentMethod": "card",
        "createdAt": "2023-07-01T12:00:00.000Z",
        "updatedAt": "2023-07-01T12:00:00.000Z"
    }
}

Error Responses

401 Unauthorized
{
    "status": 401,
    "success": false,
    "message": "Authentication required"
}
403 Forbidden
{
    "status": 403,
    "success": false,
    "message": "Access denied"
}
404 Not Found
{
    "status": 404,
    "success": false,
    "message": "Order not found"
}

Example

Request

curl -X GET \
  "http://localhost:7000/api/v1/orders/64a1b2c3d4e5f6789012345" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "x-shop-id: 64a1b2c3d4e5f6789012347"

Response

{
    "status": 200,
    "success": true,
    "message": "Order retrieved",
    "data": {
        "_id": "64a1b2c3d4e5f6789012345",
        "user": "64a1b2c3d4e5f6789012346",
        "shop": "64a1b2c3d4e5f6789012347",
        "status": "pending",
        "total": 2500000,
        "items": [
            {
                "product": "64a1b2c3d4e5f6789012348",
                "quantity": 1,
                "price": 2500000,
                "variant": "64a1b2c3d4e5f6789012349"
            }
        ],
        "shippingAddress": "64a1b2c3d4e5f678901234a",
        "paymentMethod": "card",
        "createdAt": "2023-07-01T12:00:00.000Z",
        "updatedAt": "2023-07-01T12:00:00.000Z"
    }
}