API introduction
How to call the API
On this page
Every call is an ordinary HTTPS request to the store's address, with your key in a header. These examples use https://yourstore.example.com; use the address of the store you connect to. New here? The Quick start goes from nothing to a first call.
A read call#
List the first five products. The key needs the read:products scope.
curl -s "https://yourstore.example.com/api/v1/products?limit=5" \
-H "Authorization: Bearer YOUR_API_KEY"<?php
$ch = curl_init('https://yourstore.example.com/api/v1/products?limit=5');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_API_KEY',
],
]);
$response = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($status >= 400) {
// $response['error']['code'] and $response['error']['message'] say what to fix
}// Node.js 18 or newer (fetch is built in). Save as call.mjs and run: node call.mjs
const res = await fetch('https://yourstore.example.com/api/v1/products?limit=5', {
headers: {
Authorization: 'Bearer YOUR_API_KEY',
},
});
const json = await res.json();
if (!res.ok) {
// json.error.code and json.error.message say what to fix
}# Python 3 with the requests library (pip install requests)
import requests
res = requests.get(
"https://yourstore.example.com/api/v1/products?limit=5",
headers={"Authorization": "Bearer YOUR_API_KEY"},
timeout=30,
)
data = res.json()
if not res.ok:
# data["error"]["code"] and data["error"]["message"] say what to fix
print(data["error"])A write call#
Add an internal note to an order. The key needs the write:orders scope. Write calls carry an Idempotency-Key so a retry never does the work twice (see Requests).
curl -s -X POST "https://yourstore.example.com/api/v1/orders/GK-261008-7WNM/notes" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 6f1c0b3e-0d5a-4a52-9d5e-1f6c2a7b9e10" \
-d '{
"note": "Customer called to confirm the address."
}'<?php
$ch = curl_init('https://yourstore.example.com/api/v1/orders/GK-261008-7WNM/notes');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_API_KEY',
'Content-Type: application/json',
'Idempotency-Key: ' . bin2hex(random_bytes(16)),
],
CURLOPT_POSTFIELDS => json_encode([
'note' => 'Customer called to confirm the address.',
]),
]);
$response = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($status >= 400) {
// $response['error']['code'] and $response['error']['message'] say what to fix
}// Node.js 18 or newer (fetch is built in). Save as call.mjs and run: node call.mjs
import { randomUUID } from 'node:crypto';
const res = await fetch('https://yourstore.example.com/api/v1/orders/GK-261008-7WNM/notes', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
'Idempotency-Key': randomUUID(),
},
body: JSON.stringify({
note: 'Customer called to confirm the address.',
}),
});
const json = await res.json();
if (!res.ok) {
// json.error.code and json.error.message say what to fix
}# Python 3 with the requests library (pip install requests)
import uuid
import requests
res = requests.post(
"https://yourstore.example.com/api/v1/orders/GK-261008-7WNM/notes",
headers={"Authorization": "Bearer YOUR_API_KEY", "Idempotency-Key": str(uuid.uuid4())},
json={
"note": "Customer called to confirm the address.",
},
timeout=30,
)
data = res.json()
if not res.ok:
# data["error"]["code"] and data["error"]["message"] say what to fix
print(data["error"])Read the answer#
- A status of 200 or 201 means it worked. The JSON has a
datapart (what you asked for) and ametapart. - A status of 400 or more means it did not work. The JSON has an
errorpart with acode(short and stable, for your code to check) and amessage(in plain words, for people). A 422 also lists what to fix infields. - Always check the status before you use
data.
The full shape of answers and every error code are on Responses and errors.
If your first call fails#
| You see | What it usually means |
|---|---|
401 missing_api_key or invalid_api_key | The key was not sent in a header, or it was not copied completely. |
403 insufficient_scope | The key does not have the permission this call needs. error.required_scope names it. Add it to the key in the admin. |
403 ip_not_allowed | The key can only be used from certain internet addresses, and yours is not one of them. |
404 not_found | The address is wrong (check the path and that it starts with /api/v1), or that product, order or size does not exist. |
429 rate_limited | Too many requests in a minute. Wait the seconds in the Retry-After header. |
503 service_busy | The store could not reach its database for a moment. Wait the seconds in the Retry-After header and send the same request again. |
Tools#
You can try calls without writing code. Import the Postman collection or the OpenAPI file into Postman or any other API tool, and set your store address and your key.