API

The shop’s JSON API: a public storefront half with a cart and checkout, an admin half behind a token. A briefing for developers and AI agents.

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
Accesspublic, no key — like the shop’s HTML pagestoken, Authorization: Bearer tg_…
What you seewhat a visitor sees: listed products, storefront prices, no cost priceseverything the shop knows: hidden and disabled rows, cost prices, customers
Writesonly the cart (by its own token) and placing an orderpartial 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

  1. 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").
  2. A row is addressed by any of its keys: /products/4, /products/ST-2002 and /products/1c-42 are one product. You never need to store our ids. A key made only of digits is tried as an id first.
  3. PATCH is partial: only what it names changes. Only the fields in a resource’s writable list are written; anything else is silently skipped.
  4. 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).
  5. 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 against openapi.json.
  6. Sync with updated_after (ISO 8601), not by pulling everything.
  7. Answers are enveloped: {"data": …}; a list is {"data": [...], "meta": {"page", "itemsPerPage", "total", "pages"}}; an error is {"message": …, "errors": {field: [text]}}.
  8. Storefront and language come from headers: X-Storefront: <code or id> and Accept-Language: en. Without them — the default storefront and its language.
  9. Checkout is a conversation with the cart: answers PATCHed are merged with the earlier ones, GET shows delivery and payment for them, complete recomputes everything itself and trusts nothing.
  10. Online payment happens only on the gateway’s page (payment.url in complete’s answer): open it in a browser or a web view.

Pages of this section

  • 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.