v2 is generally available. See what changed
Skip to content
Acme Commerce API Menu

Create an order

POST /api/v1/orders Requires authentication 10 requests per minute Deprecated v1

Send a bearer token in the Authorization header.

A newer version of this operation is available: POST /api/v2/orders.

Creates an order in pending state. A retried request creates a second order; v2 accepts an Idempotency-Key header that makes the retry safe.

Full URL: https://api.acme.example/api/v1/orders

Body parameters

Name Type Required Description
customer_id integer yes Who the order is for.
currency string, one of USD, EUR, GBP yes
items array yes At least one line item.
items[].product_id integer no
items[].quantity integer no

Responses

201 The created order.

422 Validation failed.

429 Too many orders created. Back off and retry after the interval in the Retry-After header.

Example request

cURL
curl -X POST 'https://api.acme.example/api/v1/orders' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "customer_id": 1,
    "currency": "USD",
    "items": [
        {
            "product_id": 1,
            "quantity": 2
        }
    ]
}'
JavaScript
const response = await fetch('https://api.acme.example/api/v1/orders', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "customer_id": 1,
      "currency": "USD",
      "items": [
          {
              "product_id": 1,
              "quantity": 2
          }
      ]
  })
});

const data = await response.json();
PHP (Laravel)
use Illuminate\Support\Facades\Http;

$response = Http::withHeaders([
    'Authorization' => 'Bearer YOUR_TOKEN',
    'Accept' => 'application/json',
    'Content-Type' => 'application/json',
])->post('https://api.acme.example/api/v1/orders', [
    'customer_id' => 1,
    'currency' => 'USD',
    'items' => [
        [
            'product_id' => 1,
            'quantity' => 2,
        ],
    ],
]);

$data = $response->json();
PHP (Guzzle)
use GuzzleHttp\Client;

$client = new Client();

$response = $client->request('POST', 'https://api.acme.example/api/v1/orders', [
    'headers' => [
        'Authorization' => 'Bearer YOUR_TOKEN',
        'Accept' => 'application/json',
        'Content-Type' => 'application/json',
    ],
    'json' => [
        'customer_id' => 1,
        'currency' => 'USD',
        'items' => [
            [
                'product_id' => 1,
                'quantity' => 2,
            ],
        ],
    ],
]);

$data = json_decode((string) $response->getBody(), true);

Example response

201
{
    "id": 8802,
    "status": "pending",
    "total": 3998,
    "currency": "USD",
    "items": [
        {
            "product_id": 12,
            "quantity": 2,
            "unit_price": 1999
        }
    ]
}

Free while you are building.

Get an API key

This page as Markdown, or the whole API as OpenAPI. Ask ChatGPT Ask Claude