# Recipe: document collection

Show a user what is missing on their records, offer the documents already in their mailbox that
could fill the gap, and prepare a message to ask the other party for the rest. This uses the chaser,
bind.co's follow-up on records that are missing something; see [Operations](https://api.bind.co/docs/operations#the-chaser).
The examples use purchase loan financing, where a buyer's passport is required. Today it is the only
operation type the chaser follows; the same routes exist on every type, but on the others the queues
are empty.

**Why it matters:** chasing missing documents is slow, manual work. Your users see what is missing,
fill most gaps from files they already have, and send a ready-made request for the rest, so records
get complete without a single "did you send it?" email written by hand.

**Scopes:** `profile:read`, `operations:purchase_loan_financing:write` (includes
`operations:purchase_loan_financing:read`), and `drafts:write` (includes `drafts:read`): the
prepared-message queue needs `drafts:read` together with the operation scope, and deciding needs
`drafts:write`.
**Webhooks:** `purchase_loan_financing.first_completed`, `purchase_loan_financing.completed`.

## 1. See where one record stands

```sh
curl https://api.bind.co/v1/operations/purchase-loan-financing/op_5b1f0c7e-8a2d-4c3b-9e61-2f7d4a9c0b13/chaser \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

The answer gives the record's phase, what is missing and the next step. To build a list instead,
search with `chaser_status`, or read one of the three queues below.

## 2. Offer what is already in the mailbox

```sh
curl https://api.bind.co/v1/operations/purchase-loan-financing/chaser/self-help \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

```json
{
  "items": [
    {
      "operation_id": "op_5b1f0c7e-8a2d-4c3b-9e61-2f7d4a9c0b13",
      "chaser_status": "in_self_help",
      "gaps": [
        {
          "canonical_path": "document:PASSPORT#buyer_passport",
          "reason": "missing_mandatory_document",
          "candidates": [],
          "document_candidates": [{"file_id": "fil_2wJyhgOT8GH", "file_name": "passport.pdf", "doc_type": "PASSPORT",
                                   "conforms": true}]
        }
      ]
    }
  ],
  "total_items": 1, "total_pages": 1, "page_number": 1, "page_size": 50
}
```

Each gap lists values found on the user's other records (`candidates`) and, for a missing document,
files in their mailbox that could be it (`document_candidates`, each with `file_name`, `doc_type` and
`conforms`). Let the user pick one:

```sh
curl https://api.bind.co/v1/operations/purchase-loan-financing/op_5b1f0c7e-8a2d-4c3b-9e61-2f7d4a9c0b13/chaser/self-help/confirm \
  -H "Authorization: Bearer $ACCESS_TOKEN" -H "Content-Type: application/json" \
  -d '{"canonical_path": "document:PASSPORT#buyer_passport", "file_id": "fil_2wJyhgOT8GH"}'
```

For a missing value, send `source_operation_id` instead of `file_id`. Accepting adds the evidence to
the record and cannot be undone; `.../chaser/self-help/reject` with the same body removes a candidate
for good.

## 3. Ask the other party

When the mailbox has nothing, bind.co prepares a message to the other party:

```sh
curl https://api.bind.co/v1/operations/purchase-loan-financing/chaser/outreach-approval \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

Each item has `counterpart_name`, `counterpart_email`, `missing_item`, `subject` and `body`. Show it
to the user; they approve it with `POST /v1/operations/purchase-loan-financing/{operation_id}/chaser/outreach-approval/confirm`
or turn it down with `.../outreach-approval/reject`, optionally with a `reason`. Approving records the
decision; it sends nothing from this call.

## 4. Hand the rest to the user

```sh
curl https://api.bind.co/v1/operations/purchase-loan-financing/chaser/owner-escalation \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

These records need the user: show their `gaps` and let them fill the values with
`PATCH /v1/operations/purchase-loan-financing/{operation_id}`, or stop the follow-up with
`POST /v1/operations/purchase-loan-financing/{operation_id}/chaser/owner-escalation/dismiss`, which
leaves the record itself unchanged.

## 5. Stay current

On `purchase_loan_financing.completed`, read the queues again: new mail can fill gaps, and records
move between phases. Files that arrive as evidence carry the same `file_id` wherever they appear; see
[Files](https://api.bind.co/docs/files).

## Make it yours

- **Loan files:** one screen of every application still missing a passport or a price, most
  fixable in a click.
- **Brokers at closing time:** collect what buyers forgot to send, with the request already written.
- **Audit readiness:** show which records are complete and which still need proof, before anyone asks.
- **Approval flows:** send lenders only complete records, and let the follow-up handle the rest.
