Skip to main content

Overview

The Orders API allows you to retrieve, update, and manage customer orders. Orders are automatically created after successful payment through the Checkout API.

Order Object

The Order object contains complete information about a customer’s purchase.
id
string
Unique identifier for the order (MongoDB ObjectId)
orderNumber
string
Human-readable order number (format: YYYY-MM-XXXX, e.g., “2024-03-0001”)
user
string
User ID who placed the order (MongoDB ObjectId)
products
array
Array of purchased products
totals
object
Order financial totals
status
string
Current order status
paymentStatus
string
Payment status
paymentMethod
string
Payment method used: credit_card, debit_card, pse, cash_on_delivery, or bank_transfer
paymentReference
string
Stripe payment intent or transaction ID
shippingAddress
object
Delivery address
shippingMethod
string
Shipping method: standard, express, overnight, or pickup
trackingNumber
string
Shipping carrier tracking number
shippingCarrier
string
Carrier name: servientrega, coordinadora, tcc, deprisa, or pickup
orderDate
string
ISO 8601 timestamp when order was created
estimatedDeliveryDate
string
ISO 8601 timestamp for estimated delivery
deliveredDate
string
ISO 8601 timestamp when order was delivered (null if not yet delivered)
statusHistory
array
Array of status change records

Get User Orders

Headers

Authorization
string
required
Bearer token: Bearer YOUR_JWT_TOKEN

Query Parameters

status
string
Filter by order status (e.g., pending, shipped, delivered)
page
integer
default:"1"
Page number for pagination
limit
integer
default:"10"
Number of orders per page
sortBy
string
default:"newest"
Sort order: newest (newest first) or oldest (oldest first)

Response

curl -X GET "https://api.fitaiid.com/api/orders?status=shipped&limit=5" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Get Order by ID

Path Parameters

id
string
required
Order ID or order number (MongoDB ObjectId or order number like “2024-03-0001”)

Response

curl -X GET https://api.fitaiid.com/api/orders/2024-03-0001 \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Update Order Status

This endpoint requires admin privileges. Status transitions are validated to prevent invalid state changes.

Path Parameters

id
string
required
Order ID (MongoDB ObjectId)

Body Parameters

status
string
required
New order status
note
string
Optional note about the status change (max 500 characters)
trackingNumber
string
Tracking number (required when changing status to shipped)
shippingCarrier
string
Carrier name (required when changing status to shipped)

Response

curl -X PUT https://api.fitaiid.com/api/orders/65f1234567890abcdef12345/status \
  -H "Authorization: Bearer ADMIN_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "status": "shipped",
    "note": "Pedido enviado con Servientrega",
    "trackingNumber": "SER123456789CO",
    "shippingCarrier": "servientrega"
  }'

Cancel Order

Orders can only be cancelled if they are in pending, confirmed, or processing status. Shipped or delivered orders cannot be cancelled.

Path Parameters

id
string
required
Order ID (MongoDB ObjectId)

Body Parameters

reason
string
Reason for cancellation (max 500 characters)

Response

curl -X POST https://api.fitaiid.com/api/orders/65f1234567890abcdef12345/cancel \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "reason": "Changed my mind about the purchase"
  }'

Track Order

Path Parameters

id
string
required
Order ID or order number

Response

curl -X GET https://api.fitaiid.com/api/orders/2024-03-0001/tracking \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Get Order Statistics

This endpoint requires admin privileges.

Query Parameters

dateFrom
string
Start date for statistics (ISO 8601 format)
dateTo
string
End date for statistics (ISO 8601 format)

Response

curl -X GET "https://api.fitaiid.com/api/orders/stats?dateFrom=2024-01-01&dateTo=2024-03-31" \
  -H "Authorization: Bearer ADMIN_JWT_TOKEN"

Error Responses

400 Bad Request
Invalid request parameters
401 Unauthorized
Missing or invalid authentication token
403 Forbidden
User does not have permission to access this order or requires admin privileges
404 Not Found
Order not found

Webhooks

Order Status Change Webhook

Configure webhooks to receive real-time notifications when order status changes. See the Webhooks documentation for setup instructions.

Webhook Payload Example

{
  "event": "order.status_changed",
  "timestamp": "2024-03-02T09:00:00.000Z",
  "data": {
    "orderId": "65f1234567890abcdef12345",
    "orderNumber": "2024-03-0001",
    "previousStatus": "processing",
    "newStatus": "shipped",
    "trackingNumber": "SER123456789CO",
    "user": {
      "id": "507f191e810c19729de860ea",
      "email": "[email protected]"
    }
  }
}

Build docs developers (and LLMs) love