POST /api/v1/orders/checkout • HTTP 400 Bad Request

HTTP 400 Bad Request Error API Example — Request & Response Example

Demonstrates what happens when a client sends invalid JSON syntax or unparseable payload parameters.

1. HTTP Client Request (POST)

POST /api/v1/orders/checkout HTTP/1.1
{
  "Content-Type": "application/json"
}

{
  "cart_items": [],
  "payment_method_id": null
}

2. Server JSON Response (HTTP 400 Bad Request)

{
  "error": "Bad Request",
  "code": "CART_EMPTY_OR_INVALID",
  "message": "Cannot process checkout: cart_items must contain at least one item.",
  "timestamp": "2026-10-06T13:05:00Z"
}

Copy-Paste Code Snippets (cURL, JavaScript Fetch, Python, Node.js)

curl -X POST "https://cometflow.space/api/v1/orders/checkout" \
  -H "Content-Type: application/json" \
  -d '{"cart_items": []}'
fetch('https://cometflow.space/api/v1/orders/checkout', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ cart_items: [] })
}).then(async res => {
  if (!res.ok) {
    const error = await res.json();
    console.error('API Error (400):', error.message);
  }
});
import requests

res = requests.post("https://cometflow.space/api/v1/orders/checkout", json={"cart_items": []})
print(res.status_code) # 400
print(res.json())

How This API Call Works Step-by-Step

  1. 1. Client submits checkout request with empty cart.
  2. 2. Business validation rejects empty payload.
  3. 3. Server halts execution before running payment gateway.
  4. 4. Returns 400 Bad Request with actionable machine-readable error code.

Backend API Functions: The API validation function checks if (!req.body.cart_items?.length) return res.status(400).json({ code: "CART_EMPTY_OR_INVALID" }).

Frequently Asked Questions

When should an API return 400 vs 422?

Return 400 Bad Request when the request itself is malformed or violates core preconditions. Return 422 Unprocessable Entity when the syntax is valid JSON but specific fields fail schema validation (e.g. invalid email format).