# Knowledge

The knowledge base is what your Wayline agents answer residents and prospects
from, by phone, text and web chat. It has two kinds of record:

- **Questions**, each with one or more **answers**. A question is asked once per organization ("Do you allow pets?"); its answers can differ by place (one for the whole organization, another for one building).
- **Guardrails**: rules the agents always follow ("Never quote a rent that isn't in the listings").

These endpoints read and write exactly what the Wayline app does, with the same rules.

## Published and pending

An answer or guardrail is either **published** (`published: true`), and used by every agent at once, or **pending** (`published: false`), waiting in **Knowledge → Pending** in the app for someone to review. Agents never use a pending answer.

- Answers and guardrails created through this API are **published unless you send `published: false`**.
- Answers proposed by an [import](https://docs.wayline.com/imports.md) are always pending.
- A question is listed as `pending` while any of its answers is pending (or it has none), and as `published` once any answer is published. A question with a live answer and a pending one is both.

## Scope

An answer or guardrail applies to the whole organization unless it is scoped. The scope is sent and returned as fields on the answer or guardrail itself:

| Field | Values |
|-------|--------|
| `propertyIds` | your property ids ([properties](https://docs.wayline.com/listings.md#properties-and-property-groups)) |
| `propertyGroupIds` | your property group ids |
| `countryCodes` | ISO 3166-1 alpha-2 codes (`US`) |
| `stateCodes` | state or province codes (`CA`) |
| `counties`, `cities` | names (`Cook`, `Austin`) |
| `zipCodes` | postal codes |

Responses name places as `properties: [{ id, label }]` and `propertyGroups: [{ id, label }]` beside the five geographic fields.

The rules:

1. **Places or geography, never both** on one answer or guardrail. Write two instead.
2. Within a field the values mean *any of*: `stateCodes: ["CA", "TX"]` is California or Texas.
3. **Two answers to one question may not claim the same place**: two organization-wide answers, or two answers both naming property 30, are refused (`422 invalid_scope`), because an agent could not choose between them. Different levels are fine: a California answer and a property answer both covering that property resolve to the property one, the most specific.
4. Guardrails all apply at once, so any number can cover the same place.
5. A property or group that isn't yours, or a country code that isn't ISO, is refused by name (`422 invalid_field`).

Codes are stored upper-case, and names are trimmed and de-duplicated.

## Questions

### The question object

```json
{
  "id": 812,
  "question": "Do you allow pets?",
  "category": "LEASING",
  "required": false,
  "createdAt": "2026-11-03T16:02:48.000Z",
  "updatedAt": "2026-11-04T09:15:02.311Z",
  "answers": [
    {
      "id": 2044,
      "value": "Cats and dogs under 40 lb, with a $500 deposit.",
      "published": true,
      "verbatim": false,
      "properties": [], "propertyGroups": [],
      "countryCodes": [], "stateCodes": [], "counties": [], "cities": [], "zipCodes": [],
      "fromCase": null,
      "knowledgeImportId": null,
      "createdAt": "2026-11-04T09:15:02.311Z",
      "updatedAt": "2026-11-04T09:15:02.311Z"
    },
    {
      "id": 2045,
      "value": "The Alder does not allow pets.",
      "published": true,
      "verbatim": false,
      "properties": [{ "id": 30, "label": "120 Main Street" }], "propertyGroups": [],
      "countryCodes": [], "stateCodes": [], "counties": [], "cities": [], "zipCodes": [],
      "fromCase": null,
      "knowledgeImportId": null,
      "createdAt": "2026-11-04T09:16:40.020Z",
      "updatedAt": "2026-11-04T09:16:40.020Z"
    }
  ]
}
```

| Field | Notes |
|-------|-------|
| `category` | `GENERAL`, `LEASING` or `MAINTENANCE` |
| `required` | Part of the set every account is asked to answer during onboarding |
| `answers[].value` | The answer, ≤ 20,000 characters |
| `answers[].verbatim` | Agents say it word for word instead of in their own phrasing: for disclosures, fees, legal wording |
| `answers[].fromCase` | `{ id, title }` of the conversation it was learned from, if any |
| `answers[].knowledgeImportId` | The import that proposed it, if any |

Answers are listed oldest first.

### `GET /v1/knowledge/questions`

| Query | |
|-------|--|
| `status` | `pending` or `published` (see above); both when left out |
| `category` | `GENERAL`, `LEASING` or `MAINTENANCE` |
| `q` | Text the question or one of its answers contains |
| `updated_since` | ISO 8601 time |
| `cursor`, `limit` | [Paging](https://docs.wayline.com/conventions.md#paging) |

### `POST /v1/knowledge/questions`

```json
{
  "question": "Do you allow pets?",
  "category": "LEASING",
  "answers": [
    { "value": "Cats and dogs under 40 lb, with a $500 deposit." },
    { "value": "The Alder does not allow pets.", "propertyIds": [30] }
  ]
}
```

`question` (1–500 characters) and at least one answer (up to 50) are required; `category` defaults to `GENERAL`. Each answer takes `value`, `published` (default `true`), `verbatim` (default `false`) and the scope fields. Answers `201` with the question.

A question that is already in your knowledge base, ignoring case and spacing, is refused with `409 duplicate_question`: add an answer to the existing one instead. [Search](#get-v1knowledgesearch) first to find it.

### `GET /v1/knowledge/questions/{id}`

One question with its answers.

### `PATCH /v1/knowledge/questions/{id}`

`{ "question": "May I have a pet?" }` and/or `{ "category": "GENERAL" }`. Answers are left as they are.

### `DELETE /v1/knowledge/questions/{id}`

Deletes the question and all its answers. `204`.

## Answers

### `POST /v1/knowledge/questions/{id}/answers`

```json
{ "value": "Texas residents pay a $300 pet deposit.", "stateCodes": ["TX"], "published": false }
```

Adds an answer; its scope must not claim a place another answer of the question already claims. Answers `201` with the whole question; the new answer is the last one.

### `PATCH /v1/knowledge/answers/{id}`

Change any of `value`, `published`, `verbatim` and the scope. Publishing a pending answer is `{ "published": true }`.

Sending **any** scope field replaces the answer's whole scope with what you send (unsent fields become empty), so send every field it should keep. Sending no scope field leaves the scope alone. Answers `200` with the whole question.

### `DELETE /v1/knowledge/answers/{id}`

Deletes one answer; answers `200` with the question. A question's last answer can't be deleted (`409 last_answer`): delete the question.

## Search

### `GET /v1/knowledge/search`

Finds the answers closest in meaning to a question, the same way your agents look answers up, so you can check whether something is already covered before adding it.

| Query | |
|-------|--|
| `q` | Required, 1–500 characters: the question in a resident's own words |
| `status` | `pending` or `published`; both when left out |
| `limit` | 1–20, default 10 |

```json
{
  "data": [
    {
      "score": 0.8123,
      "questionId": 812,
      "question": "Do you allow pets?",
      "category": "LEASING",
      "answer": { "id": 2044, "value": "Cats and dogs under 40 lb, with a $500 deposit.", "published": true, "...": "…" }
    }
  ]
}
```

Results are best first; `score` runs from 0 to 1 and is only meaningful for ordering. Blank answers are never returned.

## Guardrails

### The guardrail object

```json
{
  "id": 77,
  "value": "Never quote a rent that isn't in the listings.",
  "published": true,
  "verbatim": false,
  "isManaged": false,
  "properties": [], "propertyGroups": [],
  "countryCodes": [], "stateCodes": [], "counties": [], "cities": [], "zipCodes": [],
  "createdAt": "2026-11-04T09:20:00.000Z",
  "updatedAt": "2026-11-04T09:20:00.000Z"
}
```

`isManaged: true` marks a rule Wayline maintains for every account (fair housing, for example). You can read these but not change or delete them (`403 managed_guardrail`).

### `GET /v1/knowledge/guardrails`

`status`: `published` (yours and Wayline's live rules), `pending` (your unpublished ones) or, left out, both. Paged.

### `POST /v1/knowledge/guardrails`

`{ "value": "…", "published": true, "verbatim": false, …scope }`. `value` is 1–5,000 characters; `published` defaults to `true`. `201`.

### `GET /v1/knowledge/guardrails/{id}`

One guardrail.

### `PATCH /v1/knowledge/guardrails/{id}`

Change any of `value`, `published`, `verbatim` and the scope; as with answers, any scope field replaces the whole scope.

### `DELETE /v1/knowledge/guardrails/{id}`

`204`.
