Skip to content

Connect Your Custom Storefront

Audience: Tenant admins, engineers, and DevOps connecting a custom customer website to Ailaaj One.

Purpose: Create a Storefront API key, set scopes and routing, wire environment variables, and verify the connection.

Companion doc: Integration guide — public API flows, auth headers, checkout, and product detail fields.

Issue a Storefront API key in Admin → Platform → External APIs, bind checkout routing, and point your shop at the live /api/storefront endpoints.

What you are connecting

LayerWhere it runsRole
Ailaaj One Storefront API{your-ailaaj-one-host}/api/storefrontCatalog, cart quote, checkout, customer accounts
Your customer websiteYour domain (e.g. Cloudflare Workers)UI — calls the API from SSR/server, not from the browser for secrets
OMSSame Ailaaj One tenantOrders created with orders.source = api

Every request includes:

  • tenant_id=<your-tenant-uuid> (query string)
  • X-API-Key: <storefront-api-key> (tenant API key from External APIs)

Customer sessions (order history, profile) also send X-Storefront-Session: <token> after login.


Step 1 — Open External APIs

In Ailaaj One, go to Admin → Platform → External APIs (/app/settings/external-apis).

You will see existing keys and a Create API Key button.

External APIs page listing active storefront API keys with scopes and routing

Step 2 — Create an API key and select scopes

Click Create API Key. Give the key a clear name (e.g. Custom Storefront — Production).

For a full custom storefront (browse, cart, checkout, accounts), enable all four active scopes:

ScopeWhat it unlocks
products:readCategories, product list, product detail (PDP)
stock:readCart quote — validates stock and pricing
orders:readOrder tracking and logged-in order history
orders:writePlace checkout orders
Create API Key dialog with products, stock, and orders scopes selected

Copy the full key when shown — it is only displayed once. Store it in your deployment secrets (Vercel, Cloudflare, .env locally).

Read-only keys: If you only sync catalog to another system, products:read + stock:read is enough — routing is optional.


Step 3 — Set routing defaults (required for checkout)

When orders:write is selected, routing defaults are required. They tell OMS which store, warehouse, shipment method, and payment methods this key uses for every API order.

FieldPurpose
Default storeOMS store that owns the order
Default warehouseStock reservation and fulfilment source
Order source channelSet to Custom Storefront (api) — maps to orders.source = api
Default shipment methodDelivery option and shipping cost at checkout
Prepaid / COD paymentPayment methods offered at checkout
Routing defaults bound to store, warehouse, api order source, and payment methods

After saving, GET /api/storefront/config returns these defaults (including shipment cost) so your checkout page does not hard-code OMS IDs.


Step 4 — Wire your custom storefront platform

Point your customer website at the Storefront API. Example environment variables:

Environment variables connecting custom storefront to Storefront API
VariableUsed byValue
VITE_STOREFRONT_API_BASE_URLClient + serverhttps://{your-ailaaj-one-host}/api/storefront
VITE_STOREFRONT_TENANT_IDAll callsYour tenant UUID
VITE_STOREFRONT_API_KEYBrowser-safe catalog calls (if proxied)API key — prefer server proxy in production
STOREFRONT_SERVER_API_TOKENSSR / Workers serverSame API key for cart quote, checkout, auth
VITE_STOREFRONT_SITE_URLConfirmation linksPublic shop URL

Security: Never expose the API key in client bundles for write routes. Call catalog, cart, and checkout from your server or SSR layer, not from public browser JavaScript.


Step 5 — Verify the connection

Run these checks with your key and tenant (replace placeholders):

Config (routing loaded)

Terminal window
curl -s "https://{your-ailaaj-one-host}/api/storefront/config?tenant_id=<your-tenant-uuid>" \
-H "X-API-Key: <your-api-key>"

Categories

Terminal window
curl -s "https://{your-ailaaj-one-host}/api/storefront/categories?tenant_id=<your-tenant-uuid>" \
-H "X-API-Key: <your-api-key>"

Product list

Terminal window
curl -s "https://{your-ailaaj-one-host}/api/storefront/products?tenant_id=<your-tenant-uuid>&limit=5" \
-H "X-API-Key: <your-api-key>"

Expect { "success": true, "data": { ... } }. A 401 or 403 usually means a wrong key, missing scope, or wrong tenant_id.


Storefront API endpoint catalog

Base path: /api/storefront. All routes require tenant_id and a valid tenant API key unless noted.

Public catalog (server or BFF; scope products:read)

MethodPathDescription
GET/configCheckout routing defaults bound to this API key
GET/categoriesTop nav + subcategories + collection tree
GET/categories/[slug]Single storefront category detail
GET/productsListing — category_slug, sub_slug, q, filters, pagination
GET/products/[slug]Product detail — overview, uses, side effects, related, alternates
GET/products/[slug]/alternatesIngredient-matched alternates
GET/products/[slug]/reviewsProduct reviews (when enabled)
GET/product-searchFast search (optional Redis cache)
GET/product-filtersFacets for PLP filters
GET/brandsBrand list for filters

Cart and checkout (server trust; scopes stock:read, orders:write)

MethodPathScopeDescription
POST/cart/quotestock:readValidate lines, stock, and pricing before checkout
POST/ordersorders:writeCreate order — uses routing defaults from the key
POST/orders/trackorders:readTrack by order number (guest)
GET/POST/orders/confirmationCustomer magic-link confirmation (order_number, token)

Customer auth (server; key required)

MethodPathDescription
POST/auth/registerCreate api-channel customer account
POST/auth/loginEmail, phone, or user_name + password
POST/auth/logoutRevoke session (X-Storefront-Session)
GET/auth/meCurrent customer
POST/auth/password-reset/requestSend 6-digit OTP email
POST/auth/password-reset/confirmConfirm OTP + set new password

Logged-in customer (X-Storefront-Session + key)

MethodPathScopeDescription
GET/meAccount summary
PATCH/me/profileUpdate name, email, phone
PATCH/me/passwordChange password
GET/POST/PATCH/DELETE/me/addressesSaved addresses
GET/me/ordersorders:readOrder history (source = api)
GET/me/orders/[id]orders:readOrder detail by UUID or ORD-*
GET/POST/me/prescriptionsPrescription uploads
POST/me/prescriptions/upload-urlPresigned upload URL
GET/PATCH/me/notificationsEmail / WhatsApp preferences

How requests flow

sequenceDiagram
participant Browser
participant YourSite as Your storefront SSR
participant API as /api/storefront
participant OMS as OMS / Postgres
Browser->>YourSite: Browse / add to cart
YourSite->>API: GET products, categories (X-API-Key)
API->>OMS: Tenant-scoped catalog
OMS-->>API: JSON
API-->>YourSite: success envelope
YourSite-->>Browser: HTML / JSON
Browser->>YourSite: Checkout submit
YourSite->>API: POST cart/quote, POST orders
API->>OMS: Create order source=api
OMS-->>API: ORD-*
API-->>YourSite: Order confirmation
YourSite-->>Browser: Thank-you / redirect

Admin setup checklist

Before go-live, confirm in Ailaaj One:

  • Storefront Categories tab — public menu tree and slugs configured
  • External API key — four scopes + routing defaults saved
  • Shipment methods — API-enabled method tied to the key
  • Payment methods — prepaid and COD mapped on the key
  • Tenant domaintenant_domains row for confirmation link host
  • SMTP / WhatsApp — hub env for password reset and order notifications (see Integration guide)

DocTopic
Integration guideArchitecture, auth, checkout, Rx, and PDP API
Release notes v1.1.0Latest storefront changes
Order ManagementFulfilment after API orders land in OMS