> 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.

# Customer booking flow

How the booking site takes a homeowner from an address to a booked first appointment. Every call below is under
`https://schedule-api-dev.moxieservices.com` (dev) or `https://schedule-api.moxieservices.com` (prod).

Signup states and how they change:

* A new signup is a draft (no status yet). `completeSignup` moves it to `processing`.
* `processing` ends in `awaiting_appointment` (paid; go to the appointment step), `payment_declined` (back to the card
  step) or `failed` (show the reference and a Try again button; `completeSignup` again with a new Idempotency-Key).
* `scheduleAppointment` moves `awaiting_appointment` or `slot_unavailable` to `processing` again, which ends in
  `complete` (confirmation page), `slot_unavailable` (back to the calendar) or `awaiting_appointment` with an `error`
  (booking failed; let them try again).
* `step` on the draft only moves forward: address, property, contact, services, agreement, payment, appointment,
  complete.

Rules an implementation must follow:

* Send `X-Link-Token` on every `/v1/signup/{signupId}` call. A wrong token and an unknown signup both return 404;
  an expired signup (30 days) returns 410.
* Use a new `Idempotency-Key` for each Order Complete attempt (each click). Reuse it only to retry the same attempt
  after a network error. Reusing a key with a different body returns 409 `idempotency_mismatch`.
* After `createSignup`, always save the latest `linkToken`: a retried create returns a new token.
* Never send prices: the server computes them. Always create a quote right before Order Complete and confirm any
  price change the server reports.
* Poll `getSignupStatus` about once a second while the state is `processing`; stop on any other state.

## 1. Show the catalog for the address

`getCatalog` — `GET /v1/public/catalog?zip=75001`

Returns the office serving the ZIP with its plans, add-ons and pests. Add `homeSqft` to get each plan's price for
that home. **422 `zip_not_serviced`**: stay on the address step and ask for another address.

## 2. Start the signup

`createSignup` — `POST /v1/signup` with the address

* Headers: `CF-Turnstile-Response` (Cloudflare Turnstile), optional `Idempotency-Key`.
* **201**: keep `signupId` and `linkToken`; `resumeUrl` lets the customer come back later.
* **409 `existing_customer`**: the address is already a customer; show `details.callCenterPhone`. No signup was
  created.

## 3. Save each step

`updateSignup` — `PATCH /v1/signup/{signupId}` with `X-Link-Token`

Send what the step collected: `property`, `contact`, `pestIds`, `planId`, `smsConsent`, and the `step` reached. The
server works out the add-ons from the pests and plan. Resume with `getSignup`.

## 4. Price it

`createQuote` — `POST /v1/signup/{signupId}/quote`

Freezes the prices for 24 hours. 422 names anything missing (property, contact, plan). Optional discount:
`applyDiscountCode` / `removeDiscountCode` (`PUT` / `DELETE /v1/signup/{signupId}/discount`); every refusal is the
same 422 `discount_not_applicable`.

## 5. Agreement and card

Show the terms from `getCurrentTerms` (`GET /v1/public/terms/current`). The card goes into the payment provider's
form, which returns a token; card details never reach the API.

## 6. Order Complete

`completeSignup` — `POST /v1/signup/{signupId}/complete`

* Headers: `X-Link-Token`, a new `Idempotency-Key`, `CF-Turnstile-Response`.
* Body: the quote ID, the payment token, the terms version and the signature.
* **202**: poll `getSignupStatus` (`GET /v1/signup/{signupId}/status`) about once a second.
* **409 `price_changed`, `quote_expired`, `item_unavailable`**: show old and new totals from `details.quote`, let the
  customer confirm, then try again with a new `Idempotency-Key`.

| Status ends in         | Show                                                         |
| ---------------------- | ------------------------------------------------------------ |
| `awaiting_appointment` | The appointment step                                         |
| `payment_declined`     | The card step again                                          |
| `failed`               | The reference and a Try again button (`error.code` says why) |

## 7. Book the first appointment

1. `getAvailability` — `GET /v1/signup/{signupId}/availability`: dates with their morning and afternoon windows.
   Empty `options` comes with `routesFullMessage`: show it instead of a calendar. **503 `fieldroutes_unavailable`**:
   offer Retry.
2. `scheduleAppointment` — `PUT /v1/signup/{signupId}/appointment` with `{"date", "slot": "am" | "pm"}`. **202**,
   then poll `getSignupStatus`.

| Status ends in                      | Show                                                                          |
| ----------------------------------- | ----------------------------------------------------------------------------- |
| `complete`                          | The confirmation page (`confirmation`, `accountNumber`, `confirmationSentTo`) |
| `slot_unavailable`                  | The calendar again                                                            |
| `awaiting_appointment` with `error` | The calendar with the error; let them try again                               |

`resendConfirmation` (`POST /v1/signup/{signupId}/resend-confirmation`) resends the email, 3 times an hour.

## Errors

Every error has the same shape: `code`, `message`, `requestId`, and `fieldErrors` for invalid fields. **429
`rate_limited`**: wait and retry. **404** / **410 `link_expired`**: show a start-over screen.