Shelftara Documentation 1.0.0

HTTP API

The HTTP surface of Shelftara

Most of Shelftara is server-rendered HTML: you sign in to a page, you fill in a form, you get a page back. Three groups of endpoints speak JSON instead — the register, the summary of the reports and the assistant — and they are documented here with their request and their answer.

Where the routes live

GroupPrefixWho it is for
Marketing/, /pricing, /features, /docs, /contactVisitors, no session.
Authentication/login, /register, /forgot, /logoutVisitors, no session.
Panel/appA signed in user of a workspace, with a permission per page.
JSON API/api/v1A signed in user of a workspace, with a permission per endpoint.
Storefront/storeVisitors of the shop of a workspace.
Platform console/platformThe operator of the installation, role super_admin.
Health/healthzThe monitoring, no session.

The session

A successful sign in writes a session in the database and puts its identifier in a cookie. The cookie is the only thing that identifies the user of the next requests.

PropertyValue
NameSESSION_COOKIE, shelftara_session by default
ValueForty-eight hexadecimal characters, generated with the random source of the system
FlagsHttpOnly, SameSite=Lax, Secure when COOKIE_SECURE is on, path /
LifetimeSESSION_TTL_HOURS, 720 hours by default
Stored inThe table sessions, with the user, the workspace, the address and the user agent

The session is checked on every request. An expired session is deleted when it is met, and the server also purges the expired sessions every thirty minutes. A user who is disabled is refused even while the session is still valid.

The panel answers 302 and sends the visitor to /login?next=… when the session is missing. The JSON API answers 403 with {"error":"not allowed"}.

The CSRF rule

Shelftara uses the double submit cookie pattern. The server puts a random token in a cookie and expects the same token back on every request that changes something.

PropertyValue
Cookie nameCSRF_COOKIE, shelftara_csrf by default
Cookie flagsReadable by the page (not HttpOnly), SameSite=Lax, Secure when COOKIE_SECURE is on
Methods that are exemptGET, HEAD, OPTIONS, TRACE
Where to send the tokenThe header X-CSRF-Token, the header X-Csrf-Token, or the form field _csrf
ComparisonConstant time, so the answer does not leak the token

A request that changes something and carries no valid token is refused with 403. A request under /api/ gets a JSON body, everything else gets a plain sentence: The security token is missing or expired. Please reload the page and try again.

In a browser, the form of the panel carries the token in a hidden field _csrf and the scripts of the register read the cookie and put it in the X-CSRF-Token header.

An example with the register
# read the cookie of the session
curl -s -c jar.txt https://inventory.example.com/app/pos > /dev/null

# the CSRF token is in the jar, the session cookie as well
TOKEN=$(awk '/shelftara_csrf/ {print $7}' jar.txt)

curl -s -b jar.txt -X POST https://inventory.example.com/api/v1/pos/sale \
  -H "Content-Type: application/json" \
  -H "X-CSRF-Token: $TOKEN" \
  -d '{"lines":[{"product_id":1,"qty":2}],"payments":[{"method":"cash","amount":33.00}]}'

How a request finds its workspace

One installation serves many workspaces. The server resolves the workspace of a request with the first rule that matches, in this order:

  1. The subdomain. When DOMAIN is a real domain and the host is a subdomain of it, the subdomain is the slug. With DOMAIN=example.com, the host acme.example.com resolves the workspace acme.
  2. The path. The slug of the route /t/:slug.
  3. The query string. The value of ?tenant=.
  4. The cookie. The value of shelftara_tenant, read only for a visitor who is not signed in, so that the basket of the shop stays with the right business.
  5. The session. When nothing else matched, the workspace of the signed in user.

When the workspace is found through the query string, the server writes the cookie shelftara_tenant so that the next request of the same visitor stays on the same shop. The cookie is not HttpOnly: a shop on its own domain has to be able to read it.

The domain of a workspace

A workspace has a slug and a UUID. The slug is what the three rules above use, and it is what the operator sees in the list of the workspaces under /platform/tenants.

The marketing routes

They are public, they render HTML and they never read a session.

RouteMethodWhat it does
/GETThe home page: the headline, the plans and the features.
/pricingGETThe plans with their prices and their limits.
/featuresGETThe catalogue of the features of the product.
/docsGETThe documentation page of the marketing site.
/contactGETThe contact form.
/contactPOSTRecords the message and answers that it was received. The message is not sent anywhere in 1.0.0.
/healthzGET{"status":"ok","app":"shelftara","time":"2026-12-06T09:41:12Z"}
/robots.txtGETThe directives for the crawlers, with the address of the sitemap.
/sitemap.xmlGETThe sitemap of the marketing site.
/site.webmanifestGETThe manifest of the site, for the installation on a screen of the browser.
/llms.txtGETThe summary of the pages of the site, written for the assistants that read a web page.
/login, /register, /forgotGET, POSTThe authentication pages. /register creates a workspace, its owner and its starter data, and opens the session of the owner.
/logoutPOSTCloses the session and clears the cookie.

The forms of the authentication pages carry the CSRF token, like every other form of the application.

The storefront routes

The shop of a workspace. The workspace is resolved with the rules above; when none of them matches, the shop answers with a page that asks for a workspace instead of a catalogue.

RouteMethodWhat it does
/storeGETThe home of the shop: the categories, the featured products and the basket.
/store/category/:slugGETThe products of a category.
/store/product/:slugGETThe page of a product, with its reviews.
/store/cartGETThe basket of the visitor.
/store/cart/addPOSTAdds a quantity of a product. Fields: product_id, qty, redirect.
/store/cart/updatePOSTChanges the quantity of a line.
/store/cart/removePOSTRemoves a line from the basket.
/store/checkoutGETThe checkout form.
/store/checkoutPOSTCreates the order. Fields: name, email, phone, address, city, country, payment_method, note.
/store/order/:numberGETThe tracking page of an order.
/store/reviewPOSTRecords a review. Fields: product_id, name, rating, comment.

The basket is kept in a cookie that belongs to the slug of the shop. The answers of these routes are HTML pages with a redirect after every action.

The register API

Five endpoints under /api/v1/pos. They need the session cookie of a signed in user with the permission pos.use, and the POST ones need the CSRF token. The answers are JSON.

GET /api/v1/pos/products

Returns the active products of the workspace with the quantity on hand. The query string accepts q (name, reference or barcode) and category (the identifier of a category). The list stops at three hundred products.

GET /api/v1/pos/products?q=coffee&category=3
{
  "products": [
    {
      "id": 12,
      "name": "Ethiopia Yirgacheffe",
      "sku": "CF-ETH-YIR",
      "barcode": "8901234500011",
      "price": 16.5,
      "cost": 9.4,
      "tax_rate": 8,
      "category_id": 3,
      "image": "",
      "qty": 180,
      "stock_alert": 12
    }
  ]
}

POST /api/v1/pos/sale

Records a sale. The whole sale — the order, the invoice, the lines, the payments and the stock — is written in one transaction.

POST /api/v1/pos/sale
Content-Type: application/json
X-CSRF-Token: <token>

{
  "warehouse_id": 1,
  "customer_id": 0,
  "discount": 0,
  "note": "",
  "offline_id": "",
  "lines": [
    {"product_id": 12, "variant_id": 0, "qty": 2, "price": 0, "discount": 0}
  ],
  "payments": [
    {"method": "cash", "amount": 33.00}
  ]
}
FieldTypeWhat it does
warehouse_idnumberWhere the goods leave. When it is zero, the default warehouse of the workspace is used.
customer_idnumberThe customer of the sale. Zero means a walk-in customer.
discountnumberThe discount of the whole basket.
notestringThe note of the order.
offline_idstringThe unique identifier of a sale that was taken while the line was down. When it is given, the matching entry of the offline queue is marked as synchronised.
lines[]arrayThe basket. product_id and qty are required; a price of zero takes the price of the product, and discount is the discount of the line.
payments[]arrayThe payments. Several of them can be combined; method is the label of the method and amount the money taken.
{
  "ok": true,
  "invoice": "INV-00042",
  "total": 33.0,
  "paid": 33.0,
  "change": 0
}

The state of the invoice is unpaid, partial or paid according to what was taken, and the change is the difference between the total and what was paid.

POST /api/v1/pos/hold

Parks a basket. The payload is the state of the basket as the register holds it; the server stores it as it is.

POST /api/v1/pos/hold
{ "name": "Table 4", "payload": "{"lines":[{"product_id":12,"qty":1}]}" }
{ "ok": true, "id": 31 }

POST /api/v1/pos/sync

Stores the sales that were taken while the line was down. A sale whose identifier is already known is ignored, so the same queue can be sent again.

POST /api/v1/pos/sync
{
  "sales": [
    {"uuid": "9c1f8f0e-1a2b-4c3d-8e5f-0a1b2c3d4e5f", "payload": "{"lines":[{"product_id":12,"qty":1}]}"}
  ]
}
{ "ok": true, "stored": 1 }

GET /api/v1/pos/config

The currency, the open shift of the user and the right to give a discount.

{
  "currency": "USD",
  "shift": {
    "id": 8,
    "status": "open",
    "opened_at": "2026-12-06T08:02:11Z",
    "opening_cash": 200
  },
  "can_discount": true
}

The summary and the assistant

GET /api/v1/reports/summary

The figures of the dashboard of the workspace, as JSON. It needs the permission reports.view.

{
  "today_sales": 1842.5,
  "month_sales": 39218.75,
  "stock_value": 24180.4,
  "receivables": 4310.0,
  "payables": 1875.2,
  "open_invoices": 12,
  "low_stock": 3,
  "products": 24
}

POST /api/v1/assistant/ask

Asks a question about the business. It needs the permission dashboard.view. The question and the answer are stored in the conversation of the workspace.

POST /api/v1/assistant/ask
{ "question": "what did we sell today?" }
{
  "ok": true,
  "answer": "Today the register took 1 842.50 in 14 invoices. The month is at 39 218.75 so far. That is ahead of the same day of last week."
}

The answer is composed from the data of the workspace, never from an external service. The questions about the sales, the stock, the customers, the money that is owed, the suppliers, the profit and the top products are the ones the engine knows.

The platform console

The platform layer has no JSON endpoints in 1.0.0: it is driven by HTML forms under /platform, and each action is a POST with a form body. Only the account with the role super_admin and a workspace of zero can reach it; the other accounts get 403.

RouteMethodForm fields
/platform/tenantsPOSTname, owner_name, owner_email, password, plan_code
/platform/tenants/:id/statusPOSTstatus — active or suspended
/platform/tenants/:id/planPOSTplan_id, cycle — monthly or yearly
/platform/plansPOSTcode, name, tagline, description, price_monthly, price_yearly, max_users, max_products, max_warehouse, features, modules, is_active, is_popular, sort
/platform/billing/:id/payPOSTthe amount and the method of the payment
/platform/modulesPOSTcode, name, group, description, is_core, is_active, sort
/platform/settingsPOSTthe settings of the platform, as key and value pairs

Conventions and error codes

StatusWhenBody
200The request succeeded.The page or the JSON answer.
302The session is missing, or the action ended with a redirect.The Location header.
400The body could not be read, or the basket is empty, or a product of the basket does not exist.{"error":"the basket is empty"}
403The permission is missing, or the CSRF token is missing or wrong.{"error":"not allowed"} or {"error":"invalid csrf token"}
404The record does not exist.The error page of the application.
500The sale or the cart could not be written.{"error":"the sale could not be saved"}
  • The answers of the JSON API are UTF-8 JSON. The request bodies must be JSON with the header Content-Type: application/json.
  • The amounts are numbers of the currency of the workspace. They are stored as they arrive; the panels and the reports format them with two decimals.
  • The dates and the times of the answers are in UTC, in the format 2006-01-02T15:04:05Z.
  • The body of a request is limited to 64 MB by the server.
  • The answers of the panel are compressed when the client accepts it; the assets are served with a long cache header.