Storefront API guide
Build a store front on Mobiari with the shopper API. Publishable keys, a curl walkthrough from catalog to paid order, the cart model, and every error code.
The Storefront API is what a shopper's browser or app calls: catalog, cart, checkout and customer accounts. It is for two kinds of builders:
- Theme authors. Liquid pages render on the server, and their scripts call the same API from the store's own domain.
- Headless stores. A site or app of your own (Next.js, Remix, a mobile
app) on any domain. Mobiari keeps stock, shipping, payment and orders; you
bring the pages. The
@mobiari/storefrontSDK wraps everything on this page in a typed client; its README (sdk/storefront/README.md) coverscreateClient({ key, apiBase }).
This page is the guide. The Storefront API reference lists every operation and schema, and API conventions covers errors, pagination, idempotency and rate limits that hold for every endpoint.
Base URL and the store key
https://api.mobiari.com/v1/storefrontNo store name or slug appears in any path. The store is named by its publishable key, sent on every request:
X-Storefront-Key: pk_live_4c9b1e0f7a2d4f1c8e3b5a6d7c8e9f01| Question | Answer |
|---|---|
| Where do I create one? | In the admin, under Sales Channels, on the store's web channel, in its storefront keys. Every store already has a Default key. |
| Is it a secret? | No. It ships in browser and mobile code. It can only do what a shopper can do, so a leaked key exposes nothing a visitor could not already see. |
| Can I restrict it? | Yes. Give a key an origin allowlist: exact origins such as https://loja.example.com, or https://*.example.com for subdomains. A browser request from another origin gets 403 origin_not_allowed. An empty list accepts any origin. Requests without an Origin header (your server) always pass. |
| How many can I have? | Several per store. Give each app or environment its own, with a name, so you can revoke one without touching the others. |
| How do I revoke or rotate it? | Revoke it in the admin, in the same place; the key stops working within seconds. To rotate without downtime, create a second key, deploy it to your app, then revoke the first. |
| Do I always need it? | Not on the store's own domain (its Mobiari address or a custom domain): there the Host of the request names the store, so same-origin theme code sends no key. A headless app on another origin always sends it. |
export KEY=pk_live_4c9b1e0f7a2d4f1c8e3b5a6d7c8e9f01
export API=https://api.mobiari.com/v1/storefront
curl -s "$API/store" -H "X-Storefront-Key: $KEY"A missing key is 401 storefront_key_required, an unknown or revoked one
401 invalid_storefront_key.
Keys are created, renamed, restricted and revoked in the Mobiari admin. Managing them is not part of the API yet.
Customers
Catalog, cart and checkout are open to anonymous shoppers. The account
routes (/customers/me..., orders, returns, credit) also need the
customer's token:
X-Storefront-Key: pk_live_…
Authorization: Bearer <customer token>The token comes from POST /auth/login, POST /auth/code/verify (sign-in by
one-time code) or POST /customers/verify (after registering). It is valid
for 30 days and only in the store that issued it: another store's token is
401 not_signed_in. Store the token where your platform keeps credentials;
never in a URL. Themes use an HttpOnly cookie on the store's domain instead
(see themes).
The cart
A cart is a resource with an id. Create it once, keep the id (local storage is fine), and put it in every cart URL:
POST /carts creates a cart (201)
GET /carts/{cart_id} reads it
POST /carts/{cart_id}/items adds a variant
PUT /carts/{cart_id}/items/{variant_id}
...Every write to a cart returns the whole cart, priced the way checkout
will charge it (lines, subtotal_cents, discount_cents, shipping_cents,
tax_cents, total_cents, shipping_options, selected_shipping_option_id,
contact_draft), so you render from the answer instead of recomputing.
GET never creates a cart: an unknown or finished cart is 404
cart_not_found, and the client creates a new one.
Server-rendered themes cannot keep an id in JavaScript. For them
{cart_id} can be the literal current: the cart named by the
X-Cart-Id request header or the cart_id cookie. On current, a write
starts a cart when the shopper has none. Responses carry the cart id in
X-Cart-Id (exposed to browsers through CORS), so a headless app can also
read it from there.
Walkthrough with curl
The shell variables below carry on from the previous step. jq picks values
out of the answers.
1. Browse the catalog
# Products on sale, cheapest first, 12 at a time
curl -s "$API/products?in_stock=true&sort=price_asc&limit=12&max_price_cents=20000" \
-H "X-Storefront-Key: $KEY"{
"data": [
{
"id": "0199a4f2-6c1e-7d3a-9b1f-3e2c8a5d7f10",
"slug": "cama-box-casal",
"title": "Cama box casal",
"price_cents": 18900,
"compare_at_cents": 24900,
"available": true,
"variants": [{ "id": "0199a4f2-7a10-7b2c-8d11-6f0a2b9c4e55", "title": "Casal", "price_cents": 18900, "in_stock": true }]
}
],
"has_more": true,
"next_cursor": "bzoxMg"
}| Query parameter | Meaning |
|---|---|
search | Free text. Without an explicit sort, results rank by relevance. |
category | A category slug (GET /categories lists them). Unknown: 404 category_not_found. |
collection | A collection handle (GET /collections). Unknown: 404 collection_not_found. |
sort | newest (default without search), price_asc, price_desc, relevance, title. |
min_price_cents, max_price_cents | On the lowest price the shopper pays. Min above max: 422. |
in_stock | true hides products that cannot be bought now. |
brand | Brands separated by commas, compared without case or accents. |
options | name:value pairs separated by commas (Cor:Azul,Tamanho:M). Values of one option match any of them; different options must match on the same variant. |
limit, cursor, offset, include_total | Pagination. |
GET /products/facets takes the same filters and answers how many products each brand and option value would list (with color_hex for colours), the products in stock and the price range, to build a filter panel.
Next page, then one product by id or slug, and the shop's own details (name, currency, contact, enabled payment methods):
curl -s "$API/products?in_stock=true&sort=price_asc&limit=12&cursor=bzoxMg" -H "X-Storefront-Key: $KEY"
curl -s "$API/products/cama-box-casal" -H "X-Storefront-Key: $KEY"
curl -s "$API/store" -H "X-Storefront-Key: $KEY"
export VARIANT_ID=0199a4f2-7a10-7b2c-8d11-6f0a2b9c4e552. Cart, items and contact
CART_ID=$(curl -s -X POST "$API/carts" -H "X-Storefront-Key: $KEY" | jq -r .id)
# Add 2 (adds to the line); PUT .../items/$VARIANT_ID {"quantity": 1} sets it, 0 removes it
curl -s -X POST "$API/carts/$CART_ID/items" \
-H "X-Storefront-Key: $KEY" -H "Content-Type: application/json" \
-d "{\"variant_id\": \"$VARIANT_ID\", \"quantity\": 2}"
# Who is buying and where it goes
curl -s -X PATCH "$API/carts/$CART_ID/contact" \
-H "X-Storefront-Key: $KEY" -H "Content-Type: application/json" \
-d '{"name": "Ana Souza", "email": "ana@example.com", "phone": "11987654321",
"document": "529.982.247-25", "zip_code": "01310-100", "street": "Av. Paulista",
"number": "1000", "neighborhood": "Bela Vista", "city": "São Paulo", "state": "SP"}'The contact answer is the cart; contact_draft.invalid_fields names the
fields still to fix.
3. Shipping
# Quote: the options are in cart.shipping_options
curl -s -X POST "$API/carts/$CART_ID/shipping-quotes" \
-H "X-Storefront-Key: $KEY" -H "Content-Type: application/json" \
-d '{"destination_postal_code": "01310-100"}' | jq '.shipping_options[] | {option_id, service_name, shipping_cents, delivery_days}'
# Choose one
curl -s -X PUT "$API/carts/$CART_ID/shipping-option" \
-H "X-Storefront-Key: $KEY" -H "Content-Type: application/json" \
-d '{"option_id": "<option_id from the quote>"}'For store pickup, PUT /carts/{cart_id}/fulfillment with
{"method": "pickup", "pickup_location_id": "…"} (GET /locations?pickup=true
lists the points). To show an estimate before there is a cart, use
POST /shipping-estimates with destination_postal_code and items.
4. Discount code
curl -s -X PUT "$API/carts/$CART_ID/discount-code" \
-H "X-Storefront-Key: $KEY" -H "Content-Type: application/json" \
-d '{"code": "BEMVINDO10"}'
# DELETE on the same path removes itA code that does not apply is 422 with code one of not_found,
not_started, expired, below_minimum or usage_limit_reached. Paying
with a gift card or the customer's store credit is separate:
GET /carts/{cart_id}/credit and the credit/gift-cards and credit/wallet
routes.
5. Pay with Pix
curl -s "$API/payment-methods" -H "X-Storefront-Key: $KEY"
# {"data":[{"method":"pix","provider_code":"mercado_pago"},{"method":"card","provider_code":"mercado_pago"}],"card_public_key":"APP_USR-…"}
curl -s -X POST "$API/carts/$CART_ID/payments" \
-H "X-Storefront-Key: $KEY" -H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"method": "pix", "payer": {"document": "529.982.247-25"}}'The answer is a payment intent. For Pix, next_action is
{"type": "pix_qr", "qr_code_base64": "…", "copy_paste": "000201…", "expires_at": "…"}:
show the QR code and the copy-paste text. This call also turns the cart
into an order (once; later calls reuse it), so it fails with
document_required when neither payer.document nor the cart's contact has
the CPF/CNPJ.
Poll the intent until it leaves pending:
INTENT_ID=… # intent_id from the answer
curl -s "$API/carts/$CART_ID/payments/$INTENT_ID" -H "X-Storefront-Key: $KEY" | jq .statusstatus is pending, processing, requires_action, approved, failed,
cancelled, expired or refunded. Poll every 2 to 3 seconds and stop on
anything but pending, processing and requires_action.
For a card, tokenize it in the browser with the gateway's own SDK (the
public key is card_public_key) and send {"method": "card", "card_token": "…", "installments": 3, "payer": {…}}. GET /installments?bin=…&amount_cents=…
lists the plans, each with total_cents and interest_cents (the bin is
optional: without it, the store's own plans). Past the store's interest-free
installments the store may charge its monthly rate: the card is charged
total_cents, so show it. On a store whose card gateway is Asaas, next_action.type
is redirect: send the shopper to url, then poll. Card data never touches
your server.
When GET /payment-methods says saved_cards, a signed-in customer can send
"save_card": true (on Mercado Pago with save_card_token, a second token of
the same card) and pay later with "saved_card_id" from
GET /customers/me/cards (on Mercado Pago with a card_token made from the
card's gateway_card_id and its CVV). DELETE /customers/me/cards/{card_id}
removes one.
6. Confirm the order
curl -s -X POST "$API/carts/$CART_ID/checkout" \
-H "X-Storefront-Key: $KEY" -H "Idempotency-Key: $(uuidgen)"
# {"order_id":"…","cart_id":"…","order_number":"1042","total_cents":37800,"currency":"BRL"}Call it once the payment is approved. Before that it answers 422
payment_required; with an empty cart 400 cart_empty. The cart is closed
and GET /carts/{cart_id} becomes 404 from then on.
7. Sign in and read the orders
TOKEN=$(curl -s -X POST "$API/auth/login" \
-H "X-Storefront-Key: $KEY" -H "Content-Type: application/json" \
-d '{"email": "ana@example.com", "password": "…"}' | jq -r .token)
curl -s "$API/customers/me/orders" \
-H "X-Storefront-Key: $KEY" -H "Authorization: Bearer $TOKEN"
curl -s "$API/customers/me/orders/1042" \
-H "X-Storefront-Key: $KEY" -H "Authorization: Bearer $TOKEN"New customers register with POST /customers (201, an e-mail with a link
follows) and confirm with POST /customers/verify. Passwordless sign-in is
POST /auth/code then POST /auth/code/verify; POST /auth/password-reset
resets a password with a code. GET /customers/me/addresses lists the saved
addresses.
Shapes you will meet
Pages. Every list is a Page: { data, has_more, next_cursor, total? }.
Follow next_cursor while has_more is true; add include_total=true for
total. Reviews add a summary next to the page fields. See
Pagination.
Money is integer cents in *_cents fields, as everywhere in the API. On a
product, price_cents is what the shopper pays, and compare_at_cents is
the struck-through regular price, or null when the product is not on sale.
Variants carry the same pair, and price_range gives the lowest and highest
variant price. Show the discount only when compare_at_cents is set.
Closed sets. availability on a variant is in_stock, preorder or
out_of_stock; available_quantity stops at 99. Treat an unknown value as
"other".
Product fields. A store can attach its own details to products and
variants (material, warranty, dimensions). The ones it chose to show arrive
as fields on the product and on each variant, already in display order and
only when they have a value:
[{ "key": "madeira", "label": "Madeira", "kind": "select", "group": "Materiais", "unit": null, "value": "Carvalho" }].
Each entry carries its own label (and label_translations), kind and
unit, so you can render a specifications table without knowing the store's
setup. value is text, a number, a boolean or, for multiselect, a list.
Status codes. Create is 201 with the resource. Delete with nothing to
say is 204. A change inside a cart returns the whole cart.
Idempotency, rate limits and caching
- Idempotency. Send an
Idempotency-KeyonPOST /carts/{id}/payments,POST /carts/{id}/checkout, registration and review posts, and retry with the same key after a timeout. The rules are in Idempotency. Adding an item is not idempotent (it adds again); usePUT .../items/{variant_id}to set a quantity safely. - Rate limits. Shoppers are anonymous, so the budget is per client
address: 300 requests a minute by default, reported in the
RateLimit-*headers. A server that calls for many shoppers shares one address; cache catalog answers on your side. Over budget: 429rate_limitedwithRetry-After. See Rate limits. - Caching. Catalog and store answers can be cached for short periods by
your own CDN or
fetchcache. Cart, checkout, payment and customer answers are per shopper and must never be cached shared. Do not cache a response that sentSet-Cookie. - CORS. Browsers on any origin can call the API; the preflight allows
X-Storefront-Key,Authorization,Content-Type,Idempotency-Key,X-Cart-IdandX-Wishlist-Id, and responses exposeX-Cart-Id,X-Wishlist-Id,X-Trace-Id,RateLimit-*andRetry-After. The origin allowlist of the key is what restricts browsers.
Error catalog
Every error has the standard shape:
{ "error", "code", "details" }. Branch on code. These are the codes the
Storefront API adds to the general ones (unauthorized, forbidden,
not_found, validation_failed, rate_limited, internal_error).
validation_failed lists details.fields.<field> (messages) and, for forms,
details.codes.<field>.
Key and customer
| Status | code | When | What the client should do |
|---|---|---|---|
| 401 | storefront_key_required | No X-Storefront-Key, and the request is not on the store's own domain. | Send the key. |
| 401 | invalid_storefront_key | The key is unknown or was revoked. | Deploy the current key; create one in the admin. |
| 403 | origin_not_allowed | The browser's Origin is not on the key's allowlist. | Add the origin to the key, or call from your server. |
| 401 | not_signed_in | No customer token, an expired one, or a token from another store. | Send the shopper to sign in again. |
| 401 | invalid_credentials | Wrong e-mail or password (also for an account without a password). | Show a generic message; offer the one-time code. |
| 403 | cross_origin | A cookie session was used from another site. | Use the bearer token, or same-origin calls. |
| 422 | code_invalid | One-time or reset code is wrong, expired or used (also after 5 wrong tries). | Ask for a new code. |
| 422 | whatsapp_unavailable | The platform cannot send WhatsApp codes now. | Offer e-mail. |
| 400 | invalid_verification_token | The e-mail confirmation link is invalid, expired or used. | Register again to get a new link. |
Catalog and content
| Status | code | When | What the client should do |
|---|---|---|---|
| 404 | product_not_found | No active product with this id or slug on the channel. | Show a 404 page. |
| 404 | category_not_found, collection_not_found | The category or collection filter names none that is visible. | Drop the filter. |
| 422 | validation_failed | min_price_cents above max_price_cents; or invalid review/subscription fields. | Fix the fields in details.fields. |
| 403 | reviews_disabled | The store does not take reviews. | Hide the review form. |
| 404 | form_not_found | No active form with this slug. | Check the slug. |
| 404 | page_not_found, menu_not_found | No published page at this address, or no menu with this handle. | Show a 404 page, or leave the menu out. |
| 404 | cms_collection_not_found, cms_document_not_found | No active CMS collection with this slug, or no live document in it with this slug or id. | Show a 404 page. |
| 403 | turnstile_failed | The anti-bot check on a form was not passed. | Ask the shopper to retry the check. |
| 400 | invalid_bin_or_amount | GET /installments got a bad card BIN or amount. | Send the first 6 digits and amount_cents. |
Cart
| Status | code | When | What the client should do |
|---|---|---|---|
| 404 | cart_not_found | No open cart with this id in the store (unknown, or already checked out). | Create a new cart with POST /carts. |
| 400 | invalid_cart_id | cart_id is neither a cart id nor current. | Fix the path. |
| 404 | variant_not_found | The variant is not in this store (or not one of the product's). | Reload the product. |
| 409 | insufficient_stock | A line asks for more than is available. details has available, max_shippable and limiting_sku. | Lower the quantity to available. Also returned by payment and checkout when stock changed meanwhile. |
| 422 | gift_card_cart_mixed | A cart holds gift cards or goods, never both. (409 on gift-card-items.) | Offer a separate cart. |
| 409 | too_many_gift_cards | Too many gift card lines in the cart. | Remove one first. |
| 422 | invalid_email, invalid_delivery_date | Gift card recipient e-mail or deliver_on is invalid. | Fix the field. |
| 409 | quote_items_locked | The cart is a quote link whose seller fixed its lines. | Disable editing; the shopper only pays. |
| 409 | quote_freight_locked | A quote whose seller fixed its shipping. | Do not offer shipping choices. |
| 409 | quote_address_locked | A quote whose seller fixed the delivery address. | Do not offer address changes. |
| 409 | cart_price_negotiated | The cart's price was agreed with the seller; no discount code. | Hide the code field. |
| 409 | gift_card_not_discountable | Gift cards take no discount code. | Hide the code field. |
| 422 | not_found, not_started, expired, below_minimum, usage_limit_reached | The discount code does not apply (code says why). | Show the matching message. |
| 400 | pickup_location_required | method: pickup without pickup_location_id. | Choose a location. |
| 400 | pickup_unavailable | The location does not offer pickup. | Choose another location. |
| 404 | location_not_found | No such location. | Reload GET /locations. |
| 400 | invalid_request | Invalid CEP, a cart that cannot be quoted, no quote yet, an unknown or expired shipping option, or an estimate without items. | Quote again, then choose from shipping_options. |
| 422 | shipping_not_configured | The store has no shipping set up. | Tell the shopper to contact the store. |
| 502 | shipping_unavailable | The carriers did not answer. | Retry after a moment, or offer pickup. |
| 422 | invalid_phone | Not a phone number (the message says why). | Fix the phone. |
| 422 | gift_card_disabled, gift_card_expired, gift_card_empty | The gift card code cannot be used. | Show the matching message. |
| 404 | gift_card_not_found | No card with this code in this store. | Check the code. |
| 409 | gift_card_order | A cart that buys gift cards cannot be paid with credit. | Hide credit. |
| 422 | wallet_empty | The customer has no store credit to spend. | Hide the wallet option. |
Payment and checkout
| Status | code | When | What the client should do |
|---|---|---|---|
| 400 | cart_empty | The cart has no lines. | Send the shopper back to the cart. |
| 422 | shipping_required | No shipping option chosen. | Choose one first. |
| 422 | freight_selection_required | The cart needs a shipping choice before paying. | Quote and choose shipping. |
| 422 | saved_card_unavailable | The saved card is not the signed-in customer's, or the store's card gateway cannot charge it. | Ask for a new card. |
| 422 | address_required | The cart's contact has no billing address (street, CEP, city and state). Required for pickup too: the invoice is issued to it. | Ask for the address, save it with the cart's contact, retry. |
| 422 | document_required | Pix (and a card paid on Asaas's page) need the payer's CPF/CNPJ, not in the body or the cart's contact. | Ask for it, send payer.document. |
| 422 | invalid_document | The CPF/CNPJ fails its check digits. | Ask again. |
| 400 | installments_below_minimum | More installments than the price allows; max_installments says how many. | Offer up to that number. |
| 409 | order_not_payable | The order was cancelled or closed. | Start over with a new cart. |
| 409 | payment_in_progress | A card payment is still processing. | Keep polling the intent. |
| 409 | pix_pending | A Pix could not be cancelled to pay by card. | Let the Pix finish or expire, then retry. |
| 422 | payment_required | checkout before any payment was approved. details has order_id and cart_id. | Poll the intent; confirm only when approved. |
| 422 | gateway message | The gateway refused the payment. | Show error; offer another method. |
Account
| Status | code | When | What the client should do |
|---|---|---|---|
| 404 | address_not_found | No such address among the customer's. | Reload the list. |
| 422 | too_many_addresses | The customer already keeps 10. | Ask to remove one. |
| 404 | order_not_found | No such order among the customer's. | Show a 404 page. |
| 404 | invoice_not_found | The order has no invoice to print yet. | Try again later. |
| 404 | correction_not_found | No such correction letter. | Reload the order. |
| 422 | returns_disabled, order_not_paid, order_not_delivered, return_window_closed, nothing_to_return | The order cannot be returned now. GET .../returnable tells before the shopper tries. | Hide the return action. |
| 422 | invalid_reason, no_items, invalid_quantity, duplicate_item, item_not_in_order, quantity_exceeds_returnable | The return request is wrong. | Fix the items. |
| 409 | invalid_state | The return is already received, refunded or closed; it cannot be cancelled. | Reload the return. |
| 422 | privacy_request_open | An open request of that kind already exists. | Show the open request. |
| 409 | wishlist_full | The list holds 200 products. | Ask to remove one. |
Channel API
The server-to-server POST /v1/channel/orders (secret X-Channel-Key)
answers 401 channel_key_required or invalid_channel_key, and 422
no_valid_items when none of the lines is an active product of the store.
Chat widget
The chat widget is a separate, older surface. It still answers at
/widget/{key}/... (also under /v1/widget/...) with its own key in the
path, not at /v1/storefront. See realtime.
Theme reference
Every object and field a Liquid theme receives on each page of the hosted storefront, generated from the platform code.
API
The Mobiari API for integrations: catalog, inventory, orders and fulfilment, customers, discounts, webhooks and events of a store. Small, uniform, and it keeps its shape.