{
  "openapi": "3.1.0",
  "info": {
    "title": "Motmot Foundation Repair booking API",
    "version": "1.0.0",
    "description": "Book, find, move or cancel a free foundation inspection with Motmot Foundation Repair (San Antonio to Austin, Texas). The same API runs the booking page at https://motmotfoundationrepair.com/schedule/. An AI assistant may look up open times and book for a customer with the customer's own name, mobile number, email and property address. Viewing, moving or cancelling an existing appointment needs the 6-digit code that is sent to the customer's email or phone: ask the customer for it, never guess. Times are in America/Chicago. No API key. Please keep to a few requests a minute.",
    "contact": { "name": "Motmot Foundation Repair", "url": "https://motmotfoundationrepair.com/contact/", "email": "get@motmotfoundationrepair.com" }
  },
  "servers": [{ "url": "https://motmotfoundationrepair.com" }],
  "paths": {
    "/api/book/motmot/slots": {
      "get": {
        "operationId": "findOpenTimes",
        "summary": "Open inspection times for a property address (next 14 days)",
        "parameters": [
          { "name": "type", "in": "query", "required": true, "schema": { "type": "string", "enum": ["inspection"] }, "description": "Always inspection (the free foundation inspection)." },
          { "name": "address", "in": "query", "required": true, "schema": { "type": "string" }, "description": "The property address, street, city and ZIP.", "example": "123 Example St, San Antonio, TX 78209" },
          { "name": "from", "in": "query", "required": false, "schema": { "type": "string", "format": "date" }, "description": "Start day (YYYY-MM-DD) for later dates; use nextFrom from the previous answer." }
        ],
        "responses": {
          "200": { "description": "Open times. outOfArea: true means the address is outside the service area (call the office).", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Slots" } } } },
          "429": { "description": "Too many requests" }
        }
      }
    },
    "/api/book/motmot": {
      "post": {
        "operationId": "bookInspection",
        "summary": "Book a free inspection at an open time",
        "description": "Use an `at` value returned by findOpenTimes. Send a unique requestId per booking so a retry never books twice. The customer gets a confirmation by text and email.",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BookRequest" } } } },
        "responses": {
          "200": { "description": "Booked", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Booked" } } } },
          "400": { "description": "Refused (time taken, bad phone, outside the area). error says why in plain words.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "429": { "description": "Too many requests" }
        }
      }
    },
    "/api/book/motmot/lookup": {
      "post": {
        "operationId": "sendLookupCode",
        "summary": "Send the customer a 6-digit code to see their appointment",
        "description": "Sends a code to the email or mobile number, only if an upcoming appointment was booked with it. The answer is the same either way. Codes last 10 minutes; one every 30 seconds, 5 an hour.",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["contact"], "properties": { "contact": { "type": "string", "description": "Email or 10-digit US mobile number used to book." } } } } } },
        "responses": {
          "200": { "description": "Sent if there is a match", "content": { "application/json": { "schema": { "type": "object", "properties": { "ok": { "type": "boolean" }, "channel": { "type": "string", "enum": ["email", "sms"] } } } } } },
          "400": { "description": "Not an email or phone number", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "404": { "description": "Online lookup is switched off; send the customer to the link in their confirmation or the phone" },
          "429": { "description": "Asked too often", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/api/book/motmot/lookup/verify": {
      "post": {
        "operationId": "verifyLookupCode",
        "summary": "Trade the customer's code for their upcoming appointments",
        "description": "Each appointment carries c, a and t: pass them to getAppointment, rescheduleAppointment and cancelAppointment. Five wrong codes end the code; ask for a new one.",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["contact", "code"], "properties": { "contact": { "type": "string" }, "code": { "type": "string", "pattern": "^[0-9]{6}$" } } } } } },
        "responses": {
          "200": { "description": "The customer's upcoming appointments", "content": { "application/json": { "schema": { "type": "object", "properties": { "appointments": { "type": "array", "items": { "$ref": "#/components/schemas/Appointment" } } } } } } },
          "400": { "description": "The code is wrong, expired, used up, or was never sent (one answer for all)", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "404": { "description": "Online lookup is switched off" }
        }
      }
    },
    "/api/appt/manage": {
      "get": {
        "operationId": "getAppointment",
        "summary": "One appointment and the open times it can move to",
        "parameters": [
          { "name": "c", "in": "query", "required": true, "schema": { "type": "string" } },
          { "name": "a", "in": "query", "required": true, "schema": { "type": "string" } },
          { "name": "t", "in": "query", "required": true, "schema": { "type": "string" } }
        ],
        "responses": { "200": { "description": "The appointment; slots are the times it can move to; locked means it can no longer change online" }, "404": { "description": "Link no longer valid" } }
      }
    },
    "/api/appt/reschedule": {
      "post": {
        "operationId": "rescheduleAppointment",
        "summary": "Move an appointment to one of its open times",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["c", "a", "t", "at"], "properties": { "c": { "type": "string" }, "a": { "type": "string" }, "t": { "type": "string" }, "at": { "type": "string", "format": "date-time" } } } } } },
        "responses": { "200": { "description": "Moved; date and time are the new local time" }, "400": { "description": "Time not available" }, "409": { "description": "Can no longer change online" } }
      }
    },
    "/api/appt/cancel": {
      "post": {
        "operationId": "cancelAppointment",
        "summary": "Cancel an appointment (confirm with the customer first)",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["c", "a", "t"], "properties": { "c": { "type": "string" }, "a": { "type": "string" }, "t": { "type": "string" }, "reason": { "type": "string", "maxLength": 300 } } } } } },
        "responses": { "200": { "description": "Cancelled (already: true if it was)" }, "409": { "description": "Can no longer change online" } }
      }
    }
  },
  "components": {
    "schemas": {
      "Slot": { "type": "object", "properties": { "at": { "type": "string", "format": "date-time", "description": "Send this value as `at` to book." }, "date": { "type": "string", "example": "Mon, Nov 23" }, "time": { "type": "string", "example": "9:00 AM" }, "nearby": { "type": "boolean", "description": "An inspector is already working near this address that day." } } },
      "Slots": { "type": "object", "properties": { "slots": { "type": "array", "items": { "$ref": "#/components/schemas/Slot" } }, "nextFrom": { "type": ["string", "null"] }, "outOfArea": { "type": "boolean" }, "needAddress": { "type": "boolean" } } },
      "BookRequest": { "type": "object", "required": ["type", "at", "name", "phone", "address"], "properties": {
        "type": { "type": "string", "enum": ["inspection"] },
        "at": { "type": "string", "format": "date-time" },
        "name": { "type": "string" },
        "phone": { "type": "string", "description": "The customer's US mobile number. The customer agrees to appointment texts (STOP to opt out)." },
        "email": { "type": "string", "format": "email" },
        "address": { "type": "string" },
        "notes": { "type": "string", "maxLength": 5000, "description": "What the customer is noticing (cracks, sticking doors, sloping floors), gate codes, pets." },
        "requestId": { "type": "string", "description": "A unique id for this booking attempt." }
      } },
      "Booked": { "type": "object", "properties": { "ok": { "type": "boolean" }, "when": { "type": "object", "properties": { "date": { "type": "string" }, "time": { "type": "string" } } }, "type": { "type": "string" }, "ics": { "type": "string", "description": "Calendar file link" }, "confirmation": { "type": "object", "properties": { "sent": { "type": "boolean" }, "sms": { "type": "boolean" }, "email": { "type": "boolean" } } } } },
      "Appointment": { "type": "object", "properties": { "type": { "type": "string" }, "date": { "type": "string" }, "time": { "type": "string" }, "address": { "type": "string" }, "at": { "type": "string", "format": "date-time" }, "c": { "type": "string" }, "a": { "type": "string" }, "t": { "type": "string" } } },
      "Error": { "type": "object", "properties": { "error": { "type": "string" } } }
    }
  }
}
