Every Torgash shop has a JSON API. An accounting system syncs stock and prices
through it, a CRM pulls orders and enquiries, a mobile app shows the catalogue
and places orders, and an AI agent does any of that on behalf of the shop or of
a customer. The API is the API module (torgash.api), part of the default
set.
Two halves
/api/v2/shop/… — storefront | /api/v2/admin/… — admin | |
|---|---|---|
| Access | public, no key — like the shop’s HTML pages | token, Authorization: Bearer tg_… |
| What you see | what a visitor sees: listed products, storefront prices, no cost prices | everything the shop knows: hidden and disabled rows, cost prices, customers |
| Writes | only the cart (by its own token) and placing an order | partial PATCH, creation where allowed, and named actions |
| Rights | — | the rights of the account that issued the token — the admin panel’s own |
Both halves are rate-limited (by default 120 requests a minute per token; without a token, per IP address).
Quick start in five calls
The catalogue, no key:
curl -s 'https://shop.example/api/v2/shop/products?q=laptop' \
-H 'Accept: application/json' -H 'Accept-Language: en'
A cart and an order:
# 1. A cart — keep the token from the answer
curl -s -X POST https://shop.example/api/v2/shop/carts
# 2. Put a product in (our id, the sku or your external id)
curl -s -X PATCH https://shop.example/api/v2/shop/carts/$TOKEN/items \
-H 'Content-Type: application/json' -d '{"product": "ST-2002", "quantity": 1}'
# 3. Answer the checkout's questions (in parts if you like)
curl -s -X PATCH https://shop.example/api/v2/shop/carts/$TOKEN/checkout \
-H 'Content-Type: application/json' \
-d '{"customer_name": "Ivan", "email": "ivan@example.com", "phone": "+380675550128",
"country": "UA", "city": "Kyiv", "place_id": 14008, "address_line": "1 Example St"}'
# 4. Read the delivery and payment on offer for those answers, pick
curl -s https://shop.example/api/v2/shop/carts/$TOKEN/checkout
curl -s -X PATCH https://shop.example/api/v2/shop/carts/$TOKEN/checkout \
-H 'Content-Type: application/json' -d '{"shipping_method_id": "1", "payment_method_id": 2}'
# 5. Place it
curl -s -X POST https://shop.example/api/v2/shop/carts/$TOKEN/checkout/complete
The admin half, with a token:
curl -s 'https://shop.example/api/v2/admin/orders?updated_after=2026-11-01T00:00:00Z' \
-H "Authorization: Bearer $TG_TOKEN" -H 'Accept: application/json'
Briefing: the rules you must not skip
- Money is a decimal string in major units, with a dot (
"1999.00"), and the currency is always named beside it (currency). It is written to the API in exactly the same format. Amounts (totals, delivery, payments) have two places; a price per unit has as many as the shop keeps (2–4:"0.0120"). - A row is addressed by any of its keys:
/products/4,/products/ST-2002and/products/1c-42are one product. You never need to store our ids. A key made only of digits is tried as an id first. PATCHis partial: only what it names changes. Only the fields in a resource’swritablelist are written; anything else is silently skipped.- State moves by an action, never by writing a column: an order’s status
is
POST /admin/orders/{key}/actions/status. An action runs the same code as the admin button (stock, history, emails). - Lists:
?page=,?itemsPerPage=(ceiling 200; more is quietly capped),?order[field]=asc|desc, filters by name. An unknown parameter is silently ignored — check the spelling againstopenapi.json. - Sync with
updated_after(ISO 8601), not by pulling everything. - Answers are enveloped:
{"data": …}; a list is{"data": [...], "meta": {"page", "itemsPerPage", "total", "pages"}}; an error is{"message": …, "errors": {field: [text]}}. - Storefront and language come from headers:
X-Storefront: <code or id>andAccept-Language: en. Without them — the default storefront and its language. - Checkout is a conversation with the cart: answers
PATCHed are merged with the earlier ones,GETshows delivery and payment for them,completerecomputes everything itself and trusts nothing. - Online payment happens only on the gateway’s page (
payment.urlincomplete’s answer): open it in a browser or a web view.
Pages of this section
- Basics — tokens, headers, keys, lists, errors, limits, money, languages and dates.
- Storefront catalogue — products, categories, search, localities, gift card balance.
- Cart and checkout — placing an order end to end, with the server’s answers.
- Products and categories — reading and writing the catalogue from an accounting system.
- Orders and returns — orders, payment, statuses, returns and exchanges.
- Enquiries, reviews, marketing — enquiries, comments, reviews, gift cards, points, promotions, pages.
- Integration recipes — ready sequences of calls for common jobs.
- A resource of your own — how a module exposes its data through the API.
- Basics — Addresses, tokens and rights, headers, row keys, lists, writes, errors, limits, money, languages and dates.
- Storefront catalogue — Public products and categories, search, localities for delivery, a gift card's balance — no key needed.
- Cart and checkout — A cart addressed by its token, and checkout as a conversation with it: address, delivery, payment, coupon, gift card, paying on the gateway's page.
- Products and categories — The catalogue as an accounting system sees it: reading every product, writing stock, prices, statuses, categories, variations and SEO.
- Orders and returns — Pulling orders into a CRM or the books, moving a status by an action, payment as a separate axis, returns and exchanges.
- Enquiries, reviews, marketing — Enquiries and answering them, comments and reviews with moderation, gift cards, bonus points, promotions and pages.
- Integration recipes — Ready sequences of calls: stock and prices from an accounting system, orders into a CRM, a support agent, a sales agent, moderation.
- A resource of your own — How a module exposes its data through the API: registering a resource, describing fields for openapi.json, actions, creation, addresses of its own and hooks.