# Shop and content API

> Every address a site uses for its products, checkout, orders, blog, content, forms, bookings, reviews and accounts, plus the admin routes.

The same API is available in two places:

- **On the site's own address**, under `/_vorjo/`. For example `https://www.yourbrand.com/_vorjo/store/products`. This is what the site itself uses.
- **On the API host**, at `https://api.vorjo.com/v1/sites/<site>` plus the route, where `<site>` is the site's address name (the part before `.vorjo.app`). CORS is open, so any front end can call it.

All bodies are JSON, all keys are camelCase, money is a number in the store currency with 2 decimals (whole numbers for zero-decimal currencies), weights are grams, and dates are ISO strings. Errors come back as `{ "error": "…" }` with a 4xx status.

## Store

| Method and path | Body | Returns |
| --- | --- | --- |
| GET `store` | | Currency, prices-include-tax, countries shipped to, pickup, payment methods, checkout fields and theme |
| GET `store/products?collection=&q=&tag=&sort=&limit=&offset=&spec.Brand=` | | `{ products, total }`. `sort`: `newest`, `price-asc`, `price-desc`, `title`. `limit` up to 200. Active products only. `spec.<Name>=<value>` (repeatable, any case) keeps products with one of those values, e.g. `spec.Brand=Daikin&spec.Brand=LG`. |
| GET `store/products/:handle` | | `{ product }` |
| GET `store/specs?collection=` | | `{ filters: [{ name, values: [{ value, count }] }] }`: the specification names and values the active products use, for shop filters |
| GET `store/collections` | | `{ collections }` |
| POST `store/quote` | `{ items: [{ variantId, qty }], address?, shipping?, discountCode? }` | Lines, subtotal, saleTotal, discount, shipping, tax, total, shipping options and any problems. Each line has `price` (after any sale), `originalPrice`, `salePrice`, `saleId` and `saleName`. Prices sent by the page are ignored. |
| POST `store/checkout` | Quote body plus `{ customer: { name, email, phone }, address, note, payment, returnTo, cancelTo? }` | `{ order: { number, ref } }`, plus a `redirect` for redirect payments |
| POST `store/orders/lookup` | `{ number, email }` | `{ ref }` |

`payment` is `"card"`, `"manual"` (cash on delivery) or `"gear:<id>"` for a payment Gear such as `gear:paypal`.

Digital products: quote lines of a download have `digital: true`, and a cart of downloads only has `needsShipping: false` (no address or shipping needed at checkout). Once an order is paid, GET `store/orders/:ref` adds `downloads: [{ lineId, title, licenceKey, expiresAt, expired, files: [{ name, size, url, left }] }]`; before that it has `downloadsPending: true`. Each `url` is a signed link that expires and counts downloads; the files themselves never appear in the API or in webhooks (order lines carry `digital: true`).

```bash title="curl" group="Example: list products"
curl "https://api.vorjo.com/v1/sites/linen-and-loom/store/products?limit=2&sort=newest"
```

```js title="JavaScript"
const r = await fetch("https://api.vorjo.com/v1/sites/linen-and-loom/store/products?limit=2&sort=newest");
const { products, total } = await r.json();
```

```json title="Response"
{
  "products": [
    { "id": "p_3k9", "handle": "linen-shirt", "title": "Linen shirt", "priceMin": 48, "priceMax": 52, "image": "/_vorjo/files/shirt.jpg", "inventoryTotal": 31 },
    { "id": "p_7b2", "handle": "canvas-tote", "title": "Canvas tote", "priceMin": 24, "priceMax": 24, "image": "/_vorjo/files/tote.jpg", "inventoryTotal": null }
  ],
  "total": 24
}
```

### Shapes

```ts
Product = {
  id, handle, title, description /* markdown */, status: "active", type, vendor, tags: string[],
  images: string[], options: { name, values: string[] }[], variants: Variant[],
  specs: { name, value, group? }[] /* specifications, info only, in the owner's order: [{ name: "Brand", value: "Daikin" }, { name: "BTU", value: "12,000", group: "Cooling" }] */,
  collectionIds: string[], seo: { title, description }, taxable, requiresShipping,
  digital: boolean /* a download: never shipped; show "Instant download" (<DigitalBadge />). Files are never in the API */,
  // list views also get priceMin, priceMax, inventoryTotal, image
}
Variant = {
  id, title /* "M / Black" or "Default" */, options: { [name]: string }, sku, barcode,
  price, compareAtPrice: number | null, weight, trackInventory, inventory, allowBackorder, image, position,
  // automatic sales (public routes only): price is what it sells for now
  originalPrice /* the saved price */, salePrice: number | null, sale: SaleBadge | null,
}
SaleBadge = { id, name, endsAt: string | null, countdown: boolean /* show a timer */, stacks: boolean /* codes apply on top */ }
// a product also gets originalPriceMin, originalPriceMax and sale (the variant's sale that saves the most); priceMin and
// priceMax are today's prices. While a sale is on, compareAtPrice is at least the original price.
Collection = { id, handle, title, description, image, productIds: string[], position }
// Options and variants are the choices a customer makes that change the price or stock; specs never do.
Address = { name, line1, line2, city, region, postcode, country /* ISO-2, e.g. "US" */, phone }
```

### Several currencies

A shop may offer more currencies than its store currency (Settings › More currencies). Send `X-Vorjo-Fx: 1` (or `?currency=EUR`)
when your page shows prices in the currency the answer names; without it every price stays in the store currency. With it,
`GET /store` names the shopper's `currency` plus `shopCurrency`, `currencies` (the picker's list) and `chargedIn` (which currency
each way to pay charges); products, quotes and checkouts come in the shopper's currency (their pick in the `vj_cur` cookie, else
their country). A quote also has `shop: { currency, total, rate }`: the same total in the store currency, which cash on delivery
and other pay-later methods charge. In the admin API and webhooks an order's amounts stay in the store currency; an order placed
in another currency also has `presentment: { currency, rate, charged, subtotal, discountTotal, shippingTotal, taxTotal, total, refunded }`.

## Hosted pages

Vorjo runs these on every shop's own address. Link to them; don't rebuild them.

| Path | What |
| --- | --- |
| `/cart`, `/checkout` | Cart and checkout. Checkout reads the cart from the browser, or `?items=<variantId>:<qty>,…` from other front ends. |
| `/_vorjo/order/<ref>` | Thank-you and order status page |
| `/track` | Look up an order by number and email |
| `/account`, `/login`, `/signup`, `/forgot-password` | Customer accounts |
| `/search`, `/policies/<key>` | Search and policy pages |
| `/_vorjo/kit/kit.js` | The script behind them. It adds `window.Vorjo` (`openCart()`, `add(item)`, `checkout()`); any element with `data-vorjo-cart` opens the cart |

## Blog

| Method and path | Returns |
| --- | --- |
| GET `blog/posts?tag=&category=&limit=&offset=` | `{ posts, total, tags, categories }` (published posts, no body) |
| GET `blog/posts/:slug` | `{ post }` |
| GET `blog/categories` | `{ categories: [{ slug, name, count }] }` |

```ts
Post = { id, slug, title, excerpt, body /* markdown */, cover, tags, author,
         category: { slug, name } | null, publishedAt, seo: { title, description } }
```

## Content, forms and bookings

| Method and path | Body | Returns |
| --- | --- | --- |
| GET `content/:collection` | | `{ items }`: the site's content collection, like a menu or team list |
| POST `forms/:name` | Any fields (up to 40). Keys starting `_` are dropped, except `_page`. | `{ ok: true }` |
| GET `bookings` | | `{ services, timezone, days }` |
| GET `bookings/slots?service=&date=YYYY-MM-DD` | | `{ service, date, slots: [{ start, time }] }` |
| GET `bookings/days?service=&from=YYYY-MM-DD&to=YYYY-MM-DD&staff=` | | `{ service, timezone, from, to, days: { "YYYY-MM-DD": [{ start, time }] } }`: free times for up to 42 days in one call; only open days are listed, a full day is `[]` |
| POST `bookings` | `{ service, start, name, email, phone, note }` | `{ ok, booking }`, or 409 if the slot was just taken |

## Reviews and search

| Method and path | Body | Returns |
| --- | --- | --- |
| GET `reviews?product=&limit=&offset=` | | Published reviews |
| GET `reviews/summary?products=id1,id2` | | Average and count per product |
| POST `reviews` | `{ product, rating /* 1-5 */, title, body, name, email }` | `{ ok, published, verified }` |
| GET `search?q=&limit=` | | Pages, products and posts that match |

## Customer accounts

Account calls use an HttpOnly cookie on the shop's own host and refuse requests from other origins. They work on the site's own address only (under `/_vorjo/account/…`), not on the API host. Accounts are on unless the owner turns them off in **Settings › Checkout**.

| Method and path | Body | Returns |
| --- | --- | --- |
| GET `/_vorjo/account/me` | | `{ customer: { name, email, phone, address, marketing } \| null }` |
| POST `/_vorjo/account/register` | `{ name, email, password /* 8+ */, marketing? }` | Creates the account and signs in |
| POST `/_vorjo/account/login` | `{ email, password }` | Signs in |
| POST `/_vorjo/account/logout` | | Signs out |
| PUT `/_vorjo/account/me` | `{ name?, phone?, address?, marketing? }` | `{ customer }` |
| GET `/_vorjo/account/orders` | | Every order placed with the account's email |
| POST `/_vorjo/account/password` | `{ current, password }` | Changes the password and signs out other devices |
| POST `/_vorjo/account/reset/start` | `{ email }` | Emails a 6-digit code |
| POST `/_vorjo/account/reset/finish` | `{ email, code, password }` | Sets a new password |
| POST `/_vorjo/account/delete` | `{ password }` | Closes the account (orders stay with the shop) |

## The admin API

The admin panel uses a separate, signed-in API under `/api/p/:projectId/manage/…`, with a permission per staff member: catalog routes need `products`, orders, customers and stats need `orders`, store settings need `settings`, and the blog needs `blog`. It isn't open to third parties. Hosted Gears reach the same routes at `https://api.vorjo.com/v1/admin/…` with an access token, limited to the permissions the owner accepted: see [Build a Gear (hosted apps)](/developers/gears-hosted).

### Products and inventory

| Method and path | Body | Returns |
| --- | --- | --- |
| GET `store/products?q=&status=&collection=` | | `{ products: Product[] }` with the list extras |
| POST `store/products` | `Product` (no ids needed; variants without an id are new) | `{ product }` |
| GET `store/products/:id` | | `{ product }` |
| PUT `store/products/:id` | The full `Product` (variants with an id are updated, missing ones removed, no id = new) | `{ product }` |
| DELETE `store/products/:id` | | `{ ok }` |
| POST `store/products/:id/duplicate` | | `{ product }` |
| POST `store/products/bulk` | `{ ids, status?, delete? }` | `{ ok }` |
| GET `store/inventory?q=&low=1` | | `{ items: [{ variantId, productId, productTitle, variantTitle, sku, image, inventory, trackInventory, allowBackorder }] }` |
| POST `store/inventory/:variantId` | `{ set?: number, delta?: number, reason?: string }` | `{ inventory }` |
| GET `store/inventory/:variantId/history` | | `{ events: [{ at, delta, after, reason, by }] }` |
| GET `store/collections` / POST / PUT `:id` / DELETE `:id` | `Collection` | `{ collections }` / `{ collection }` |
| GET `digital/products/:id` | | `{ files: [{ id, name, size, type }], keys: { available, used }, settings, maxFile }` |
| POST `digital/products/:id/files?name=<file name>` | The file itself (raw body) | `{ file }` (private; up to the plan's size: Free 50 MB, Starter 500 MB, Pro 2 GB) |
| DELETE `digital/products/:id/files/:fileId` | | `{ ok }` |

### Orders and customers

| Method and path | Body | Returns |
| --- | --- | --- |
| GET `store/orders?status=open|cancelled|archived|all&payment=&fulfillment=&q=` | | `{ orders: Order[] }` (without events) |
| GET `store/orders/:id` | | `{ order }` |
| PATCH `store/orders/:id` | `{ note?, tags?, archived? }` | `{ order }` |
| POST `store/orders/:id/fulfill` | `{ lines?: [{ lineId, qty }] /* empty = everything left */, carrier, trackingNumber, trackingUrl, notify }` | `{ order }` |
| POST `store/orders/:id/fulfillments/:fid/delivered` | | `{ order }` |
| POST `store/orders/:id/pay` | | `{ order }` (manual payments) |
| POST `store/orders/:id/refund` | `{ amount, reason, restock: [{ lineId, qty }], notify }` | `{ order }` (card payments are refunded through Stripe) |
| POST `store/orders/:id/cancel` | `{ restock: boolean, notify: boolean, reason }` | `{ order }` |
| POST `store/orders/:id/note` | `{ text }` | `{ order }` |
| GET `digital/orders/:id` | | `{ digital, paid, downloads: [{ lineId, title, licenceKey, expiresAt, expired, max, files: [{ id, name, size, used, left }] }] }` |
| POST `digital/orders/:id/resend` | | `{ ok }` (emails the download links again; an expired link gets a new period) |
| POST `digital/orders/:id/reset` | | `{ ok }` (download count back to zero, new period) |
| GET `store/customers?q=` | | `{ customers: Customer[] }` |
| GET `store/customers/:email` | | `{ customer, orders: Order[] }` |

### Discounts, settings, stats and the blog

| Method and path | Body | Returns |
| --- | --- | --- |
| GET `store/discounts` / POST / PUT `:id` / DELETE `:id` | `Discount` | `{ discounts }` / `{ discount }` |
| GET `store/sales` / POST / GET `:id` / PUT `:id` / DELETE `:id` | `Sale` (PUT changes only the fields sent) | `{ sales }` / `{ sale }` (each with `status`: `active`, `scheduled`, `ended` or `off`) |
| POST `store/sales/preview` | `Sale` (not saved) | `{ count, total, currency, examples: [{ productId, title, variantTitle, price, salePrice }] }`: what the draft would change, as if it were on now |
| GET `store/settings` / PUT `store/settings` | `StoreSettings` | `{ settings }` |
| GET `store/checkout` / PUT `store/checkout` | `{ name, logo, accent, font, radius, colors: { mode, background, surface, text, muted, border, accentText }, badges, banner, cartNote, thankYou, supportEmail, policies: [{ label, url }] }` | The look of the hosted checkout (`settings` permission). Colours are `#rrggbb`; anything else is dropped, and pairs that read badly are adjusted (PUT answers `fixes`, one line per change). GET also returns `site`, the site's own colours. |
| GET `store/stats?days=30` | | `{ series: [{ date, sales, orders }], totals: { sales, orders, aov, customers, returning, refunded }, top, lowStock, pending: { toFulfill, awaitingPayment } }` |
| GET `blog/posts?q=&status=&category=` / POST / GET `:id` / PUT `:id` / DELETE `:id` | `Post` (`category`: a category's slug) | `{ posts }` / `{ post }` |
| GET `blog/categories` / POST / PUT `:slug` / DELETE `:slug` | `{ name }` | `{ categories: [{ slug, name, count }] }` (deleting one clears its posts' category) |
| POST `upload?name=x.png` | The raw image as the body | `{ url }` |

### Admin shapes

The admin routes see more than the public API: drafts, costs, inventory history, and orders with their customers and timeline.

```ts
Product = { ...public fields, status: "active" | "draft" | "archived", createdAt, updatedAt,
  digitalSettings: { enabled, downloadLimit /* per file, default 5 */, expiryDays /* default 7 */, keys: "off" | "list" | "auto" } | null }
// POST/PUT store/products also take digitalSettings, and digitalKeysAdd: "KEY-1\nKEY-2" (licence keys added to the product's list)
Variant = { ...public fields, cost: number | null }
Discount = {
  id, code /* UPPERCASE */, type: "percent" | "fixed" | "free_shipping", value /* 10 = 10% or 10 money */,
  minSubtotal: number | null, startsAt: string | null, endsAt: string | null, usageLimit: number | null, used,
  oncePerCustomer: boolean, appliesTo: { kind: "all" | "collections" | "products", ids: string[] }, active: boolean,
}
Sale = {
  id, name, active: boolean, type: "percent" | "fixed",
  tiers: { min, max: number | null, value }[], // by the item's own price, e.g. [{ min: 5, max: 20, value: 10 }, { min: 20, max: null, value: 15 }];
                                               // or send just value: 10 for one amount on every price
  targets: { kind: "all" | "collections" | "products" | "variants", ids: string[] },
  excludes: { products: string[], variants: string[], collections: string[] },
  startsAt: string | null, endsAt: string | null /* the sale is over at endsAt */, priority /* breaks ties */,
  stacks: boolean /* discount codes apply on top */, countdown: boolean /* show "Sale ends in" (needs endsAt) */,
  gearId: string | null /* the Gear that made it */, createdBy,
}
// One sale per line: the one that saves the most (equal savings: higher priority, then the older sale). A sale price is never
// below 0 and is rounded to the currency. Saved product prices never change. A discount code skips lines whose sale has
// stacks: false. Orders keep originalPrice, salePrice and saleId on each line.
StoreSettings = {
  currency: "USD", pricesIncludeTax, taxShipping, defaultTaxRate /* percent */,
  taxes: { id, country /* ISO-2 */, region /* "" = whole country */, rate /* percent */, name }[],
  zones: { id, name, countries: string[] /* ["*"] = everywhere else */, regions: string[] /* [] = whole country */,
           rates: { id, name, price, minSubtotal, maxSubtotal, minWeight, maxWeight, freeOver, estimate /* "2-4 days" */ }[] }[],
  pickup: { enabled, locations: { id, name, address, hours }[] },
  manualPayment: { enabled, label /* "Cash on delivery" */, note },
  requirePhone, lowStock /* alert at or below */, orderNotes,
}
Order = {
  id, number /* 1001… */, status: "open" | "cancelled" | "archived",
  paymentStatus: "pending" | "paid" | "partially_refunded" | "refunded",
  fulfillmentStatus: "unfulfilled" | "partial" | "fulfilled" | "delivered",
  payment: "card" | "manual" | "gear:<id>", currency,
  lines: { id, productId, variantId, title, variantTitle, sku, image, price, qty, discount, tax, total, fulfilled, weight, digital? /* true: a download */ }[],
  subtotal, discountTotal, shippingTotal, taxTotal, total, refunded, discountCode: string | null,
  shippingMethod: { kind: "ship" | "pickup", name, price, estimate, rateId, locationId },
  customer: { name, email, phone }, shippingAddress: Address | null, billingAddress: Address | null /* only when different */,
  note /* the customer's checkout note */, internalNote /* staff only; PATCH { note } sets it */, tags: string[],
  fulfillments: { id, lines: { lineId, qty }[], carrier, trackingNumber, trackingUrl, status: "shipped" | "delivered", createdAt, deliveredAt }[],
  events: { at, kind: "placed" | "paid" | "fulfilled" | "delivered" | "refunded" | "cancelled" | "note" | "email" | "edited", text, by }[],
  test: boolean, createdAt,
}
Customer = { email, name, phone, orders, spent, firstOrderAt, lastOrderAt, lastAddress: Address | null }
Post = { ...public fields, status: "draft" | "published" | "scheduled", publishedAt /* in the future when scheduled */, createdAt, updatedAt }
```
