# Yatoon Menu REST API — 4.2.0

Base address: `https://your-site.com/wp-json/yatoon/v1/`

The API uses the standard WordPress REST API. Responses are JSON. Money is a string with the currency's decimals (`"12.50"`, `"1200"` for JPY). Times are RFC 3339 in UTC (`2026-12-03T15:00:00Z`). Dates for reservations are the restaurant's local `YYYY-MM-DD`.

## Authentication

| Routes | Who |
| --- | --- |
| `GET /store`, `GET /menu`, `GET /menu/items/{id}` | Anyone, unless the owner turns the public API off under **Yatoon Menu → API & webhooks**. |
| `POST /orders/quote` | Same as the menu: anyone while the public API is on. |
| `POST /orders` | Order managers (`yatoon_manage_orders`). Customer apps without sign-in only when the owner turns on *Let customer apps place pay-in-person orders*. |
| Reading and updating orders | Users with the kitchen (`yatoon_manage_kitchen`) or order (`yatoon_manage_orders`) capability. Phone, email and delivery address are returned to order managers only. |
| Cancel order, collect payment | Order managers (`yatoon_manage_orders`). |
| Reservations | `yatoon_manage_reservations`. |
| Change a dish | Menu managers (`yatoon_manage_menu`). |

Administrators can use every route. For an app or integration:

1. Create a WordPress user with the lowest role it needs (not an administrator).
2. Add an **Application Password** for that user under *Users → Profile*.
3. Call the API over HTTPS with Basic authentication:

```bash
curl -u "kitchen-app:abcd efgh ijkl mnop qrst uvwx" \
  "https://your-site.com/wp-json/yatoon/v1/orders?status=new,preparing"
```

JavaScript running on the same site can use the logged-in cookie and an `X-WP-Nonce` header created with `wp_create_nonce( 'wp_rest' )`.

Every write goes through the same code as the dashboard: the same permission checks, inventory locks, notifications, loyalty and POS sync.

## Store

`GET /store`

```json
{
  "name": "Yatoon Noodle Bar",
  "address": "1 Main St, Indianapolis, IN",
  "phone": "+1 317 555 0100",
  "website": "https://your-site.com/",
  "logo": "https://your-site.com/wp-content/uploads/logo.png",
  "timezone": "America/Indiana/Indianapolis",
  "currency": { "code": "USD", "symbol": "$", "decimals": 2 },
  "ordering": {
    "enabled": true,
    "accepting_orders": true,
    "message": "",
    "hours": "11:00 AM – 9:00 PM",
    "fulfillment_types": [ { "type": "pickup", "label": "Pickup" }, { "type": "delivery", "label": "Delivery" } ]
  },
  "locations": [ { "key": "main", "name": "Downtown", "hours": "", "address": "", "phone": "", "website": "" } ],
  "pages": { "menu": "https://your-site.com/order/", "order_status": "https://your-site.com/order-status/", "reservations": null },
  "api_version": 1
}
```

## Menu

`GET /menu`

| Parameter | Description |
| --- | --- |
| `lang` | Dish text in another language, e.g. `zh_CN`, `es_MX`. Untranslated text falls back to the original. |
| `location` | Only dishes offered at this location key (dishes offered everywhere are always included). Without it, every visible dish is returned and each carries its `locations`. |
| `include_hidden` | Menu managers only: include hidden dishes, with stock and visibility. |

```json
{
  "currency": "USD",
  "language": null,
  "categories": [
    {
      "name": "Soups",
      "items": [
        {
          "id": 7,
          "name": "Beef Pho",
          "description": "Slow-cooked broth, rice noodles.",
          "category": "Soups",
          "price": "12.50",
          "image": "https://…/pho.jpg",
          "featured": true,
          "tags": [ "spicy" ],
          "allergens": [ { "key": "peanuts", "label": "Peanuts" } ],
          "options": [
            { "id": "g-1a2b", "name": "Size", "required": true, "max": 1,
              "options": [ { "id": "o-3c4d", "name": "Large", "price": "2.00" } ] }
          ],
          "max_per_order": 10,
          "in_stock": true,
          "available_now": true,
          "locations": []
        }
      ]
    }
  ]
}
```

`GET /menu/items/{id}` returns one dish (hidden dishes return 404 except to menu managers).

### Change a dish

`POST /menu/items/{id}` (menu managers). Send any of:

| Field | Effect |
| --- | --- |
| `price` | New price. |
| `stock` | Stock count. `0` = sold out, `null` = unlimited. |
| `visible` | `false` hides the dish, `true` shows it. |
| `sold_out_today` | `true` marks it sold out until midnight (restaurant time), `false` makes it available again. |

The response is the dish with manager fields (`visible`, `stock`, `sold_out_until`). Fields are applied one after another; if one is refused, earlier fields in the same request are already saved.

## Orders

### Place an order

`POST /orders` places a pay-in-person order (`cash`, or `manual` for other offline payment). Orders go through exactly the same checks as the website checkout: opening hours, stock, required options, delivery area and minimums, coupons, kitchen capacity and time slots. The kitchen, printers, notifications and webhooks see them like any other order.

Online card payments are not taken through the API: send customers to the website checkout for those.

```bash
curl -u "pos:abcd efgh ijkl mnop qrst uvwx" -H "Content-Type: application/json" \
  -H "Idempotency-Key: pos2-20261203-000123" \
  -d @order.json "https://your-site.com/wp-json/yatoon/v1/orders"
```

```json
{
  "items": [
    { "item_id": 7, "quantity": 2, "instructions": "No onion",
      "options": [ { "group": "Size", "option": "Large" }, { "group_id": "g12", "option_id": "o3" } ] }
  ],
  "customer": { "name": "Ann Lee", "phone": "+1 317 555 0123", "email": "ann@example.com" },
  "fulfillment": { "type": "pickup", "time": "ASAP", "location_key": "main" },
  "notes": "Call when ready",
  "coupon": "",
  "tip": "4.00",
  "payment": { "method": "cash", "paid": false },
  "language": "en_US",
  "marketing": { "email": false, "sms": false }
}
```

| Field | Description |
| --- | --- |
| `items` | Required. `item_id` and `quantity` from `GET /menu`. Options by `group` and `option` name, or by `group_id` and `option_id`. |
| `customer` | `name`, `phone`, `email`, `phone_country` (two letters, for numbers without a country code). The website's contact rules apply. |
| `fulfillment` | `type`: `pickup`, `delivery` or `dinein`. `time`: `ASAP`, a restaurant-local time (`2026-12-03T18:30`) or RFC 3339 with an offset. `location_key`, `table` (dine-in), `delivery_address`, `delivery_postcode`. |
| `payment` | `method`: `cash` (default) or `manual`. `paid: true` records the payment straight away (order managers, for example a POS that already took the money). |
| `language` | Language for the customer's messages, one of the restaurant's languages. |
| `bot_token`, `otp_token` | Customer apps only: the Turnstile/hCaptcha token and the SMS verification token, when the restaurant uses them on the website. |
| `source`, `external_ref` | Order managers: where the order came from (`pos`, `ubereats`, `doordash`, `deliveroo`…: 2–40 lowercase letters, digits, `-` or `_`) and its ID there. The same `source` and `external_ref` always return the first order (`200`, `"existing": true`), whichever account sends it. Without `source`, staff orders are `api` and customer-app orders `app`. |

**Idempotency-Key** (header, 16–100 letters, digits, `-` or `_`): send a unique value per order. If a timeout makes you send the same order again with the same key, you get the first order back (`200`, `"existing": true`) instead of a duplicate.

When a pay-in-person order was saved but payment could not be recorded, the response includes a warning and the order still shows `pending`. Retry the original request with the same idempotency key or external reference. An identical request with `paid: true` can finish recording the payment without creating a second order.

Response `201`:

```json
{
  "order": { "id": 1043, "number": "K7Q2M9XB", "status": "new", "…": "same shape as GET /orders/{id}" },
  "tracking": { "key": "9b1f…", "url": "https://your-site.com/order-status/?order=K7Q2M9XB&key=9b1f…" },
  "existing": false,
  "warnings": []
}
```

Orders entered by staff belong to the guest (not to the staff account) and are marked as API orders. Rate limits: 120 orders per 5 minutes per address for staff, 12 for customer apps.

### Price a cart

`POST /orders/quote` takes the same body and returns the lines, `totals` (subtotal, discount, tax, tip, fees, total), the coupon that applies and the `fulfillment` time the order would get, without saving anything or needing customer details.

### List orders

`GET /orders`

| Parameter | Description |
| --- | --- |
| `status` | Comma-separated: `new`, `preparing`, `ready`, `done`, `cancelled`, `awaiting_payment`, `payment_attention`, `payment_expired`. |
| `after`, `before` | Creation time range (RFC 3339). |
| `search` | Order number or its beginning. |
| `since_id` | Orders with a larger ID, oldest first. Remember the last ID you saw to poll for new orders. |
| `updated_after` | Orders changed at or after this time (RFC 3339), oldest change first. Poll with the last `updated_at` you saw to pick up status and payment changes; the same order can come back, so match on `id`. |
| `source`, `external_ref` | Only orders from one source (`website`, `app`, `api` or an integration name), or the order with this external ID. |
| `page`, `per_page` | Paging (max 100). Totals are in the `X-WP-Total` and `X-WP-TotalPages` headers. |

```json
{
  "id": 1042,
  "number": "K7Q2M9XA",
  "status": "new",
  "payment": { "status": "paid", "method": "card" },
  "fulfillment": {
    "type": "delivery",
    "time": "Today 6:30 PM",
    "location": "Downtown",
    "location_key": "main",
    "table": "",
    "delivery_address": "12 Oak St",
    "delivery_postcode": "46204",
    "estimated_ready_at": "2026-12-03T23:15:00Z"
  },
  "customer": { "name": "Ann Lee", "phone": "+13175550123", "email": "ann@example.com" },
  "items": [
    { "item_id": 7, "name": "Beef Pho", "quantity": 2, "unit_price": "14.50", "line_total": "29.00",
      "options": [ { "group": "Size", "name": "Large", "price": "2.00" } ], "instructions": "No onion" }
  ],
  "totals": { "currency": "USD", "subtotal": "29.00", "discount": "0.00", "tax": "2.03", "tip": "4.00", "fees": "3.99", "total": "39.02" },
  "coupon": "",
  "notes": "",
  "language": "en_US",
  "test": false,
  "created_at": "2026-12-03T22:58:41Z",
  "updated_at": "2026-12-03T23:04:10Z",
  "source": "website",
  "external_ref": ""
}
```

`GET /orders/{id}` returns one order.

### Kitchen status

`POST /orders/{id}/status` with `status` = `preparing`, `ready` or `done`.

- `expected`: the status you last saw. If another device already moved the order, the request fails with `409` instead of overwriting.
- `undo`: `true` lets an order manager move an order back a step.

Customers receive the same notifications as when staff use the kitchen display.

### Cancel, collect payment

- `POST /orders/{id}/cancel`: `reason`, `restock` (`true` returns the dishes to stock), `expected`. Only unpaid pay-in-person orders (and gift-card orders) can be cancelled here; online payments are refunded with the payment provider.
- `POST /orders/{id}/collect-payment`: records a pay-in-person payment.

## Reservations

- `GET /reservations?from=2026-12-01&to=2026-12-07&status=pending,confirmed` (paged like orders, earliest first).
- `GET /reservations/{id}`
- `POST /reservations/{id}/status` with `status` (`pending`, `confirmed`, `seated`, `completed`, `cancelled`, `no_show`, as configured), optional `table`, and `expected` / `version` to avoid overwriting another device's change.

## Errors

Errors use the WordPress format:

```json
{ "code": "yatoon_conflict", "message": "Another device changed this order. Refresh before cancelling it.", "data": { "status": 409 } }
```

| HTTP | Meaning |
| --- | --- |
| 400 | Invalid value or a change that is not allowed in the current state. |
| 401 / 403 | Not signed in, or the user lacks the capability. |
| 404 | Order, reservation or dish not found. |
| 409 | Someone else changed it first, checkout is busy, or the order cannot be placed right now (closed, time full, out of stock). The message says which. |
| 429 | Too many requests from this address; wait a few minutes. |
| 503 | The order could not be saved; try again with the same `Idempotency-Key`. |

## Webhooks (Pro)

Add addresses under **Yatoon Menu → API & webhooks**. Events:

| Event | When |
| --- | --- |
| `order.created` | An order is accepted (paid online, or pay in person). |
| `order.status_changed` | Preparing, ready, completed or cancelled. |
| `order.payment_collected` | A pay-in-person payment is recorded. |
| `order.payment_adjusted` | A refund or dispute is recorded. |
| `reservation.created` | A reservation request arrives. |
| `reservation.updated` | Confirmed, changed, cancelled or expired (`change` field). |
| `menu.item_updated` | A dish is saved or changed in bulk. Several changes to one dish within a few seconds arrive as one delivery with the dish as it is then. |

Body:

```json
{ "id": "evt_9f2c…", "type": "order.created", "created": "2026-12-03T22:58:42Z", "site": "https://your-site.com/", "data": { "object": { …order as in GET /orders/{id}… } } }
```

Headers: `X-Yatoon-Event`, `X-Yatoon-Delivery` (the event ID; use it to ignore duplicates) and `X-Yatoon-Signature: t=<unix time>,v1=<signature>`.

Verify the signature: compute HMAC-SHA256 of `"<t>.<raw request body>"` with the webhook's signing secret, compare it to `v1` in constant time, and reject old timestamps (for example older than 5 minutes).

```php
[ $t, $v1 ] = sscanf( $_SERVER['HTTP_X_YATOON_SIGNATURE'], 't=%d,v1=%s' );
$valid = abs( time() - $t ) < 300 && hash_equals( hash_hmac( 'sha256', $t . '.' . file_get_contents( 'php://input' ), $secret ), $v1 );
```

Answer with any 2xx status within 10 seconds. Otherwise the delivery is retried up to five times with growing delays; failures appear under **Operations & health**. Addresses must be public `https://` URLs.

## Blocks and page builders

The same restaurant components are available as blocks (category *Yatoon Restaurant*) and as widgets in Elementor, Beaver Builder, Bricks, Brizy, Divi and WPBakery. They render exactly like the shortcodes; use each one once per page.

In Brizy the elements show your real menu while you edit (clicks are disabled in the editor) and have Brizy toolbar settings. Other builders show a placeholder while editing; open the published page to see the live menu.

### Widget options

Each placement can change a few things without touching the restaurant-wide settings. They are available in the block sidebar, Elementor, Brizy and WPBakery, and as shortcode attributes:

| Option | Components | Values |
| --- | --- | --- |
| `categories` | Menu | Category names separated by commas. Only these categories are shown (for example a drinks page). |
| `hide_hero`, `hide_featured`, `hide_search` | Menu | `1` hides the promotion banner, the featured dishes or the search box. |
| `layout` | Menu | `single`, `auto2`, `columns3`, `columns4` or `auto3` columns on wide screens. |
| `accent`, `button_color` | Menu | A hex color, for example `#c2410c`. |
| `max_width` | Menu, order tracking, reservations, gift cards | Width in pixels; the component is centred. |

```
[yatoon_menu categories="Drinks, Desserts" layout="auto2" hide_hero="1" max_width="960"]
```
