> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sahlfinancial.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Document requests

> Ask an applicant for documents through a secure link or an iframe. Create, track, resend and revoke a request, and get told by webhook.

A document request collects supporting documents from one applicant (for example a declined or borderline client) while you keep your own KYC provider. You create a request, Sahl returns a link, the applicant opens it, accepts the privacy notice, uploads the documents you asked for and submits. Sahl reads them and tells you by webhook. You read the outcome on the case in the console.

| Endpoint | Does | Scope |
| - | - | - |
| `POST /v1/requests` | Create a request and its link. | `requests:write` |
| `GET /v1/requests` | List requests, newest first. | `requests:read` or `requests:write` |
| `GET /v1/requests/{request_id}` | One request, with its documents. | `requests:read` or `requests:write` |
| `POST /v1/requests/{request_id}/revoke` | Kill the link now. | `requests:write` |
| `POST /v1/requests/{request_id}/resend` | Mint a fresh link and email it. | `requests:write` |

All calls go to `https://app.sahlfinancial.com/api` with `Authorization: Bearer <key>`. The default environment is `sandbox`. Send `X-Sahl-Environment: production` for a live request (or `?environment=production` on the query). Production needs your workspace to be approved for Production API calls (see [Go live](https://docs.sahlfinancial.com/go-live.md#partner-document-apis)). These routes also accept a console session: reviewers and admins write, every role reads.

> [!NOTE]
>
> The applicant never calls these routes. They use the link, which is their only credential.

## Create a request

```bash cURL theme={"dark"}
curl -X POST https://app.sahlfinancial.com/api/v1/requests \
  -H "Authorization: Bearer $SAHL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "reference": "alya:app:1001",
    "applicant": {"name": "Amina B.", "email": "amina@example.com", "phone": "+212600000000"},
    "documents": ["bank_statement", "payslip"],
    "reason": "We need two documents to finish your application.",
    "locale": "fr",
    "expires_in_days": 7,
    "send_email": true,
    "channel": "link",
    "metadata": {"loan_id": "L-77"}
  }'
```

```javascript JavaScript theme={"dark"}
const res = await fetch("https://app.sahlfinancial.com/api/v1/requests", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SAHL_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    reference: "alya:app:1001",
    applicant: { name: "Amina B.", email: "amina@example.com", phone: "+212600000000" },
    documents: ["bank_statement", "payslip"],
    reason: "We need two documents to finish your application.",
    locale: "fr",
    expires_in_days: 7,
    send_email: true,
    channel: "link",
    metadata: { loan_id: "L-77" },
  }),
});
const request = await res.json(); // 201 with request.url, or 200 with url null
```

```python Python theme={"dark"}
import os, requests

res = requests.post(
    "https://app.sahlfinancial.com/api/v1/requests",
    headers={"Authorization": f"Bearer {os.environ['SAHL_API_KEY']}"},
    json={
        "reference": "alya:app:1001",
        "applicant": {"name": "Amina B.", "email": "amina@example.com", "phone": "+212600000000"},
        "documents": ["bank_statement", "payslip"],
        "reason": "We need two documents to finish your application.",
        "locale": "fr",
        "expires_in_days": 7,
        "send_email": True,
        "channel": "link",
        "metadata": {"loan_id": "L-77"},
    },
)
request = res.json()
```

| Field | Type | Rules |
| - | - | - |
| `reference` | string, required | 1 to 64 characters of `A-Z a-z 0-9 _ . : -`. Your id for the applicant or file. The request is filed on the case for this reference and environment. |
| `documents` | array of strings, required | At least one [document type key](#document-type-keys). Duplicates are dropped. |
| `applicant` | object | `name` (up to 120 characters), `email`, `phone` (5 to 32 characters of digits and `+ ( ) - .`). Unknown keys are refused. All optional. |
| `reason` | string | Up to 500 characters, shown to the applicant. |
| `locale` | `en`, `fr` or `ar` | Language of the page and of the email. Default `en`. |
| `expires_in_days` | integer | 1 to 30. Default 7. |
| `send_email` | boolean | Default `false`. When `true`, `applicant.email` is required (422 `email_required`). |
| `channel` | `link` or `embed` | Default `link`. Use `embed` when you show the page in an iframe. |
| `metadata` | object | Your own data, returned on every read. Up to 2,000 bytes once serialised. |
| `force_new` | boolean | Default `false`. See [Idempotency](#idempotency). |

The 201 answer:

```json theme={"dark"}
{
  "id": "6f0c1d52-0000-4000-8000-000000000001",
  "reference": "alya:app:1001",
  "status": "pending",
  "environment": "sandbox",
  "case_id": "a1b2c3d4-0000-4000-8000-000000000002",
  "url": "https://app.sahlfinancial.com/r/Yw3k...",
  "expires_at": "2026-12-01T10:00:00+00:00",
  "created_at": "2026-11-24T10:00:00+00:00",
  "opened_at": null,
  "submitted_at": null,
  "completed_at": null,
  "applicant": {"name": "Amina B.", "email_masked": "a***@example.com", "phone_masked": "*********000"},
  "documents": [
    {"type": "bank_statement", "label": "Relevé bancaire", "status": "missing"},
    {"type": "payslip", "label": "Bulletin de paie", "status": "missing"}
  ],
  "channel": "link",
  "locale": "fr",
  "reason": "We need two documents to finish your application.",
  "email_sent_at": "2026-11-24T10:00:01+00:00",
  "resend_count": 0,
  "metadata": {"loan_id": "L-77"},
  "email_sent": true
}
```

The `url` is returned only by create (201) and by resend. Sahl stores a SHA-256 of the link's token, never the token, so keep the URL or call resend. Applicant contact details come back masked.

### Idempotency

A request is unique per workspace, environment and `reference` while it is open (`pending`, `opened` or `submitted`). Creating again for the same `reference` returns the open request with HTTP 200, `"url": null`, `"existing": true` and `"email_sent": false`. Send `"force_new": true` to supersede it: the old link is revoked and a new request is created.

### Errors on create

| Status | `detail.code` | Cause |
| - | - | - |
| 401 / 403 | (message) | Missing, invalid or revoked key, or a key without `requests:write`. |
| 403 | `production_api_not_approved` | A Production call before Sahl approved your workspace. |
| 403 | `production_requires_paid_plan`, `work_email_required`, `production_trial_ended` | The Production rules of your plan. |
| 409 | `privacy_controller_missing` | A live Moroccan workspace has not named its data controller (Settings, Privacy and compliance), so it cannot collect documents yet. |
| 422 | `email_required` | `send_email` without `applicant.email`. |
| 422 | (field list) | `reference` pattern, an unknown document type, `expires_in_days` out of range. |
| 429 | `production_case_limit_reached`, `sandbox_limit_reached` | The Free plan's monthly case allowance. |
| 429 | `rate_limit_exceeded` | More than 60 calls a minute with one key. See [Errors](https://docs.sahlfinancial.com/errors.md#429-too-many-requests). |

## Statuses

```mermaid theme={"dark"}
flowchart LR
    A[pending] --> B[opened]
    B --> C[submitted]
    C --> D[completed]
    A --> E[expired]
    B --> E
    C --> E
    A --> F[revoked]
    B --> F
    C --> F
```

| Status | Meaning |
| - | - |
| `pending` | Created. The applicant has not opened the link. |
| `opened` | The applicant opened the link. |
| `submitted` | The applicant submitted. Sahl is reading the files. |
| `completed` | Every requested document has been read or has failed. |
| `expired` | The expiry date passed. Enforced on every access. |
| `revoked` | You revoked it, or a `force_new` create superseded it. |

A document inside a request has its own status: `missing` (nothing uploaded), `received` (uploaded, being read), `readable` or `unreadable`. No extracted value is returned by these routes and none is shown to the applicant. You read the result on the case in the console, under the `reference`.

## Read, list, revoke, resend

```bash theme={"dark"}
# list, filtered
curl -H "Authorization: Bearer $SAHL_API_KEY" \
  "https://app.sahlfinancial.com/api/v1/requests?reference=alya:app:1001&status=opened&limit=50&offset=0"

# one request
curl -H "Authorization: Bearer $SAHL_API_KEY" \
  https://app.sahlfinancial.com/api/v1/requests/$REQUEST_ID

# kill the link
curl -X POST -H "Authorization: Bearer $SAHL_API_KEY" \
  https://app.sahlfinancial.com/api/v1/requests/$REQUEST_ID/revoke

# mint a new link and email it
curl -X POST -H "Authorization: Bearer $SAHL_API_KEY" -H "Content-Type: application/json" \
  -d '{"send_email": true}' \
  https://app.sahlfinancial.com/api/v1/requests/$REQUEST_ID/resend
```

* **List** takes `reference`, `status` (one of the six above, else 422 `invalid_status`), `environment`, `limit` (1 to 200, default 50) and `offset`. It answers `{"items": [...], "total", "limit", "offset"}`.
* **Get** answers the same object as create, without `url`. Once the request is `completed` it adds `result` with `risk_level` and `score_band` (a range such as `600-699`) of the case.
* **Revoke** is idempotent on a revoked request. A `completed` or `expired` request answers 409 `not_revocable`.
* **Resend** mints a new link, so the old one stops working, and emails it unless you send `{"send_email": false}`. Only for `pending` and `opened` requests (409 `not_resendable` otherwise). At most 3 resends per request (429 `resend_limit`) and one a minute (429 `rate_limited` with `Retry-After`). `send_email: true` needs an applicant email (422 `email_required`).
* A request the list or a get finds past its date is marked `expired` and the `request.expired` event is sent.
* An unknown id, or another workspace's, answers 404 `not_found`.

## The applicant's link

`url` is `https://app.sahlfinancial.com/r/<token>`. The page shows your workspace name and logo, the documents asked for, your `reason`, the expiry date and the privacy notice that names your workspace as the data controller. The applicant:

1. Opens the link. The request becomes `opened`.
2. Accepts the privacy notice (consent). In Production the page may ask the applicant to complete a short verification challenge first. No file is taken before consent: an upload without it answers 403 `consent_required`.
3. Uploads each document. PDF, JPEG, PNG, TIFF or WebP, up to 30 MB per file, up to 5 files per document type and 30 files per request. A file that was not asked for answers 422 `document_type_not_requested`.
4. Submits. A submit with nothing uploaded answers 409 `no_documents`. The request becomes `submitted`, and `completed` when every document is read.

An unknown, malformed, expired or revoked link all answer the same 404 `not_found` ("This link is not valid."), so nothing can be learned by trying links. In Sandbox, the applicant can upload [specimen documents](https://docs.sahlfinancial.com/guides/sandbox-specimens.md) only, as everywhere else.

### Embed the page in an iframe

Create the request with `"channel": "embed"` and show the returned `url`:

```html theme={"dark"}
<iframe
  src="https://app.sahlfinancial.com/r/TOKEN"
  allow="camera"
  style="width:100%;height:720px;border:0"></iframe>
```

The page may only be framed by sites on your allow-list, set in the console (admin only) or with a session on `PATCH /v1/tenants/current/request-settings`:

```json theme={"dark"}
{"widget_frame_origins": ["https://app.alya.example"], "request_reply_to": "support@alya.example"}
```

* `widget_frame_origins`: up to 20 `https` origins, with no path, no wildcard and no credentials. The server sends `Content-Security-Policy: frame-ancestors 'self' <your origins>` on the page's routes. An empty list lets any https site frame it.
* `request_reply_to`: an email address, or `null`, used as the reply-to of the request email.

When the page runs in a frame it tells the parent what happened with `window.postMessage`. The message carries no personal data, only the event type, the request status and the type and status of each document:

```json theme={"dark"}
{
  "source": "sahl",
  "type": "sahl.request.document_uploaded",
  "requestStatus": "opened",
  "documents": [{"type": "bank_statement", "status": "received"}, {"type": "payslip", "status": "missing"}]
}
```

`type` is one of `sahl.request.opened`, `sahl.request.document_uploaded`, `sahl.request.submitted` and `sahl.request.error`. The page cannot know your origin, so always check `event.origin` and `event.data.source`:

```javascript theme={"dark"}
window.addEventListener("message", (event) => {
  if (event.origin !== "https://app.sahlfinancial.com") return;
  if (event.data?.source !== "sahl") return;
  if (event.data.type === "sahl.request.submitted") {
    // refresh your own view; confirm with the webhook or GET /v1/requests/{id}
  }
});
```

Treat these messages as a hint for your interface. The webhook, or a `GET`, is the source of truth.

## Webhooks

Subscribe an endpoint to `request.opened`, `request.submitted`, `request.completed` and `request.expired` (see [Webhook endpoints](https://docs.sahlfinancial.com/guides/webhook-endpoints.md)). Deliveries are signed like every other Sahl event. Payloads carry ids, your `reference` and statuses, never a name, an email, a phone number, a file name or a document value.

```json theme={"dark"}
{
  "event": "request.completed",
  "event_id": "5b1e0c7e-0000-4000-8000-000000000003",
  "occurred_at": "2026-11-25T09:12:03+00:00",
  "tenant_id": "00000000-0000-4000-8000-000000000000",
  "request_id": "6f0c1d52-0000-4000-8000-000000000001",
  "reference": "alya:app:1001",
  "environment": "production",
  "case_id": "a1b2c3d4-0000-4000-8000-000000000002",
  "status": "completed",
  "documents": [
    {"type": "bank_statement", "status": "readable"},
    {"type": "payslip", "status": "unreadable"}
  ],
  "missing": [],
  "risk_level": "medium",
  "score_band": "600-699"
}
```

`request.opened`, `request.submitted` and `request.expired` have the same shape without `risk_level` and `score_band`. `missing` lists the types never uploaded. `request.opened` is sent on the first open only. `request.completed` is sent once, when the request is `submitted` and every requested document is read or has failed.

## Email

With `send_email: true` Sahl emails the link from `<your workspace name> via Sahl <no-reply@sahlfinancial.com>`, with your `request_reply_to` as the reply-to. The email is in the request's `locale` and carries the link, the expiry date, your reason, the data controller and a privacy line. It carries no document content. Sahl does not send from your own domain today. The answer's `email_sent` says whether the email left; `email_sent_at` records when.

## Document type keys

Use these keys in `documents`. They are stable.

| Key | Document |
| - | - |
| `bank_statement` | Bank statement |
| `payslip` | Payslip |
| `national_id` | National ID card (CIN) |
| `passport` | Passport |
| `proof_of_address` | Proof of address (utility bill) |
| `employment_attestation` | Employer attestation |
| `salary_certificate` | Salary certificate |
| `tax_clearance` | Tax clearance certificate |
| `cnss_attestation` | CNSS attestation |
| `rib_certificate` | Bank details certificate (RIB) |
| `company_registration` | Company registration (RC) |
| `invoice` | Invoice |

The applicant sees each label in the request's language. Any other key is a 422 that lists the known ones.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.