Using the API
Every call carries a token and says which resource it means. There is one URL shape for everything:
GET /api/v2/admin/{resource}
GET /api/v2/admin/{resource}/{key}
PATCH /api/v2/admin/{resource}/{key}
POST /api/v2/admin/{resource}/{key}/actions/{action}
Admin → API reference is the live list: every endpoint that exists on this shop, its filters, what it answers with, and a Send button that fires the call from the page. The same thing machine-readable is at
GET /api/v2/openapi.json
— OpenAPI 3.1, public (a client generating a stub does not have a token yet), and generated from what the modules declared rather than kept beside it. Feed it to Postman, to a code generator, or to whoever is writing the other end.
Authentication
Issue a token in the admin panel and send it on every call:
Authorization: Bearer tg_...
The token belongs to the account that issued it and can never do more than that account may. It is also narrowed when issued: one resource at a time, read or write — the price feed’s key reads products and nothing else, the CRM’s key reads orders and cannot touch the catalogue, the 1C exchange has a door of its own. A call outside the key’s rooms is a 403 that names the resource. “Write” carries “read” of the same resource. The plaintext is shown once, at issue: the database keeps only a hash, so a stolen dump cannot be replayed. A call with a token the shop did not issue counts against the caller’s address.
Addressing a row
By our id, or by any key the resource declares — for a product that is
external_id, sku and slug. These are the same product:
/api/v2/admin/products/4
/api/v2/admin/products/ST-2002
/api/v2/admin/products/1c-42
That is the point of external_id: an exchange stores its own id and never has
to keep ours.
Lists
?page=2&itemsPerPage=50
?order[sku]=desc
?updated_after=2026-09-01T00:00:00Z
?status=active
Asking for more items than the shop allows gets the ceiling, not an error.
updated_after is the filter an exchange should be built on: pulling the whole
catalogue every night is how an integration ends up switched off.
The answer is always the same shape:
{"data": [...], "meta": {"page": 1, "itemsPerPage": 30, "total": 412, "pages": 14}}
Writing
A PATCH changes what it names and nothing else — sending a stock level does
not risk the name, the price or the description. Each resource decides what an
exchange may write; for products that is stock, status, prices, sku and
external_id, and not the slug, the categories or the photos.
Prices are sent in major units, and may name their own currency:
PATCH /api/v2/admin/products/1c-42 {"price": 42000, "price_currency": "UAH"}
They are stored exactly as the admin form would store them: the typed number kept, the shop’s own price derived from it (see the catalogue’s docs on pricing in another currency).
Changing an order
Not by writing the status column — by asking for the transition:
POST /api/v2/admin/orders/TG-000123/actions/status {"status": "complete"}
This runs the same code the admin panel’s own select runs: the stock moves, the
change is logged, the customer’s email goes out. A PATCH setting status
would have looked like it worked and done none of it.
The money is a second axis with a door of its own — the payment control on the order’s page:
POST /api/v2/admin/orders/TG-000123/actions/payment {"state": "paid"}
POST /api/v2/admin/orders/TG-000123/actions/payment {"state": "partially_paid", "paid_total": "1500.00"}
POST /api/v2/admin/orders/TG-000123/actions/payment {"state": "pending"}
paid when the money arrived; pending takes a payment back off an order
marked paid by mistake; refunded says the money was returned outside any
gateway. paid_total is everything the order now holds, a gift card included;
left out, it is all of it. The order’s history names the token that said so.
Sending what the order already says changes nothing and logs nothing, so a CRM
may send its whole state as often as it likes.
Storefront and language
X-Storefront: main (id or code; the default storefront otherwise)
Accept-Language: ru
Prices, currencies and translations follow those two headers. A storefront that is switched off or does not exist is the same as not sending the header.
The shop half
/api/v2/shop/... is public, exactly as the storefront’s own pages are:
GET /api/v2/shop/products?q=ноутбук&category=laptops
GET /api/v2/shop/products/ST-2002
GET /api/v2/shop/categories
It answers with what a visitor may see — listed products, prices through the same display filter the page uses, no cost prices — and it cannot write: only GET is routed there.
The cart
POST /api/v2/shop/carts → { "token": "..." }
GET /api/v2/shop/carts/{token}
PATCH /api/v2/shop/carts/{token}/items { "product": "ST-2002", "quantity": 2 }
DELETE /api/v2/shop/carts/{token}
The token IS the authorisation: keep it, and it is your cart. An unknown token is a 404 — the API does not say whether a cart exists to somebody who was not given its address.
One call sets a quantity, and 0 removes the line: “how many of this do you
want” is one question. The product is named by id, sku or external id, like
everywhere else.
Every amount is in minor units of the shop’s books; currency in the answer
says what the visitor’s prices are displayed in.
Checking out
A browser answers every checkout question on one page and submits once. A client cannot: it has to give an address before it can be told what delivery costs, and choose a delivery before it knows the total. So checkout is a conversation with the cart — each answer is kept on it, and the client can stop and come back.
GET /api/v2/shop/carts/{token}/checkout
PATCH /api/v2/shop/carts/{token}/checkout { "city": "Київ", "place_id": 703448 }
POST /api/v2/shop/carts/{token}/checkout/complete
A PATCH is MERGED onto the answers already given, so a step that picks a
delivery does not unanswer the address. Sending a field as null erases it.
Nothing is validated against what is on offer yet: an address typed one field at
a time is briefly nonsense, and refusing it would make a form impossible to
build.
The GET answers with the state of the checkout for the answers so far:
{
"answers": { … what has been given … },
"delivery": [ { "id": "3", "label": "Courier delivery", "cost": 5000,
"delivery_time": "1–2 days", "needs_address": true,
"needs_fields": false, "meta": {} } ],
"payment": [ { "id": 2, "label": "Card online", "charged_in": "UAH" } ],
"currency": "USD", "subtotal": 4000, "discount": 0
}
The delivery options are priced for the address given so far — that is why the
address is the first question. A cost of null means a carrier answered but
named no price: the shop will quote it by hand, and a client must not print
“free”. needs_fields says the option wants something more from the customer (a
branch to collect from); charged_in is the currency a payment method will ask
the bank for when it cannot take the one being shopped in.
complete places the order. Everything is re-derived from the stored answers
and nothing is trusted from the client, so a delivery option with no rate in the
winning zone cannot be bought however the cart was PATCHed. An incomplete
checkout comes back as a 422 naming the fields:
{ "message": "The checkout is not complete.",
"errors": { "email": ["The email field is required."] } }
A shop that confirms a customer’s contact with a code at checkout answers the
same 422, naming that field: a code is proved in a browser and the API has no
way of asking for one, so such a shop takes these orders only on its site.
A placed one comes back as a 201:
{ "data": { "order": { "number": "TG-000123", "status": "awaiting_payment",
"total": 4500, "currency": "UAH",
"payment": { "state": "unpaid", "currency": "UAH",
"amount": 4500, "url": "https://…" } } } }
payment.url is where a browser would have been redirected — a gateway’s own
page. Open it in a web view and come back; there is no way to take a card
without one. It is null when the method takes no money online.
The order is placed by the same object the storefront’s own form goes through, which is why stock, statuses, currencies, taxes, automations and the confirmation email all behave identically here. The cart is emptied, not deleted: its token still points at it.
Putting a module on the API
A module does not write a controller, a route or a page of documentation. It registers what it has, and everything else — paging, sorting, permissions, error shapes, the reference page and the OpenAPI document — is applied to it from one place.
Answer the api.resources hook and register:
ApiResources::register('admin.widgets', [
'label' => 'Widgets', // English; the Russian goes in the module's lang/ru.json
'permission' => 'widgets.manage',
'query' => fn () => Widget::query(),
'serialize' => fn (Widget $w) => ['id' => $w->id, 'sku' => $w->sku],
'sortable' => ['id', 'sku', 'created_at'],
'lookup' => ['external_id', 'sku'],
'filters' => ['status' => fn ($q, $v) => $q->where('status', $v)],
'update' => fn (Widget $w, array $data) => $w->update(...), // omit for read-only
]);
The name is SECTIONED. admin.widgets is served at /api/v2/admin/widgets and
needs a token; shop.widgets is served at /api/v2/shop/widgets, is public and
is read-only however it is registered — only GET is routed there. Register both
when the shop should see a narrower version of the same table; do not register
one resource that hides fields conditionally, because that is how a cost price
eventually reaches a storefront.
lookup is the part worth naming: /widgets/1c-42 and /widgets/W-7 and
/widgets/4 all find the same row, so an integration never has to store our
autoincrements.
Saying what it means
Four keys are read by nothing at runtime. They are what the reference page and
openapi.json are written from, and they live here rather than in a document of
their own — a description kept somewhere else is a description that is wrong
within a month, usually about the field somebody added on a Friday.
'description' => 'What this resource is, in a sentence or two.',
'schema' => [ // what `serialize` answers with
'id' => 'integer',
'price' => ['type' => 'integer', 'description' => 'Minor units of `currency`.'],
'stock' => 'integer|null',
'lines' => ['type' => 'array', 'of' => ['sku' => 'string', 'qty' => 'integer']],
],
'writable' => [ // what a PATCH may carry
'stock' => 'integer',
'status' => ['type' => 'string', 'enum' => ['active', 'hidden']],
],
A field is a bare type string or an array with type, description, example,
enum, format and of (the fields of an object, or of each item of an
array). Declare nothing and the page says so — an open object — rather than
inventing a list of fields.
Descriptions are English strings like every declared word; the reference translates them through the module’s lang files where a translation exists.
A filter or an action can carry prose the same way, as a closure or as a closure with a sentence beside it:
'filters' => [
'updated_after' => [
'description' => 'Everything touched since a moment (ISO 8601).',
'example' => '2026-09-01T00:00:00+03:00',
'apply' => fn ($q, $v) => $q->where('updated_at', '>=', $v),
],
],
Transitions, not state writes
Anything that is a decision gets an action, never a writable column:
'actions' => [
'status' => [
'description' => 'Move it, running the shop’s own code.',
'body' => ['status' => ['type' => 'string', 'example' => 'complete']],
'apply' => fn (Widget $w, array $data) => app(WidgetMover::class)->move($w, $data['status']),
],
],
POST /widgets/{key}/actions/status runs your code; a PATCH setting the
column would have looked like it worked and moved no stock, logged nothing and
sent no email.
An endpoint that is not a resource
Some things are not a table with a serialiser — the cart and the checkout are
the worked examples. Register the routes yourself and describe them through the
api.openapi.paths hook, which hands you the paths and takes them back:
hook_listen('api.openapi.paths', fn (array $paths) => $paths + [
'/pay/acme/callback' => ['post' => [
'tags' => ['Shop · Payments'],
'summary' => 'Acme’s callback',
'security' => [],
'responses' => ['200' => ['description' => 'Recorded.']],
]],
]);