Skip to main content

Order Service โ€“ API Reference ๐Ÿงพ

This document describes the customer and admin APIs exposed by the Order Service in ShopVerse.

All APIs are accessed via the API Gateway.
Authorization is enforced using gateway-injected headers.


๐ŸŒ Base URLโ€‹


/api/orders


๐Ÿ” Authentication & Authorizationโ€‹

  • JWT is validated at the API Gateway
  • Gateway injects:
    • X-User-Email
    • X-User-Role
  • Customers can access only their own orders
  • Admins can access all orders

๐Ÿ›’ Place Order (Customer)โ€‹

Create a new order for the authenticated user.

โžค Endpointโ€‹


POST /api/orders

โžค Request Bodyโ€‹

{
"items": [
{
"productId": "PROD123",
"quantity": 2
},
{
"productId": "PROD456",
"quantity": 1
}
]
}

โžค Success Response (201 CREATED)โ€‹

{
"orderId": "ORD789",
"status": "CREATED",
"totalAmount": 5497
}

โžค Error Responsesโ€‹

StatusReason
400Invalid request / insufficient stock
401Unauthorized
500Internal server error

๐Ÿ“„ Get Order by ID (Customer / Admin)โ€‹

Fetch order details by order ID.

โžค Endpointโ€‹

GET /api/orders/{orderId}

โžค Access Rulesโ€‹

  • CUSTOMER โ†’ only own orders
  • ADMIN โ†’ any order

โžค Success Response (200 OK)โ€‹

{
"orderId": "ORD789",
"customerId": "user@example.com",
"status": "CREATED",
"orderDate": "2026-01-21T12:30:00",
"totalAmount": 5497,
"items": [
{
"productId": "PROD123",
"quantity": 2,
"price": 2499
}
]
}

๐Ÿ“ฆ Get My Orders (Customer)โ€‹

Fetch all orders placed by the authenticated user.

โžค Endpointโ€‹

GET /api/orders/my

โžค Success Response (200 OK)โ€‹

[
{
"orderId": "ORD789",
"status": "CREATED",
"totalAmount": 5497,
"orderDate": "2026-01-21T12:30:00"
}
]

๐Ÿ‘‘ Get All Orders (Admin)โ€‹

Fetch all orders in the system.

โžค Endpointโ€‹

GET /api/orders

โžค Role Requiredโ€‹

ADMIN

โžค Success Response (200 OK)โ€‹

[
{
"orderId": "ORD789",
"customerId": "user@example.com",
"status": "CONFIRMED",
"totalAmount": 5497
}
]

๐Ÿ”„ Update Order Status (Admin)โ€‹

Update the status of an order.

โžค Endpointโ€‹

PUT /api/orders/{orderId}/status

โžค Role Requiredโ€‹

ADMIN

โžค Request Bodyโ€‹

{
"status": "CONFIRMED"
}

โžค Allowed Status Transitionsโ€‹

CREATED โ†’ CONFIRMED
CONFIRMED โ†’ CANCELLED

โžค Success Response (200 OK)โ€‹

{
"message": "Order status updated successfully"
}

๐Ÿ” Order Lifecycleโ€‹


๐Ÿ“ก Events Publishedโ€‹

EventTopicDescription
ORDER_PLACEDorder-eventsNew order created
ORDER_STATUS_UPDATEDorder-eventsOrder status changed

Consumed by:

  • Notification Service
  • Analytics Service
  • Recommendation Service

๐Ÿ”„ Request Flowโ€‹


โš ๏ธ Common Errorsโ€‹

StatusMeaning
400Invalid order / stock issue
401Unauthorized
403Forbidden
404Order not found
409Invalid status transition

๐Ÿ“Œ Summaryโ€‹

The Order API provides:

  • Secure order creation
  • Ownership-based access
  • Admin-controlled order lifecycle
  • Event-driven extensibility

It acts as the transactional core of ShopVerse.