> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://schedule-docs.moxieservices.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://schedule-docs.moxieservices.com/_mcp/server.

# Admin portal flow

How the admin portal signs staff in and works with the API. All admin routes are under `/v1/admin`.

Rules an implementation must follow:

* Every `/v1/admin` call needs `Authorization: Bearer <token>` from `createAdminSession`. No cookies. The token lasts
  8 hours; on 401 `unauthenticated` sign in again.
* Read `me.permissions` and `me.offices` from the session (or `getMe`) to decide what to show, but the server checks
  every call again: 403 `forbidden` means the user lacks the permission or the office.
* Editable records carry `version`. Send the version you read with every save; 409 `version_conflict` means someone
  else saved first: reload and let the user redo the change. Single on/off switches (availability toggles) skip
  `version`.
* Lists are paged: pass `limit` (1 to 200, default 50) and the previous page's `nextCursor`; the last page has none.
* Creating with an `Idempotency-Key` (where offered) makes a retried click safe.
* Background work (FieldRoutes list refresh, ZIP pull) returns 202 with a Job: poll `getJob` until `succeeded` or
  `failed`.
* Settings sections (scheduling, route groups, abandoned cart, notifications, referrals, integrations) have one global
  value plus office overrides: read with `officeId` to get the office's effective value and where it came from.

## 1. Sign in

1. The portal gets a Google ID token from Google Sign-In (company accounts only).
2. `createAdminSession` — `POST /v1/admin/session` with `{"googleIdToken": "..."}`. In dev only, `{"testEmail":
   "test.admin@moxiepestcontrol.com"}` works without Google.
3. **201**: keep `token`; `me` has the user's permissions and offices. Send `Authorization: Bearer <token>` on every
   admin call.

`getMe` (`GET /v1/admin/me`) reloads the user, permissions and offices.

## 2. Show only what the user may use

Permissions are IDs with a level, for example `sub_manage: edit`, `disc_create: yes`. Edit includes view. Offices
limit what a user sees and changes: records in other offices are not found (404) and saves to them are refused (403).
Office pickers use `listOffices` and `listOfficeGroups`.

## 3. Edit a record

1. Read it (for example `getSubscriptionType`), keep its `version`.
2. Save the whole record with that `version` (for example `updateSubscriptionType`).
3. **409 `version_conflict`**: reload and redo. **422 `validation_failed`**: show each `fieldErrors[].field` next to
   its input.

## 4. Settings with office overrides

`GET` a section with `officeId` to see the office's effective value. Save the global value with `PUT` (needs every
office), override one office with `PUT .../offices/{officeId}`, and return it to the global value with `DELETE
.../offices/{officeId}`.

## 5. Background jobs

FieldRoutes list refreshes (`syncFieldRoutes`) and ZIP pulls (`pullServiceArea`) return **202** with a Job. Poll
`getJob` (`GET /v1/admin/jobs/{jobId}`) until `succeeded` (counts in `result`) or `failed` (`error`). Asking again
while one runs returns the same job.

## 6. Dashboard

`getDashboardSummary`, `listAbandonedCarts` and `listSetupAlerts` power the home page. Visits stay 0 until GA4 is
connected.