Integration recipes

Ready sequences of calls: stock and prices from an accounting system, orders into a CRM, a support agent, a sales agent, moderation.

Each recipe is an order of calls and what must not be missed. In every example $SHOP is the shop’s address (https://shop.example) and $TG_TOKEN a token from Data exchange → API tokens.

Stock and prices from an accounting system

Token: read + write, an owner with catalog.manage.

  1. Once — link the products. Write your id onto each product:

    curl -s -X PATCH "$SHOP/api/v2/admin/products/ST-1001" \
         -H "Authorization: Bearer $TG_TOKEN" -H 'Content-Type: application/json' \
         -d '{"external_id": "1c-42"}'
    

    For thousands of products a file import with an external_id column is faster (Data exchange → Import). Categories get their external_id there too.

  2. Regularly — send only the changes:

    curl -s -X PATCH "$SHOP/api/v2/admin/products/1c-42" \
         -H "Authorization: Bearer $TG_TOKEN" -H 'Content-Type: application/json' \
         -d '{"stock": 7, "price": "1249.00", "cost_price": "910.00"}'
    
    • Prices are in major units. If your system keeps prices in another currency, add "price_currency": "EUR": the shop converts by the rate itself, and again on every change of it.
    • Out of stock — stock: 0. Taken off sale — "availability_status": "discontinued" or "status": "hidden".
    • 404 — the shop has no product with that external_id: create it in the admin or by import; the API does not create products.
  3. Pull the shop’s own changes (managers’ edits, say):

    curl -s -g "$SHOP/api/v2/admin/products?updated_after=2026-11-01T03:00:00%2B02:00&order[updated_at]=asc&itemsPerPage=200" \
         -H "Authorization: Bearer $TG_TOKEN"
    

    Remember the updated_at of the last row you got and start the next request from it (encode the offset’s + as %2B). The filter includes its boundary (>=), so the last row comes once more — that is expected.

Mind the limit (120 requests a minute by default): on 429 wait Retry-After seconds. 5,000 products one by one is ~42 minutes; send only what changed.

Orders into a CRM or the books

Token: read (+ write if the CRM moves statuses), orders.manage.

  1. Pull new and changed orders:

    curl -s -g "$SHOP/api/v2/admin/orders?updated_after=$LAST&order[updated_at]=asc&itemsPerPage=100" \
         -H "Authorization: Bearer $TG_TOKEN"
    

    Walk the pages while meta.page < meta.pages; keep the last order’s updated_at as the next $LAST. An order you have seen comes again on any change (status, payment) — update it on your side by id or number.

  2. Write your own id onto the order to address it by later: PATCH /admin/orders/TG-000123 {"external_id": "CRM-58812"}.

  3. Move the status from the CRM — only by the action: POST /admin/orders/CRM-58812/actions/status {"status": "shipped"}. The shop writes stock off or puts it back and tells the customer itself.

  4. Payment — read payment.state and payment.paid_total, not the status: it is a separate axis. An order is paid when payment.state is paid.

customer_ref on enquiries and customer.email / customer.user_id on orders help tie one person’s orders and enquiries together.

A support agent

Token: read + write, issued as a staff member of its own with enquiries.manage (and orders.manage if the agent answers about orders — remember that such a token can then move order statuses too). The agent’s acts show in the audit log under that account’s name.

  1. The queue: GET /admin/enquiries?awaiting_reply=1&order[created_at]=asc.
  2. For each enquiry read answers (what was asked), messages (the conversation), subject (which product or order), locale (which language to answer in).
  3. Context:
    • a product — GET /admin/products/{subject.id} (stock, price) or the storefront’s GET /shop/products/{id} (as the customer sees it);
    • an order — GET /admin/orders?email={email}.
  4. If can_be_answered is false the answer will not arrive (they left only a phone): assign a manager with PATCH {"manager_id": 3, "status": "in_progress"} and leave a note in notes so a person calls back.
  5. Otherwise answer: POST /admin/enquiries/{id}/actions/reply {"body": "…"} — plain text in the locale language. The customer’s email goes out by itself.
  6. Settled — PATCH {"status": "done"}; to lock the conversation — POST …/actions/close.

A sales agent (on a customer’s behalf)

No key — the storefront half only. Send Accept-Language in the customer’s language and X-Storefront if there are several storefronts.

  1. Find the product: GET /shop/products?q=<what the customer asked>. Narrow it down by characteristics (compare code and value_code), check in_stock. The category tree — GET /shop/categories, a category’s products — ?category={slug}.
  2. The cart: POST /shop/carts → keep the token; PATCH /shop/carts/{token}/items {"product": "<sku>", "quantity": 1}. A 422 with errors.product — not that many in stock, offer fewer.
  3. The town: GET /places/suggest?q=<town> → when there are several, ask again showing label and context.
  4. Checkout answers: PATCH /shop/carts/{token}/checkout with customer_name, phone (with the country code), email, country, city, place_id, address_line.
  5. Delivery and payment: the answer has delivery[] and payment[]. Tell the customer the options with prices (cost: null — “the shop will quote it”, not “free”). Choose with PATCH {"shipping_method_id": "…", "payment_method_id": …}; if an option has needs_fields: true, it needs shipping_fields too.
  6. The total: before placing, tell the customer total and to_pay from the answer and get an explicit yes.
  7. Place: POST /shop/carts/{token}/checkout/complete. 422 — errors lists what is missing: ask for it and try again. 201 — tell them the order number (number); if there is a payment.url, give the customer the link to pay.

Moderating reviews and comments

Permission reviews.moderate / comments.moderate.

  1. GET /admin/reviews?status=pending&only=reviews&order[created_at]=asc.
  2. Publish — PATCH {"status": "published"}, reject — PATCH {"status": "rejected", "moderation_note": "advertising"}. The product’s average follows by itself.
  3. Answer in public — POST /admin/reviews/{id}/actions/reply {"body": "…"} (this publishes the review).
  4. Comments — GET /admin/comments?status=pending, then PATCH {"status": "approved"} or "rejected".

A gift card for a review or a campaign

  1. POST /admin/giftcards {"amount": "200.00", "recipient_email": "…", "recipient_name": "…", "message": "Thank you for the review!"} — the letter goes at once.
  2. Save code from the answer if your system needs it: the API will not show it again.
  3. Or points instead of a card: POST /admin/points/{user_id}/actions/adjust {"points": 200, "reason": "For a review with a photo"}.

An external storefront or a mobile app

  • Catalogue, search, product cards — /shop/products, /shop/categories.
  • “About us” and “Delivery” texts — GET /admin/pages/{slug} → rendered_body (a read-only token is enough; keep it on your server, never in the app).
  • Cart and checkout — as for the sales agent above; keep the cart token on the device.
  • Payment — open payment.url in a web view or the browser.