MobiariDocs

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/storefront SDK wraps everything on this page in a typed client; its README (sdk/storefront/README.md) covers createClient({ 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/storefront

No 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
QuestionAnswer
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 parameterMeaning
searchFree text. Without an explicit sort, results rank by relevance.
categoryA category slug (GET /categories lists them). Unknown: 404 category_not_found.
collectionA collection handle (GET /collections). Unknown: 404 collection_not_found.
sortnewest (default without search), price_asc, price_desc, relevance, title.
min_price_cents, max_price_centsOn the lowest price the shopper pays. Min above max: 422.
in_stocktrue hides products that cannot be bought now.
brandBrands separated by commas, compared without case or accents.
optionsname: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_totalPagination.

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-6f0a2b9c4e55

2. 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 it

A 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 .status

status 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-Key on POST /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); use PUT .../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: 429 rate_limited with Retry-After. See Rate limits.
  • Caching. Catalog and store answers can be cached for short periods by your own CDN or fetch cache. Cart, checkout, payment and customer answers are per shopper and must never be cached shared. Do not cache a response that sent Set-Cookie.
  • CORS. Browsers on any origin can call the API; the preflight allows X-Storefront-Key, Authorization, Content-Type, Idempotency-Key, X-Cart-Id and X-Wishlist-Id, and responses expose X-Cart-Id, X-Wishlist-Id, X-Trace-Id, RateLimit-* and Retry-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

StatuscodeWhenWhat the client should do
401storefront_key_requiredNo X-Storefront-Key, and the request is not on the store's own domain.Send the key.
401invalid_storefront_keyThe key is unknown or was revoked.Deploy the current key; create one in the admin.
403origin_not_allowedThe browser's Origin is not on the key's allowlist.Add the origin to the key, or call from your server.
401not_signed_inNo customer token, an expired one, or a token from another store.Send the shopper to sign in again.
401invalid_credentialsWrong e-mail or password (also for an account without a password).Show a generic message; offer the one-time code.
403cross_originA cookie session was used from another site.Use the bearer token, or same-origin calls.
422code_invalidOne-time or reset code is wrong, expired or used (also after 5 wrong tries).Ask for a new code.
422whatsapp_unavailableThe platform cannot send WhatsApp codes now.Offer e-mail.
400invalid_verification_tokenThe e-mail confirmation link is invalid, expired or used.Register again to get a new link.

Catalog and content

StatuscodeWhenWhat the client should do
404product_not_foundNo active product with this id or slug on the channel.Show a 404 page.
404category_not_found, collection_not_foundThe category or collection filter names none that is visible.Drop the filter.
422validation_failedmin_price_cents above max_price_cents; or invalid review/subscription fields.Fix the fields in details.fields.
403reviews_disabledThe store does not take reviews.Hide the review form.
404form_not_foundNo active form with this slug.Check the slug.
404page_not_found, menu_not_foundNo published page at this address, or no menu with this handle.Show a 404 page, or leave the menu out.
404cms_collection_not_found, cms_document_not_foundNo active CMS collection with this slug, or no live document in it with this slug or id.Show a 404 page.
403turnstile_failedThe anti-bot check on a form was not passed.Ask the shopper to retry the check.
400invalid_bin_or_amountGET /installments got a bad card BIN or amount.Send the first 6 digits and amount_cents.

Cart

StatuscodeWhenWhat the client should do
404cart_not_foundNo open cart with this id in the store (unknown, or already checked out).Create a new cart with POST /carts.
400invalid_cart_idcart_id is neither a cart id nor current.Fix the path.
404variant_not_foundThe variant is not in this store (or not one of the product's).Reload the product.
409insufficient_stockA 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.
422gift_card_cart_mixedA cart holds gift cards or goods, never both. (409 on gift-card-items.)Offer a separate cart.
409too_many_gift_cardsToo many gift card lines in the cart.Remove one first.
422invalid_email, invalid_delivery_dateGift card recipient e-mail or deliver_on is invalid.Fix the field.
409quote_items_lockedThe cart is a quote link whose seller fixed its lines.Disable editing; the shopper only pays.
409quote_freight_lockedA quote whose seller fixed its shipping.Do not offer shipping choices.
409quote_address_lockedA quote whose seller fixed the delivery address.Do not offer address changes.
409cart_price_negotiatedThe cart's price was agreed with the seller; no discount code.Hide the code field.
409gift_card_not_discountableGift cards take no discount code.Hide the code field.
422not_found, not_started, expired, below_minimum, usage_limit_reachedThe discount code does not apply (code says why).Show the matching message.
400pickup_location_requiredmethod: pickup without pickup_location_id.Choose a location.
400pickup_unavailableThe location does not offer pickup.Choose another location.
404location_not_foundNo such location.Reload GET /locations.
400invalid_requestInvalid 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.
422shipping_not_configuredThe store has no shipping set up.Tell the shopper to contact the store.
502shipping_unavailableThe carriers did not answer.Retry after a moment, or offer pickup.
422invalid_phoneNot a phone number (the message says why).Fix the phone.
422gift_card_disabled, gift_card_expired, gift_card_emptyThe gift card code cannot be used.Show the matching message.
404gift_card_not_foundNo card with this code in this store.Check the code.
409gift_card_orderA cart that buys gift cards cannot be paid with credit.Hide credit.
422wallet_emptyThe customer has no store credit to spend.Hide the wallet option.

Payment and checkout

StatuscodeWhenWhat the client should do
400cart_emptyThe cart has no lines.Send the shopper back to the cart.
422shipping_requiredNo shipping option chosen.Choose one first.
422freight_selection_requiredThe cart needs a shipping choice before paying.Quote and choose shipping.
422saved_card_unavailableThe saved card is not the signed-in customer's, or the store's card gateway cannot charge it.Ask for a new card.
422address_requiredThe 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.
422document_requiredPix (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.
422invalid_documentThe CPF/CNPJ fails its check digits.Ask again.
400installments_below_minimumMore installments than the price allows; max_installments says how many.Offer up to that number.
409order_not_payableThe order was cancelled or closed.Start over with a new cart.
409payment_in_progressA card payment is still processing.Keep polling the intent.
409pix_pendingA Pix could not be cancelled to pay by card.Let the Pix finish or expire, then retry.
422payment_requiredcheckout before any payment was approved. details has order_id and cart_id.Poll the intent; confirm only when approved.
422gateway messageThe gateway refused the payment.Show error; offer another method.

Account

StatuscodeWhenWhat the client should do
404address_not_foundNo such address among the customer's.Reload the list.
422too_many_addressesThe customer already keeps 10.Ask to remove one.
404order_not_foundNo such order among the customer's.Show a 404 page.
404invoice_not_foundThe order has no invoice to print yet.Try again later.
404correction_not_foundNo such correction letter.Reload the order.
422returns_disabled, order_not_paid, order_not_delivered, return_window_closed, nothing_to_returnThe order cannot be returned now. GET .../returnable tells before the shopper tries.Hide the return action.
422invalid_reason, no_items, invalid_quantity, duplicate_item, item_not_in_order, quantity_exceeds_returnableThe return request is wrong.Fix the items.
409invalid_stateThe return is already received, refunded or closed; it cannot be cancelled.Reload the return.
422privacy_request_openAn open request of that kind already exists.Show the open request.
409wishlist_fullThe 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.

On this page