Everything a storefront for your store needs to talk to Soko Sensei: which headers to send, the endpoints available, and what they return.
Your details
| API base URL | https://staging.sokosensei.com/api |
Store ID (X-Store-Id) |
YOUR_STORE_ID |
API key (X-Store-Key) |
Your storefront API key |
Keys are generated in the admin: go to Settings, open Integrations and find the Storefront API key section. A new key is shown once; regenerating it stops the old one immediately.
Headers
Send these on every request:
| Header | Value |
|---|---|
Accept |
application/json |
X-Store-Id |
Your Store ID (all endpoints except store resolve) |
X-Store-Key |
Your storefront API key |
Idempotency-Key |
On requests that create something (see below) |
- A wrong key is always rejected with
401. - When Require the API key is on (under Settings, in Integrations), a missing key is rejected with
401too, store resolve included, so your site gets nothing without it. Add the key to your storefront and deploy before switching it on. - While it is off, a missing key is let through and store resolve returns a warning in
data.warnings. - The key travels with browser requests, so anyone inspecting your site's traffic can see it. It ties requests to your storefront; never use it as a password or put other secrets in your frontend.
Idempotency-Key
Booking, checkout, payments, leads and form submissions take an Idempotency-Key header: a random value (a UUID is ideal, 16–128 letters, digits, dashes or underscores) that you make once per customer action and send again on every retry of that action.
- The first request runs. A repeat with the same key and the same body within 24 hours gets the first response back (with header
Idempotent-Replayed: true) instead of running again, so a double tap or a retry after a timeout never places a second order, booking or M-Pesa prompt. - The same key with a different body is refused with
422; make a new key when the customer changes their answers. - A repeat while the first is still running gets
409withRetry-After; wait and send it again. - Required (
428without it) when Require an Idempotency-Key is on (under Settings, in Integrations); checked whenever it is sent. - Keep the key after a timeout, a network error or a
5xx, and retry with it. Make a new one after a success, or after a4xxthat the customer fixes.
Responses
Every response uses the same envelope:
{ "success": true, "message": "Products retrieved successfully", "data": { } }
Errors have "success": false, a readable message, and for validation errors (422) the field errors in data.
| Status | Meaning |
|---|---|
400 |
A required header is missing, or the Idempotency-Key is malformed |
401 |
Invalid or missing API key |
404 |
Store, product, service, order or form not found |
409 |
A request with this Idempotency-Key is still running; retry shortly |
410 |
A personal form link was already used, has expired or was cancelled |
413 |
Request too large (form submissions over 64 KB) |
422 |
Validation failed, or the request can't be completed (e.g. slot taken, key reused for a different request) |
428 |
Idempotency-Key required |
429 |
Too many requests; slow down and retry |
502 |
A payment gateway could not be reached |
List endpoints return data.items and data.pagination (current_page, per_page, total, last_page). Use page and per_page (1–100, default 15) to page through results.
1. Load the store
GET /store/resolve — call this first. Send X-Store-Host (your site's domain) instead of X-Store-Id.
Returns the store's name, branding, contact details, socials, theme, checkout_mode, payment_methods and warnings. checkout_mode is how this store's customers pay (online, manual or whatsapp, see section 4); payment_methods lists its gateways only when it is online. Show only the payment options listed in payment_methods:
"flow": "stk_push"(M-Pesa): ask for a phone number, call itsendpoint, then poll the payment status."flow": "redirect"(Pesapal): call itsendpointand send the customer to the returnedredirect_url."test_mode": truemeans the store is on sandbox; no real money moves.
2. Products
GET /products— filters:search,category(category id),on_sale,is_featured(true/false); sort withsort_by(product_name,product_cost,created_at) andsort_dir(asc/desc).GET /products/categories— the store's active categories that have products sold online, withproducts_count. Each product carries itscategory.GET /products/{id}— one product with every photo.avatar_urlis the main photo (when a product has no main photo, its first extra photo),imagesthe extra photos in the store's order (id,url), andphotosevery photo's URL, main first: showphotosas the product's gallery. The list (GET /products) carries the same fields.
Prices are whole KES. cost is the regular price and current_cost is what checkout charges. When a discount applies, sale_percentage and sale_cost are set (otherwise null): show cost struck through next to sale_cost. Sorting by product_cost follows the price customers pay.
3. Services and appointments
GET /services— filters:search,on_sale,requires_appointment,pricing_type; sort withsort_by(service_name,price,created_at). Each service'scategory(id,name) is its service category: services have their own categories, apart from the product ones. Service categories made from the old shared ones kept their ids.GET /services/{id}— one service with its images.
A fixed price service's current_price is its price before VAT; current_price_with_vat is what the booking charges. vat is { "enabled": bool, "rate": 16, "amount": 240 } (rate null and amount 0 when the service charges no VAT); ranges have min_cost_with_vat and max_cost_with_vat. When a discount applies, sale_percentage is set with sale_price (fixed) or sale_min_cost and sale_max_cost (range). Free and quoted services are never discounted.
GET /services/{id}/slots?date=YYYY-MM-DD— available time slots.POST /services/{id}/slots/{slotId}/book— body:guest_name,guest_email,guest_phone,description(required);guest_age,guest_gender,preferred_specialist_gender,promo_code(optional).
For a paid service the booking response includes payment.order_type ("service"), payment.order_id and payment.amount (the sale price when on sale, less any promo, plus VAT; payment.vat_amount is the VAT in it and payment.promo shows the code and discount); use them to take payment (section 5). A promo code works only on fixed price services.
4. Checkout (products)
POST /checkout — body:
{
"items": [{ "id": "<product id>", "quantity": 2 }],
"firstName": "Jane",
"lastName": "Wanjiku",
"email": "jane@example.com",
"phone": "0712345678",
"delivery": "pickup",
"orderDescription": "Optional note",
"promoCode": "SAVE20"
}
delivery is pickup or delivery. orderDescription and promoCode are optional. If the cart lists the same product twice, the quantities are added together. Prices are worked out on the server, never taken from the request: each item is charged its sale price when on sale. The response's data.id is the order id to pay with (order_type "product"), and it returns the breakdown to show the customer:
{
"id": "cart_01K...",
"currency": "KES",
"items": [
{ "id": "<product id>", "name": "Kitchen Sink Mixer Tap", "quantity": 2, "regular_price": 2800, "unit_price": 2380, "sale_percentage": 15, "subtotal": 4760, "discount": 840, "promo_discount": 952 }
],
"subtotal": 5600,
"discount": 840,
"promo": { "code": "SAVE20", "discount": 952 },
"total_cost": 3808
}
Products show current_cost (before VAT), vat (enabled, rate, amount) and current_cost_with_vat (what checkout charges for one). In the order, each item has vat_rate and vat_amount, and the order has vat_amount.
The response also has order_number, the short number the customer quotes and the store's admin sees (e.g. TH-1042; show it to the customer), while id stays the long cart id it always was (either works with the payment endpoints), payment_status, order_status, checkout_mode, online_payment, manual_payment and whatsapp_url.
checkout_mode is the store's choice (Store settings → Checkout) of how its customers pay. Follow it on your confirmation page:
checkout_mode |
What to do |
|---|---|
online |
online_payment lists the store's gateways (["mpesa"], ["mpesa", "pesapal"]). Let the customer pick one and start it as in section 5. manual_payment and whatsapp_url are null. |
manual |
Pay the shop directly: show manual_payment (below). online_payment is []. |
whatsapp |
Send the customer to whatsapp_url: a wa.me chat with the store (its WhatsApp number, else its phone) with the order typed out (the store's name, the items and quantities, the total, the customer's name and the order number). manual_payment is there too. online_payment is []. |
Until a store chooses, it gets online when it has a gateway, else manual when it lists payment options, else whatsapp. A store with neither a WhatsApp nor a phone number never gets whatsapp: it gets manual, with its contacts. In every mode the order is placed and stays pending until it is paid (online) or the store records the payment; the store gets an email and SMS for it, and the customer an SMS and (with an email) an email saying it is received, pending payment confirmation, with how to pay.
When the customer pays the shop directly (manual or whatsapp), the order is still placed and stays pending until the store records the payment. manual_payment then tells the customer how to pay the store directly and how to reach it; show it on your confirmation page:
"manual_payment": {
"reference": "TH1042",
"methods": [
{ "type": "mpesa_till", "title": "M-Pesa Buy Goods (till)", "details": [{ "label": "Till number", "value": "987654" }, { "label": "Name", "value": "Thika Hardware" }], "note": null },
{ "type": "cash", "title": "Cash", "details": [], "note": "Pay at the counter on pickup." }
],
"contacts": { "phone": "0722 000 111", "whatsapp": "0712 345 678", "whatsapp_url": "https://wa.me/254712345678?text=…", "email": "sales@example.co.ke", "address": null, "hours": "Mon–Sat, 8:00–18:00" }
}
reference is what the customer quotes as the account number or bank reference (the order number without its dash). methods and contacts hold only what the store has filled in. In online mode, manual_payment is null: start the payment as in section 5.
Checking an order
POST /orders/lookup lets a customer check an order: body order_number (the short one, e.g. TH-1042 in any case and with or without the dash, or the long id from before) and the phone or email they used at checkout. Both must match; any mismatch returns the same 404, so it never tells which part was wrong. It returns order_number, order_status (pending, processed, dispatched, delivered, cancelled), payment_status, items (name, quantity, line_total), vat_amount, promo_discount, total_cost, delivery_method and, while it waits to be paid by hand, manual_payment. It never returns the customer's name, phone or email. 10 requests per minute per visitor, and 10 per hour for any one order number.
total_cost is the amount the payment will ask for: subtotal − discount − promo.discount + vat_amount. VAT is worked out per unit after the sale price and promo. discount is from sale prices; promo is null when no code was used. If a promo covers the whole order, total_cost is 0 and the order is marked free, so skip payment.
Promo codes
A store's promo code works on one product, one category (its products and services) or one service, has an optional start and end date and an optional maximum number of orders. It comes off after the sale price. For a product, the store chooses whether the value comes off each unit or once off that product's total.
POST /promo-codes/check shows the price with a code before the customer orders. Body: code, and either items (same as checkout) or service_id (a fixed price service being booked). Nothing is saved, so send the code again with checkout or booking.
- With
itemsit returns the same breakdown as checkout, withoutid. - With
service_idit returnsprice,promo_discount,vat_rate,vat_amount,total_cost(with VAT) andpromo_code.
An unusable code returns 422 with a message to show, e.g. "This promo code has expired." or "This promo code doesn't apply to anything in your cart." Checkout and booking return the same errors. The check allows 20 requests per minute per visitor.
5. Payments
POST /payments/mpesa— body:order_id,order_type(productorservice, defaultproduct),phone. Sends an M-Pesa prompt to the customer's phone.POST /payments/pesapal— body:order_id,order_type, optionalcallback_url(must be https on your store's own domain; defaults tohttps://<your domain>/checkout/complete). Returnsredirect_url.GET /payments/{order_type}/{order_id}/status— returnspayment_statusandpaid. Poll this every few seconds after starting an M-Pesa payment, or when the customer returns from Pesapal.
Payment endpoints allow 10 requests per minute per visitor.
6. Leads
POST /leads — body: name (required), email or phone (one required), interest, business_type, message, source (optional). Use it for contact or enquiry forms. Allows 10 requests per minute per visitor.
6a. Consent forms (module)
For stores with the Consent forms module. The store sends a client a personal link from the admin (Send consent form under Consent, or from an appointment) by SMS and email: https://<your domain>/forms/consent/<token>. Build that page on your site; keep it out of your navigation, sitemap and analytics, and set robots: noindex and referrer: no-referrer on it.
GET /form-invitations/{token}— opens a link. Returnstype(consent),form,recipient(name,email,phoneto fill in),store.nameandexpires_at.404for an unknown token,410when it was used, expired or cancelled (showmessage).form:id,title,intro,body(HTML; sanitise before showing),version,fieldsandform_token.fieldssays how to ask for each detail:required,optionaloroff(don't show it, and don't send it).POST /consent-forms/{form id}/submissions—decision(acceptedordeclined),name,email, the fields the form asks for (phone,id_number,date_of_birthasYYYY-MM-DD),version,form_token,invitation(the token from the link) andwebsite(an empty hidden field). Accepting emails a signed PDF to the client and the store; declining is recorded.
Rules the API enforces: the form_token must come from the same form and be at least 3 seconds and at most 12 hours old; a link works once; only the form's own fields are accepted (text up to 255 characters); bodies over 64 KB are refused; a filled website field is silently ignored; 5 sends per minute and 30 per hour per visitor, 3 per form per 10 minutes, 200 per hour per store, and 5 per email per form per day. A changed form returns 409 with the new version: load it again. Forms the store has opened to everyone (not "Only by personal link") are also listed at GET /consent-forms and shown by id, and can be submitted without invitation.
7. AI sales assistant (add-on)
The easiest way to add the assistant is the ready-made chat widget. Put this on every page, with your Store ID:
<script src="https://<soko-sensei-host>/widget/assistant.js" data-store-id="YOUR_STORE_ID" async></script>
Add data-store-key="ssk_..." if you use a storefront API key, and data-color="#813e98" to match your brand. The widget shows nothing unless the AI sales assistant is on your plan and switched on under Settings, in Integrations.
To build your own chat UI instead:
GET /assistant— returnsenabled,nameandgreeting. Hide the chat whenenabledisfalse.POST /assistant/chat— body:message(1–500 characters) andsession(leave it out on the first message, then send back thesessionyou received). Returnssession,replyandmode. Whenmodeisdetails_form, show a form for the customer's name and phone or email. Allows 20 messages per minute per visitor.POST /assistant/details— body:session,name, plusphoneoremail, and an optionalmessage. Saves a lead with the recent chat attached and sends your usual lead alert. One lead per chat; sending again updates it. Allows 10 requests per minute per visitor.
The assistant answers from your products, services, prices, stock and opening hours. It never places orders or takes payments. Phone numbers, emails and M-Pesa codes typed into the chat are removed before anything is sent to the AI. A 403 with data.code assistant_unavailable means the assistant is off for this store.
8. Agent mode (A2UI)
Agent mode is a full-width shopping screen instead of a chat bubble. The customer says what they need; the assistant shows product cards, fills the cart, offers booking times and opens the checkout or booking form. An order, booking or payment only goes through when the customer fills in the form and taps the button. Switch it on under Settings, in Integrations, in the Agent mode part of the AI sales assistant section. It is part of the AI sales assistant add-on and uses the same monthly message limit; button taps don't count towards it.
The easiest way to add it is the ready-made screen. Put this on a page of your site, with your Store ID:
<div id="soko-agent"></div>
<script src="https://<soko-sensei-host>/widget/agent.js" data-store-id="YOUR_STORE_ID" data-mount="#soko-agent" async></script>
data-store-key and data-color work as for the chat widget. Without data-mount, a "Shop with AI" button opens the screen full-size; data-name="Fundi Sensei" sets its title before the first response. Soko Sensei also hosts the same screen for every store at https://<soko-sensei-host>/shop/YOUR_STORE_ID, which you can share on WhatsApp or social media.
Buttons on your own pages can open the screen and start something in it. Add data-launcher="false" to the script tag if you don't want the floating button as well:
<button data-soko-agent>Ask us</button>
<button data-soko-agent data-soko-agent-product="PRODUCT_ID">Add to cart</button>
<button data-soko-agent data-soko-agent-service="SERVICE_ID">Book a time</button>
<button data-soko-agent data-soko-agent-category="CATEGORY_ID">Paint</button>
<button data-soko-agent data-soko-agent-ask="Do you deliver to Ruiru?">Delivery?</button>
<form data-soko-agent><input name="q" placeholder="What are you building?"><button>Ask</button></form>
The IDs are the public_id values from the products, services and categories endpoints. Only data-soko-agent-ask and the form use the AI; the others work like taps on the screen.
Building your own front end
Responses carry A2UI messages (version v0.9.1, basic catalog https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json) in data.a2ui, so you can draw them with an official A2UI renderer (React, Lit, Angular or Flutter) or your own. The screen has four surfaces: assistant (the reply line and suggestion chips), results (product cards, services, open times, the details form), cart, and task (checkout, booking and payment). Every component is built by Soko Sensei from your store's data; the AI only writes the reply line.
GET /agent(send the session in anX-Agent-Sessionheader, if you have one) — the whole screen:createSurfacefor each surface, then its components. Also returnssession(nullfor a new visitor: a session is created on the first message or tap) andname. No AI call.POST /agentwith{"session": "...", "message": "I need 3 bags of cement"}— the assistant answers and redraws what changed. 20 per minute per visitor.POST /agentwith{"session": "...", "action": {"name": "...", "surfaceId": "...", "sourceComponentId": "...", "context": {...}}, "dataModel": {...}}— a button tap. Send the button'saction.event.nameandcontext, and for theresultsandtasksurfaces (sendDataModel: true) the surface's data model with the form values. 60 per minute per visitor.
Each response has session, text (the reply line), a2ui (only the surfaces that changed), poll and redirect. When poll is payment_status, send that action every few seconds until it comes back null. When redirect is set, send the customer there (Pesapal).
Actions: add_to_cart, set_qty (qty 0 removes), view_product, browse, show_welcome, show_services, show_times, checkout, place_order, show_payment, pay_mpesa, pay_pesapal, payment_status, pick_slot, book, close_task, details, send_details and ask (a suggestion chip, treated as a typed message). The cart is kept on the server with the session, and prices always come from Soko Sensei. Payments can only be started for the order or booking placed in the same session. A session can place up to 3 orders or bookings. M-Pesa prompts are limited to 3 per order and 3 per phone number every 10 minutes. Completed orders, bookings, details forms and payments are also capped per visitor connection and per store each hour. With pay_pesapal, send return_url (an https page on your store's domain) to bring the customer back to your page. When a response's session differs from the one you sent (a new or expired session), it deletes and recreates every surface.
Form values are used only to place the order or booking. They are never saved with the chat or sent to the AI. A 403 with data.code assistant_unavailable means agent mode is off for this store.