{"openapi":"3.0.3","info":{"title":"Studio CMS API","description":"Content Management Service API for the Studio platform. Provides endpoints for app configuration, content retrieval, lead capture, analytics events, and API token management.","version":"1.0.0","contact":{"name":"XAPP AI","url":"https://xapp.ai"},"license":{"name":"Proprietary"}},"servers":[{"url":"https://api.xapp.ai"}],"security":[],"paths":{"/availability/v1/businesses/{appId}/windows":{"get":{"operationId":"getAvailabilityWindows","summary":"Arrival windows a business offers","description":"The arrival windows a business offers over a date range, one entry per window per availability class. Windows come from the business's own policy (default two 4-hour windows, 08:00-12:00 and 13:00-17:00), capped per class per window and per day, and, when the business turns holds on, reduced by the requested windows of its open leads. Full windows are omitted. Every window is a request the business confirms (`confirmation: business_confirms`); none is a guaranteed appointment.\n\nOnly businesses enabled for the Availability API answer; others return 404. Takes a CMS API key with the `read:availability` scope (its own business only), or an XAPP-issued `search:availability` key (any enabled business).","tags":["Availability"],"security":[{"CmsApiToken":[]}],"parameters":[{"name":"appId","in":"path","required":true,"description":"The business (app) id.","schema":{"type":"string","maxLength":100}},{"name":"from","in":"query","required":false,"description":"First date, YYYY-MM-DD in the business timezone. Defaults to today.","schema":{"type":"string","format":"date"}},{"name":"to","in":"query","required":false,"description":"Last date, inclusive. Defaults to 14 days from `from`. At most 62 days.","schema":{"type":"string","format":"date"}},{"name":"classId","in":"query","required":false,"description":"Comma-separated availability class ids (see /services).","schema":{"type":"string","maxLength":500}},{"name":"service","in":"query","required":false,"description":"Free text matched against the classes' names and summaries, e.g. `leaking sink`.","schema":{"type":"string","maxLength":200}},{"name":"origin","in":"query","required":false,"description":"Stamped on each booking link: `ai_mode`, `therightpro`, `rwg` or `agent`.","schema":{"type":"string","enum":["ai_mode","therightpro","rwg","agent"]}}],"responses":{"200":{"description":"The business's windows.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AvailabilityWindowsResponse"},"examples":{"twoWindows":{"summary":"A Monday morning and afternoon","value":{"businessId":"app-1","timeZone":"America/New_York","asOf":"2026-11-16T11:00:00.000Z","windows":[{"start":"2026-11-16T08:00:00-05:00","end":"2026-11-16T12:00:00-05:00","status":"limited","basis":"policy","confirmation":"business_confirms","classId":"repair","remaining":1,"bookingUrl":"https://book.xapp.ai/?key=KEY&environment=production&origin=ai_mode&placeId=PLACE&window=2026-11-16T08%3A00%3A00-05%3A00%2F2026-11-16T12%3A00%3A00-05%3A00"},{"start":"2026-11-16T13:00:00-05:00","end":"2026-11-16T17:00:00-05:00","status":"open","basis":"policy","confirmation":"business_confirms","classId":"repair","remaining":2}]}}}}}},"400":{"description":"Bad date range.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"The key lacks read:availability.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Unknown business, or not enabled for the Availability API.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/availability/v1/businesses/{appId}/services":{"get":{"operationId":"getAvailabilityServices","summary":"Bookable services (availability classes) of a business","description":"The availability classes a caller can ask windows for. Lead-only classes (quotes that need follow-up) are left out. Only businesses enabled for the Availability API answer. Takes a `read:availability` key (its own business) or a `search:availability` key (any enabled business).","tags":["Availability"],"security":[{"CmsApiToken":[]}],"parameters":[{"name":"appId","in":"path","required":true,"description":"The business (app) id.","schema":{"type":"string","maxLength":100}}],"responses":{"200":{"description":"The business's bookable classes.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AvailabilityServicesResponse"}}}},"403":{"description":"The key lacks read:availability.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Unknown business, or not enabled for the Availability API.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/availability/v1/windows/search":{"get":{"operationId":"searchAvailabilityWindows","summary":"Search arrival windows across businesses","description":"Businesses enabled for the Availability API with an open arrival window, sorted by their earliest window and then by distance. A business is enabled unless it turned the API off, and only while it is a customer business (not a demo or internal app) on a plan that allows partner booking, with a booking form and a Google place. Windows are computed from each business's current settings when you search, so `asOf` is the time of the request; windows that have started are left out. Needs a `search:availability` key, which XAPP issues for partners and its own surfaces.","tags":["Availability"],"security":[{"CmsApiToken":[]}],"parameters":[{"name":"vertical","in":"query","required":false,"description":"A business type, e.g. `plumber` (Google place types and the business's own).","schema":{"type":"string","maxLength":100}},{"name":"classId","in":"query","required":false,"description":"Comma-separated availability class ids.","schema":{"type":"string","maxLength":500}},{"name":"service","in":"query","required":false,"description":"Free text matched against the businesses' class names and summaries, e.g. `leaking sink`.","schema":{"type":"string","maxLength":200}},{"name":"zip","in":"query","required":false,"description":"A postal code the business is listed at.","schema":{"type":"string","maxLength":10}},{"name":"lat","in":"query","required":false,"description":"Latitude; give with `lng`.","schema":{"type":"number","minimum":-90,"maximum":90}},{"name":"lng","in":"query","required":false,"description":"Longitude; give with `lat`.","schema":{"type":"number","minimum":-180,"maximum":180}},{"name":"radiusMiles","in":"query","required":false,"description":"Distance from `lat`,`lng`. Default 25.","schema":{"type":"number","minimum":0,"maximum":100}},{"name":"from","in":"query","required":false,"description":"First day, YYYY-MM-DD, in each business's timezone.","schema":{"type":"string","format":"date"}},{"name":"to","in":"query","required":false,"description":"Last day, YYYY-MM-DD, inclusive. At most 62 days after `from`.","schema":{"type":"string","format":"date"}},{"name":"earliest","in":"query","required":false,"description":"`true` returns only each business's earliest window.","schema":{"type":"boolean"}},{"name":"limit","in":"query","required":false,"description":"Results per page. Default 20.","schema":{"type":"integer","minimum":1,"maximum":100}},{"name":"cursor","in":"query","required":false,"description":"`nextCursor` from the previous page.","schema":{"type":"string"}},{"name":"origin","in":"query","required":false,"description":"Stamped on the booking links.","schema":{"type":"string","enum":["ai_mode","therightpro","rwg","agent"]}}],"responses":{"200":{"description":"Matching businesses and their windows.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AvailabilitySearchResponse"}}}},"400":{"description":"Bad query: coordinates, radius, limit, dates or cursor.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"The key lacks search:availability.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/cms/app/{appId}/leads/echo-check":{"get":{"operationId":"echoCheck","summary":"Check for echo leads","description":"Checks if a lead with matching contact info (email/phone) was recently captured and successfully sent to an integration (e.g., Jobber). Used by agent-server to detect 'echo leads' — CRM notification emails that bounce back through email capture, which would otherwise create duplicate leads.\n\nReturns `isEcho: true` with the matched lead details if a recent lead with matching contact info was sent to an integration within the time window.","tags":["Leads"],"security":[{"ApiGatewayKey":[]}],"parameters":[{"name":"appId","in":"path","required":true,"description":"The application ID to check for echo leads.","schema":{"type":"string","maxLength":100}},{"name":"email","in":"query","required":false,"description":"Email address to match against recent leads. At least one of `email` or `phone` is required.","schema":{"type":"string","maxLength":500}},{"name":"phone","in":"query","required":false,"description":"Phone number to match against recent leads. Comparison is digits-only. At least one of `email` or `phone` is required.","schema":{"type":"string","maxLength":500}},{"name":"windowMinutes","in":"query","required":false,"description":"How far back to look for matching leads, in minutes. Values outside 1-1440 are clamped, not refused.","schema":{"type":"integer","default":120,"maximum":1440}}],"responses":{"200":{"description":"Echo check result.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/EchoCheckResult"},"examples":{"echoDetected":{"summary":"Echo detected — lead matches recent integration send","value":{"isEcho":true,"matchedLeadId":"fa10b3fc-0a59-40fb-b18c-70e70c583a05","matchedLeadDate":"2026-06-05T14:30:00.000Z","matchedIntegrationId":"jobber-tenant-123"}},"noEcho":{"summary":"No echo — this is a new lead","value":{"isEcho":false}}}}}},"400":{"description":"Validation error (missing email and phone).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/cms/app/{appId}/leads":{"put":{"operationId":"publicLeadSubmission","summary":"Submit or update a lead","description":"Public endpoint for submitting new leads or updating existing ones. Supports upsert via `leadId` or `sessionId` — if a matching lead is found, fields are merged (new fields added, existing fields overwritten, untouched fields kept). Supports partial saves where `submitted: false` indicates the lead is still being built up (e.g., during a chat conversation).\n\nField names are automatically normalized to canonical uppercase form (e.g., `email` → `EMAIL`, `phone` → `PHONE`).\n\nRate limited to 10 requests/second with burst capacity of 20. An existing lead is found by `leadId`, then by `sessionId`. When neither finds one, a new lead is created under a fresh id; a supplied `leadId` is not used for it. `fields` may be empty when `submitted` or `deliver` is false. More than 50 fields after merging with the stored lead is a 400.","tags":["Leads"],"security":[],"parameters":[{"name":"appId","in":"path","required":true,"description":"The application ID to submit the lead for.","schema":{"type":"string","maxLength":100}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PublicLeadSubmissionRequest"},"examples":{"newLead":{"summary":"Create a new lead","value":{"lead":{"sessionId":"chat-session-abc123","source":"chat-widget","fields":[{"name":"name","value":"Jane Smith"},{"name":"phone","value":"555-1234"},{"name":"email","value":"jane@example.com"}]}}},"partialLead":{"summary":"Submit a partial lead (still being built)","value":{"lead":{"sessionId":"chat-session-abc123","source":"chat-widget","fields":[{"name":"name","value":"Jane Smith"}]},"submitted":false}},"updateByLeadId":{"summary":"Update an existing lead by leadId","value":{"leadId":"fa10b3fc-0a59-40fb-b18c-70e70c583a05","lead":{"source":"chat-widget","fields":[{"name":"email","value":"jane@example.com"},{"name":"phone","value":"555-9999"}]}}},"partialToSubmitted":{"summary":"Complete a partial lead (transition to submitted)","value":{"leadId":"fa10b3fc-0a59-40fb-b18c-70e70c583a05","lead":{"source":"chat-widget","fields":[{"name":"phone","value":"555-1234"}]},"submitted":true}}}}}},"responses":{"200":{"description":"Lead submitted or updated successfully.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PublicLeadSubmissionResponse"},"examples":{"created":{"summary":"New lead created","value":{"success":true,"leadId":"fa10b3fc-0a59-40fb-b18c-70e70c583a05","status":"submitted","isNew":true}},"updated":{"summary":"Existing lead updated","value":{"success":true,"leadId":"fa10b3fc-0a59-40fb-b18c-70e70c583a05","status":"submitted","isNew":false}}}}}},"400":{"description":"Validation error.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"examples":{"missingId":{"summary":"No identifier provided","value":{"message":"Either lead sessionId or leadId is required."}},"missingSource":{"summary":"Missing source","value":{"message":"Lead source is required."}}}}}},"404":{"description":"App not found or deleted.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/cms/app/leads":{"put":{"operationId":"sendLeads","summary":"Submit a lead (authenticated)","description":"Authenticated endpoint for submitting leads. Requires `leads:write` scope. The token needs both `events:write` (the gateway allows the route only for it) and `leads:write` (the handler checks it). The body is passed through without validation.","tags":["Leads"],"security":[{"CmsApiToken":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"lead":{"$ref":"#/components/schemas/ExternalLead"},"extras":{"$ref":"#/components/schemas/Extras"}}}}}},"responses":{"200":{"description":"Lead submitted successfully.","content":{"application/json":{"schema":{"type":"object"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"}},"parameters":[{"name":"appId","in":"query","required":false,"description":"Which app an organization-level token acts on. Required for an organization token (400 without it); ignored for an app token.","schema":{"type":"string"}}]}},"/cms/app":{"get":{"operationId":"getApp","summary":"Get app configuration","description":"Returns the app configuration for the authenticated API token. Requires `read:app` scope.","tags":["App"],"security":[{"CmsApiToken":[]}],"responses":{"200":{"description":"App configuration.","content":{"application/json":{"schema":{"type":"object","properties":{"app":{"$ref":"#/components/schemas/App"}}}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"description":"App not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"parameters":[{"name":"appId","in":"query","required":false,"description":"Which app an organization-level token acts on. Required for an organization token (400 without it); ignored for an app token.","schema":{"type":"string"}}]}},"/cms/entity":{"get":{"operationId":"listEntities","summary":"List all entities","description":"Returns all entities for the authenticated app. Requires `read:entity` scope.","tags":["Content"],"security":[{"CmsApiToken":[]}],"responses":{"200":{"description":"List of entities.","content":{"application/json":{"schema":{"type":"object","properties":{"entities":{"type":"array","items":{"$ref":"#/components/schemas/Entity"}}}}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"description":"The app has no entities.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"errorType":"LambdaError","httpStatus":404,"message":"Entities not found."}}}}},"parameters":[{"name":"appId","in":"query","required":false,"description":"Which app an organization-level token acts on. Required for an organization token (400 without it); ignored for an app token.","schema":{"type":"string"}},{"name":"entityId","in":"query","required":false,"description":"Returns that one entity as `{entity}` instead of the list.","schema":{"type":"string"}}]}},"/cms/entity/{entityId}":{"get":{"operationId":"getEntity","summary":"Get a single entity","description":"Returns a specific entity by ID. Requires `read:entity` scope.","tags":["Content"],"security":[{"CmsApiToken":[]}],"parameters":[{"name":"entityId","in":"path","required":true,"schema":{"type":"string"}},{"name":"appId","in":"query","required":false,"description":"Which app an organization-level token acts on. Required for an organization token (400 without it); ignored for an app token.","schema":{"type":"string"}}],"responses":{"200":{"description":"Entity found.","content":{"application/json":{"schema":{"type":"object","properties":{"entity":{"$ref":"#/components/schemas/Entity"}}}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"description":"Entity not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/cms/handler":{"get":{"operationId":"listHandlers","summary":"List all handlers","description":"Returns all handlers (intents) for the authenticated app. Requires `read:handler` scope. Supports A/B test experiment assignment via `sessionId` query parameter or `x-session-id` header.","tags":["Content"],"security":[{"CmsApiToken":[]}],"parameters":[{"name":"sessionId","in":"query","required":false,"description":"A/B experiments are applied only to a single handler (`?handlerId=` or GET /cms/handler/{handlerId}), never to the list.","schema":{"type":"string"}},{"name":"appId","in":"query","required":false,"description":"Which app an organization-level token acts on. Required for an organization token (400 without it); ignored for an app token.","schema":{"type":"string"}},{"name":"handlerId","in":"query","required":false,"description":"Returns that one handler as `{handler}` instead of the list. `intentId` is accepted as an alias.","schema":{"type":"string"}}],"responses":{"200":{"description":"List of handlers.","content":{"application/json":{"schema":{"type":"object","properties":{"handlers":{"type":"array","items":{"$ref":"#/components/schemas/Handler"}}}}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"description":"The app has no handlers.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"errorType":"LambdaError","httpStatus":404,"message":"Handlers not found."}}}}}}},"/cms/handler/{handlerId}":{"get":{"operationId":"getHandler","summary":"Get a single handler","description":"Returns a specific handler by ID. Also accepts `intentId` as an alias. Requires `read:handler` scope. The handler may carry `_experiment` (the A/B assignment), and an experiment can override `data.CAPTURE_MAIN_FORM`.","tags":["Content"],"security":[{"CmsApiToken":[]}],"parameters":[{"name":"handlerId","in":"path","required":true,"description":"Handler ID or intent ID.","schema":{"type":"string"}},{"name":"sessionId","in":"query","required":false,"description":"Session ID for A/B test experiment assignment.","schema":{"type":"string"}},{"name":"appId","in":"query","required":false,"description":"Which app an organization-level token acts on. Required for an organization token (400 without it); ignored for an app token.","schema":{"type":"string"}}],"responses":{"200":{"description":"Handler found.","content":{"application/json":{"schema":{"type":"object","properties":{"handler":{"$ref":"#/components/schemas/Handler"}}}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"description":"Handler not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/cms/externalId":{"get":{"operationId":"getExternalId","summary":"Get app external ID","description":"Returns the external ID for the authenticated app, derived from the API token. Creates one if not already set. Requires `read:app` scope.","tags":["App"],"security":[{"CmsApiToken":[]}],"parameters":[{"name":"appId","in":"query","required":false,"description":"App ID override (only used when API token is at organization level).","schema":{"type":"string"}}],"responses":{"200":{"description":"External ID.","content":{"application/json":{"schema":{"type":"object","properties":{"externalId":{"type":"string"}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"},"500":{"description":"The external id could not be retrieved.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"errorType":"LambdaError","httpStatus":500,"message":"Could not retrieve ID."}}}}}}},"/cms/suggestions":{"get":{"operationId":"getSuggestions","summary":"Full-text search across app content","description":"Searches across intents, entities, FAQs, events, utterances, and suggestions using Elasticsearch. Requires `read:app` scope.","tags":["Search"],"security":[{"CmsApiToken":[]}],"parameters":[{"name":"queryText","in":"query","required":false,"description":"Search query text.","schema":{"type":"string","default":""}},{"name":"size","in":"query","required":false,"description":"Number of results to return.","schema":{"type":"integer","default":10}},{"name":"toHtml","in":"query","required":false,"description":"Format results as HTML.","schema":{"type":"boolean"}},{"name":"appId","in":"query","required":false,"description":"Which app an organization-level token acts on. Required for an organization token (400 without it); ignored for an app token.","schema":{"type":"string"}}],"responses":{"200":{"description":"Search results.","content":{"application/json":{"schema":{"type":"object","description":"Contains intents, entities, FAQs, events, utterances, and suggestions matching the query."}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/cms/faq/query":{"get":{"operationId":"faqQuery","summary":"Semantic FAQ search","description":"Searches the app's FAQ. `question` is a text match on the FAQ questions; `similarQuestion` uses embeddings. One of them is required (400 otherwise).","tags":["Search"],"security":[{"CmsApiToken":[]}],"parameters":[{"name":"question","in":"query","required":false,"description":"Question to search for. Either `question` or `similarQuestion` is required.","schema":{"type":"string"}},{"name":"similarQuestion","in":"query","required":false,"description":"Alternative to `question` for similarity search.","schema":{"type":"string"}},{"name":"from","in":"query","required":false,"description":"Offset of the first result. A non-negative integer; anything else is a 400.","schema":{"type":"integer"}},{"name":"size","in":"query","required":false,"description":"Number of results to return. A non-negative integer; anything else is a 400.","schema":{"type":"integer"}},{"name":"appId","in":"query","required":false,"description":"Which app an organization-level token acts on. Required for an organization token (400 without it); ignored for an app token.","schema":{"type":"string"}}],"responses":{"200":{"description":"FAQ search results.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FAQQueryResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/cms/search":{"get":{"operationId":"kendraQuery","summary":"Knowledge base search","description":"Searches the knowledge base (OpenSearch). Requires `read:app` scope.","tags":["Search"],"security":[{"CmsApiToken":[]}],"parameters":[{"name":"question","in":"query","required":true,"description":"Search query.","schema":{"type":"string"}},{"name":"locationId","in":"query","required":false,"description":"Accepted but not used yet.","schema":{"type":"string"}},{"name":"useRetrievalApi","in":"query","required":false,"description":"Deprecated and ignored. Kendra is no longer queried.","schema":{"type":"string","enum":["Query","Retrieve"]}},{"name":"appId","in":"query","required":false,"description":"Which app an organization-level token acts on. Required for an organization token (400 without it); ignored for an app token.","schema":{"type":"string"}}],"responses":{"200":{"description":"Search results.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/KnowledgeBaseResult"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"},"500":{"description":"The search failed, including when `question` is missing.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"errorType":"LambdaError","httpStatus":500,"message":"Internal error."}}}}}}},"/cms/rag":{"get":{"operationId":"rag","summary":"Retrieval-Augmented Generation Q&A","description":"Uses an LLM to generate answers from knowledge base sources (OpenSearch). Provides source citations. Requires `read:app` scope.","tags":["Search"],"security":[{"CmsApiToken":[]}],"parameters":[{"name":"question","in":"query","required":true,"description":"User question.","schema":{"type":"string"}},{"name":"locationId","in":"query","required":false,"description":"Accepted but not used yet.","schema":{"type":"string"}},{"name":"useRetrievalApi","in":"query","required":false,"description":"Deprecated and ignored. Kendra is no longer queried.","schema":{"type":"string","enum":["Query","Retrieve"]}},{"name":"appId","in":"query","required":false,"description":"Which app an organization-level token acts on. Required for an organization token (400 without it); ignored for an app token.","schema":{"type":"string"}}],"responses":{"200":{"description":"Generated answer with sources.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/RAGResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/cms/spellchecker":{"get":{"operationId":"spellChecker","summary":"Check spelling","description":"Checks the spelling of `sentence`. The app's entity values and their synonyms count as correctly spelled words. Requires the `read:entity` scope.","tags":["Content"],"security":[{"CmsApiToken":[]}],"parameters":[{"name":"sentence","in":"query","required":true,"description":"Text to spell check.","schema":{"type":"string"}},{"name":"appId","in":"query","required":false,"description":"Which app an organization-level token acts on. Required for an organization token (400 without it); ignored for an app token.","schema":{"type":"string"}}],"responses":{"200":{"description":"Spell check results.","content":{"application/json":{"schema":{"type":"object","properties":{"sentence":{"type":"string"},"result":{"type":"array","items":{"type":"object","description":"Spelling error with suggestions."}}}}}}},"400":{"description":"Missing sentence parameter.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/cms/app/events":{"put":{"operationId":"pushEvents","summary":"Push analytics events","description":"Pushes analytics events to the Kinesis stream. All events must belong to the authenticated app. Requires `events:write` scope.","tags":["Events"],"security":[{"CmsApiToken":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"events":{"type":"array","items":{"type":"object","description":"Stentor app handler event."}}}}}}},"responses":{"200":{"description":"Events pushed successfully.","content":{"application/json":{"schema":{"type":"object"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"}},"parameters":[{"name":"appId","in":"query","required":false,"description":"Which app an organization-level token acts on. Required for an organization token (400 without it); ignored for an app token.","schema":{"type":"string"}}]}},"/cms/widget/events":{"post":{"operationId":"widgetEvents","summary":"Track widget interactions","description":"Public endpoint for tracking form widget interactions (opens, step changes, submissions, partial data, closes). Supports UTM parameter and A/B test tracking.","tags":["Events"],"security":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["events"],"description":"One of `key` or `appId` is required.","properties":{"key":{"type":"string","description":"The widget's embed key; resolves the app."},"appId":{"type":"string","description":"The app directly, instead of `key`."},"widgetType":{"type":"string","enum":["form","chat"]},"events":{"type":"array","items":{"$ref":"#/components/schemas/WidgetEvent"}}}}}}},"responses":{"200":{"description":"Events accepted.","content":{"application/json":{"schema":{"type":"object","properties":{"processed":{"type":"integer"}}}}}},"400":{"description":"Invalid event payload.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"The widget key is not valid.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"errorType":"LambdaError","httpStatus":401,"message":"Invalid widget key."}}}}}}},"/cms/onboarding/events":{"put":{"operationId":"putOnboardingEvents","summary":"Track onboarding flow events","description":"Public endpoint for tracking onboarding flow progress. Captures step completion, app setup, and user actions. Enriches events with IP-based geolocation. A body that is not JSON fails with a 5xx, not a 400.","tags":["Events"],"security":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/OnboardingEvent"}}}},"responses":{"200":{"description":"Received.","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string","example":"Event received"}}}}}}}}},"/cms/token":{"post":{"operationId":"createToken","summary":"Create an API token","description":"Creates a new API token for an app (`appId`) or, when no `appId` is given, for an organization (`organizationId`). Maximum 2 tokens per app/organization; an organization's partner keys do not count. Requires Stentor authorization.","tags":["Tokens"],"security":[{"StentorAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"appId":{"type":"string","description":"App ID to create token for."},"organizationId":{"type":"string","description":"Organization ID to create token for."}}}}}},"responses":{"200":{"description":"Token created.","content":{"application/json":{"schema":{"type":"object","properties":{"token":{"$ref":"#/components/schemas/ApiToken"}}}}}},"400":{"description":"No id, or the app already has the maximum number of tokens.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"errorType":"LambdaError","httpStatus":400,"message":"The maximum number of tokens has been exceeded."}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"description":"The app or organization was not found, or the caller may not write to it. The message is `App not found.` or `Organization not found.`","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"errorType":"LambdaError","httpStatus":404,"message":"App not found."}}}}}},"delete":{"operationId":"deleteToken","summary":"Delete an API token","description":"Deletes an API token by ID. Requires Stentor authorization and write permission on the associated app/organization.","tags":["Tokens"],"security":[{"StentorAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["tokenId"],"properties":{"tokenId":{"type":"string","description":"Token ID to delete."}}}}}},"responses":{"200":{"description":"Token deleted.","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string","example":"Success"}}}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/cms/token/{appId}":{"get":{"operationId":"getTokens","summary":"List API tokens","description":"Returns the API tokens for an app, or for an organization when the `organizationId` query parameter is given (the path value is then ignored). An organization's partner keys are not listed. For the next page, pass a response's `LastEvaluatedKey` back, JSON-encoded, as the `LastEvaluatedKey` query parameter. Requires Stentor authorization.","tags":["Tokens"],"security":[{"StentorAuth":[]}],"parameters":[{"name":"appId","in":"path","required":true,"description":"App ID to list tokens for. Ignored when `organizationId` is given.","schema":{"type":"string"}},{"name":"organizationId","in":"query","required":false,"description":"List the organization's tokens instead of the app's.","schema":{"type":"string"}},{"name":"LastEvaluatedKey","in":"query","required":false,"description":"The previous page's `LastEvaluatedKey`, JSON-encoded. Anything else is a 400.","schema":{"type":"string"},"example":"{\"tokenId\":\"token-0f8e…\",\"appId\":\"my-app\"}"}],"responses":{"200":{"description":"List of tokens.","content":{"application/json":{"schema":{"type":"object","properties":{"tokens":{"type":"array","items":{"$ref":"#/components/schemas/PublicApiToken"}},"LastEvaluatedKey":{"type":"object","description":"Pagination cursor, present when there is another page. Pass it back JSON-encoded as the `LastEvaluatedKey` query parameter.","nullable":true}}}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}}},"components":{"securitySchemes":{"ApiGatewayKey":{"type":"apiKey","in":"header","name":"X-Api-Key","description":"An API Gateway API key, checked by API Gateway itself before the request reaches a handler (routes marked `private: true` in serverless.yml). Distinct from CmsApiToken (which is sent in `Authorization`): this key is issued by API Gateway and must belong to a usage plan covering this API and stage, whereas a CmsApiToken is minted by POST /cms/token and carries its own scopes. Only /cms/app/{appId}/leads/echo-check requires it."},"CmsApiToken":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"A CMS API token, created with POST /cms/token, sent as `Authorization: Bearer <token>`. Its scopes decide which routes it may call; the authorizer's answer is cached for 300 seconds. An organization-level token must also name the app with `?appId=`."},"StentorAuth":{"type":"apiKey","in":"header","name":"x-xapp-usertoken","description":"The signed-in Studio user's Cognito ID token, as the raw JWT (no `Bearer` prefix)."}},"schemas":{"AvailabilityWindow":{"type":"object","required":["start","end","status","basis","confirmation","classId"],"properties":{"start":{"type":"string","format":"date-time","description":"ISO 8601 with offset, business timezone."},"end":{"type":"string","format":"date-time","description":"ISO 8601 with offset, business timezone."},"status":{"type":"string","enum":["open","limited"],"description":"`limited` when one booking is left in the window."},"basis":{"type":"string","enum":["policy","calendar"],"description":"What backs the window. The business's policy overrides any connected calendar, so this is `policy`."},"confirmation":{"type":"string","enum":["business_confirms"],"description":"The business confirms every booking."},"classId":{"type":"string","description":"Availability class the window is for."},"remaining":{"type":"integer","description":"Bookings left in the window for the class, when the class is capped."},"bookingUrl":{"type":"string","format":"uri","description":"Opens the business's booking form with this window pre-selected."}}},"AvailabilitySearchResult":{"type":"object","required":["businessId","appId","name","timeZone","asOf","windows"],"properties":{"businessId":{"type":"string"},"appId":{"type":"string"},"name":{"type":"string"},"timeZone":{"type":"string","description":"IANA timezone of the business."},"distanceMiles":{"type":"number","description":"From `lat`,`lng`, to the business's nearest listed location. Only when searching by coordinates."},"asOf":{"type":"string","format":"date-time","description":"When this business's windows were computed."},"windows":{"type":"array","items":{"$ref":"#/components/schemas/AvailabilityWindow"}}}},"AvailabilitySearchResponse":{"type":"object","required":["asOf","results"],"properties":{"asOf":{"type":"string","format":"date-time"},"results":{"type":"array","items":{"$ref":"#/components/schemas/AvailabilitySearchResult"}},"nextCursor":{"type":"string","description":"Pass as `cursor` for the next page; absent on the last."}}},"AvailabilityWindowsResponse":{"type":"object","required":["businessId","timeZone","asOf","windows"],"properties":{"businessId":{"type":"string"},"timeZone":{"type":"string","description":"IANA timezone of the business."},"asOf":{"type":"string","format":"date-time"},"windows":{"type":"array","items":{"$ref":"#/components/schemas/AvailabilityWindow"}}}},"AvailabilityServicesResponse":{"type":"object","required":["businessId","services"],"properties":{"businessId":{"type":"string"},"services":{"type":"array","items":{"type":"object","required":["id","name","summary"],"properties":{"id":{"type":"string"},"name":{"type":"string"},"summary":{"type":"string"}}}}}},"PublicLeadSubmissionRequest":{"type":"object","required":["lead"],"properties":{"lead":{"$ref":"#/components/schemas/ExternalLead"},"extras":{"$ref":"#/components/schemas/Extras"},"leadId":{"type":"string","maxLength":100,"description":"UUID of an existing lead to update. Returned by a previous call to this endpoint. If provided, the existing lead is looked up and fields are merged."},"submitted":{"type":"boolean","default":true,"description":"Whether the lead is fully submitted. Set to `false` for partial saves (e.g., during an ongoing chat conversation). Partial leads skip AI analysis and integration sends. When later set to `true`, the full pipeline is triggered."},"deliver":{"type":"boolean","default":true,"description":"`false` saves the lead without delivering it. Honoured on updates only."}},"description":"At least one of `lead.sessionId` or `leadId` must be provided. If both are provided, `leadId` takes precedence for lookup."},"PublicLeadSubmissionResponse":{"type":"object","properties":{"success":{"type":"boolean","example":true},"leadId":{"type":"string","format":"uuid","description":"Stable UUID for this lead. Use this to update the lead in subsequent calls."},"status":{"type":"string","enum":["partial","submitted"],"description":"Current status of the lead."},"isNew":{"type":"boolean","description":"`true` if a new lead was created, `false` if an existing lead was updated."}}},"ExternalLead":{"type":"object","required":["fields","source"],"properties":{"sessionId":{"type":"string","maxLength":200,"description":"Chat/form session ID. Used for lead lookup when `leadId` is not provided. At least one of `sessionId` or `leadId` (on the parent request) must be provided."},"source":{"type":"string","maxLength":100,"description":"Source of the lead (e.g., `chat-widget`, `form-widget`, `email`).","example":"chat-widget"},"fields":{"type":"array","items":{"$ref":"#/components/schemas/LeadFormField"},"maxItems":50,"description":"Lead form fields. Field names are automatically normalized (e.g., `email` → `EMAIL`, `phone` → `PHONE`). On updates, fields are merged by name — new fields are added, existing fields are overwritten, untouched fields are kept."},"userId":{"type":"string","description":"User ID that generated the lead."},"company":{"type":"string","description":"Company name."},"transcript":{"type":"array","items":{"type":"object"},"description":"Conversation transcript from chat interactions."},"refId":{"type":"string","description":"Reference ID in a third-party CRM/FSM."},"placeId":{"type":"string","description":"Google Place ID for multi-location businesses."},"jobTypeId":{"type":"string","description":"Job type ID for CRM integration."},"availabilityClassId":{"type":"string","description":"ID to identify the availability strategy (blocked days ahead, etc.)."},"isAbandoned":{"type":"boolean","description":"Whether this lead was from an abandoned form."}}},"LeadFormField":{"type":"object","required":["name","value"],"properties":{"name":{"type":"string","maxLength":100,"description":"Field name. Common names are auto-normalized: `name`/`fullname` → `FULL_NAME`, `email` → `EMAIL`, `phone`/`mobile`/`cell` → `PHONE`, `address` → `ADDRESS`, `message`/`comments` → `MESSAGE`, `firstname`/`fname` → `FIRST_NAME`, `lastname`/`lname`/`surname` → `LAST_NAME`."},"value":{"type":"string","maxLength":10000,"description":"Field value."}}},"Extras":{"type":"object","additionalProperties":true,"properties":{"environment":{"type":"string"},"source":{"type":"string"},"channel":{"type":"string","description":"Transport mechanism through which the lead was captured (e.g., `chat`, `form`, `email`, `sms`, `voice`, `mcp`). Distinct from `source`: a WordPress form submission captured via email would have source=`form-widget`, channel=`email`."},"externalId":{"type":"string"},"isAbandoned":{"type":"boolean"},"jobTypeId":{"type":"string"},"rwg_token":{"type":"string","description":"Reserve with Google token."}},"description":"Additional metadata for the lead. Supports arbitrary key-value pairs."},"App":{"type":"object","properties":{"appId":{"type":"string"},"organizationId":{"type":"string"},"name":{"type":"string"},"businessDescription":{"type":"string"},"businessHours":{"type":"object"},"places":{"type":"array","items":{"type":"object"}},"externalId":{"type":"string"}}},"Entity":{"type":"object","properties":{"entityId":{"type":"string"},"appId":{"type":"string"},"displayName":{"type":"string"},"values":{"type":"array","items":{"type":"object"}}}},"Handler":{"type":"object","properties":{"intentId":{"type":"string"},"appId":{"type":"string"},"name":{"type":"string"},"type":{"type":"string"},"slots":{"type":"array","items":{"type":"object","properties":{"name":{"type":"string"},"type":{"type":"string"},"required":{"type":"boolean"}}}}}},"FAQQueryResponse":{"type":"object","properties":{"total":{"type":"integer"},"faq":{"type":"array","items":{"type":"object","description":"A stored FAQ page with its search score.","additionalProperties":true,"properties":{"appId":{"type":"string"},"organizationId":{"type":"string"},"name":{"type":"string"},"slug":{"type":"string"},"url":{"type":"string"},"questions":{"type":"array","items":{"type":"string"}},"answer":{"type":"string"},"_score":{"type":"number"}}}}}},"KnowledgeBaseResult":{"type":"object","properties":{"totalNumberOfResults":{"type":"integer"},"documents":{"type":"array","items":{"type":"object","description":"Knowledge base document with title, excerpt, and source URI."}}}},"RAGResponse":{"type":"object","properties":{"result":{"type":"string","description":"LLM-generated answer."},"hasAnswer":{"type":"boolean","description":"Whether a relevant answer was found in the knowledge base."},"sources":{"type":"array","items":{"type":"object","description":"Source document with title, URI, and relevant excerpt."}}}},"WidgetEvent":{"type":"object","required":["eventType","metadata"],"properties":{"eventType":{"type":"string","enum":["load","form_open","engaged","next_step","previous_step","step_change","submit","partial_data","close","error","open","page_change","message","capture_start","capture_field","capture_complete","conversation_user_message","conversation_agent_response"],"description":"Form, chat or conversation event type."},"metadata":{"$ref":"#/components/schemas/WidgetEventMetadata"},"data":{"type":"object","description":"Event-specific data. Structure varies by eventType."}}},"WidgetEventMetadata":{"type":"object","required":["sessionId"],"properties":{"timestamp":{"type":"string","format":"date-time"},"sessionId":{"type":"string"},"formId":{"type":"string"},"userId":{"type":"string"},"utm_source":{"type":"string"},"utm_medium":{"type":"string"},"utm_campaign":{"type":"string"},"utm_term":{"type":"string"},"utm_content":{"type":"string"},"gclid":{"type":"string","description":"Google Click ID."},"fbclid":{"type":"string","description":"Facebook Click ID."},"msclkid":{"type":"string","description":"Microsoft Click ID."},"currentUrl":{"type":"string"},"userAgent":{"type":"string"},"experimentId":{"type":"string","description":"A/B test experiment ID."},"variantId":{"type":"string","description":"A/B test variant ID."}},"additionalProperties":true},"OnboardingEvent":{"type":"object","properties":{"path":{"type":"string"},"useragent":{"type":"string"},"currentStep":{"type":"string"},"props":{"type":"object","properties":{"currentStep":{"type":"string"},"appId":{"type":"string"},"organizationId":{"type":"string"},"productId":{"type":"string"},"couponId":{"type":"string"},"name":{"type":"string"},"website":{"type":"string"},"place":{"type":"object","properties":{"name":{"type":"string"},"placeId":{"type":"string"},"mapsUrl":{"type":"string"}}},"searchAddress":{"type":"string"},"leadsContact":{"type":"string"}}}}},"ApiToken":{"type":"object","properties":{"token":{"type":"string","description":"The API token value. Only returned on creation."},"tokenId":{"type":"string"},"appId":{"type":"string"},"organizationId":{"type":"string"},"created":{"type":"string","format":"date-time"},"lastUsed":{"type":"string","format":"date-time"},"scope":{"type":"array","items":{"type":"string"},"description":"read:app, read:entity, read:handler, write:app, events:write, leads:write, leads:read, ..."}}},"PublicApiToken":{"type":"object","description":"API token without the secret token value.","properties":{"tokenId":{"type":"string"},"appId":{"type":"string"},"organizationId":{"type":"string"},"created":{"type":"string","format":"date-time"},"lastUsed":{"type":"string","format":"date-time"},"scope":{"type":"array","items":{"type":"string"},"description":"read:app, read:entity, read:handler, write:app, events:write, leads:write, leads:read, ..."},"mask":{"type":"string","description":"The token, masked."}}},"EchoCheckResult":{"type":"object","required":["isEcho"],"properties":{"isEcho":{"type":"boolean","description":"Whether this lead appears to be an echo of a recently sent integration lead."},"matchedLeadId":{"type":"string","description":"The leadId of the original lead that was sent to an integration. Only present when `isEcho` is true."},"matchedLeadDate":{"type":"string","format":"date-time","description":"The date the original lead was captured. Only present when `isEcho` is true."},"matchedIntegrationId":{"type":"string","description":"The integration ID the original lead was sent to (e.g., `jobber-tenant-123`). Only present when `isEcho` is true."}}},"ErrorResponse":{"type":"object","required":["errorType","httpStatus","message"],"properties":{"errorType":{"type":"string"},"httpStatus":{"type":"integer"},"message":{"type":"string","description":"Human-readable error message."}}}},"responses":{"Unauthorized":{"description":"Authentication required. Provide a valid API token.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"Forbidden":{"description":"The token does not carry this route's scope, or the app is not the token's.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"BadRequest":{"description":"The request fails validation; `message` says why.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"errorType":"LambdaError","httpStatus":400,"message":"appId was not provided in the path parameters for organization level CMS token."}}}},"NotFound":{"description":"Not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"errorType":"LambdaError","httpStatus":404,"message":"App not found."}}}}}},"tags":[{"name":"Availability","description":"Arrival windows businesses offer, for partners and agents. Every customer business with a booking form is included unless it turns the Availability API off in Studio."},{"name":"Leads","description":"Lead capture and management."},{"name":"App","description":"App configuration and metadata."},{"name":"Content","description":"Entities, handlers, and spell checking."},{"name":"Search","description":"Full-text search, FAQ, knowledge base, and RAG."},{"name":"Events","description":"Analytics and tracking events."},{"name":"Tokens","description":"API token management."}]}