# Importing PDFs

Turn documents you already have (a resident handbook, a pet policy, move-in
instructions) into questions and answers. Wayline reads every page of each PDF,
scanned ones included, proposes the questions a resident or prospect could ask
with the answers the document gives, and puts them in **Knowledge → Pending** for
a person to review. Nothing an import proposes is used by your agents until it is
published.

## For an AI agent: the whole flow

1. **Ask where to upload each PDF**: `POST /v1/knowledge/uploads`.
2. **Upload it** straight to storage with the URL and fields you got back.
3. **Start one import for all of them**: `POST /v1/knowledge/imports`.
4. **Poll** `GET /v1/knowledge/imports/{id}` until `status` is `COMPLETED` or `FAILED`.
5. **Review** what it proposed: `GET /v1/knowledge/questions?status=pending`, and publish what's right with `PATCH /v1/knowledge/answers/{id}` `{ "published": true }`, or leave it for a person.

### 1. `POST /v1/knowledge/uploads`

```json
{ "fileName": "Resident Handbook.pdf", "contentType": "application/pdf", "size": 2483021 }
```

`size` is the file's size in bytes. Only PDFs, up to 50 MB each. Answers `201`:

```json
{
  "url": "https://level-orgs.s3.amazonaws.com/",
  "fields": { "key": "7/knowledge/files/3f2c….pdf", "Content-Type": "application/pdf", "policy": "…", "x-amz-signature": "…" },
  "key": "7/knowledge/files/3f2c….pdf"
}
```

### 2. Upload the file

POST a `multipart/form-data` form to `url`: every entry of `fields` as a form field, in any order, then the file itself as the **last** field, named `file`. No API key: the fields are the permission, valid for one hour and for exactly that size range and type.

```bash
curl -X POST "$URL" \
  -F "key=$KEY" -F "Content-Type=application/pdf" -F "policy=$POLICY" -F "x-amz-signature=$SIGNATURE" … \
  -F "file=@Resident Handbook.pdf;type=application/pdf"
```

A `204` (or any 2xx) means it is stored.

### 3. `POST /v1/knowledge/imports`

```json
{
  "files": [
    { "key": "7/knowledge/files/3f2c….pdf", "name": "Resident Handbook.pdf" },
    { "key": "7/knowledge/files/91ab….pdf", "name": "Pet Policy.pdf" }
  ],
  "propertyGroupId": 60
}
```

- `files`: 1–20 uploads, each by the `key` you were given; `name` (shown to reviewers) defaults to the key's file name.
- `propertyId` or `propertyGroupId` (not both): where the answers apply. Leave both out for the whole organization. When a document itself names one of your buildings for a fact, that answer is scoped to the building instead.

Answers `202` with the import, and a `Location` to poll. Only one import runs per organization at a time: while one is running a new one is refused with `409 import_in_progress` and a `Retry-After` header. Put all your PDFs in one import.

### 4. `GET /v1/knowledge/imports/{id}`

```json
{
  "id": 31,
  "strategy": "FILE",
  "status": "COMPLETED",
  "startedAt": "2026-11-04T09:10:00.000Z",
  "completedAt": "2026-11-04T09:14:38.000Z",
  "failureReason": null,
  "questionCount": 18,
  "answerCount": 21,
  "files": [{ "name": "Resident Handbook.pdf" }, { "name": "Pet Policy.pdf" }]
}
```

| Field | |
|-------|--|
| `status` | `IN_PROGRESS`, then `COMPLETED` or `FAILED` |
| `failureReason` | Why it failed, for a person, when it did |
| `questionCount`, `answerCount` | What it proposed: new questions, and answers added to existing ones too |

Polling every 15–30 seconds is plenty: a short PDF takes a minute or two, a long one longer (every page is read).

`GET /v1/knowledge/imports` lists your imports, paged, oldest first; imports started in the Wayline app (from mailboxes, Intercom, videos) are listed too.

## Limits and behavior

- PDFs only, up to 50 MB and 150 pages each, 20 per import, and 500 pages per import in total. A file over a limit is skipped and the rest are imported.
- A file that can't be read (password protected, not really a PDF, or no readable text) is skipped. If no file can be read, the import fails and `failureReason` names each file and why.
- Uploaded files are deleted once read: no answer links to them.
- An import never overwrites an answer that already has text: when a document disagrees with your knowledge base, the existing answer stays and it's left to a person.
- A question the knowledge base already has (ignoring case and spacing) gets a new answer rather than a duplicate question.
