> For the complete documentation index, see [llms.txt](https://api-docs.hengelending.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://api-docs.hengelending.com/api/guides/loan-lifecycle.md). Agents can also search and read this documentation through its [MCP server](https://api-docs.hengelending.com/~gitbook/mcp).

# Loan lifecycle

A loan moves through two stages. Henge owns it until it is submitted. After that the LOS owns it and its status comes from there.

```mermaid
stateDiagram-v2
    [*] --> Created: POST /loan-applications
    Created --> Started: POST .../start
    Started --> Submitted: POST .../submit
    Submitted --> LOSStatus: the LOS sets the status
    LOSStatus --> LOSStatus: status moves
    LOSStatus --> [*]: funded, sold or ended
```

## Created, started, submitted

* **Created.** The loan has an `id`, borrowers, a property and no LOS file. It has no `externalId`, no loan number and no LOS status yet.
* **Started.** `POST /loan-applications/{id}/start` stores the form and creates the section tasks. Calling it again changes nothing and returns `started: false`.
* **Submitted.** `POST /loan-applications/{id}/submit` creates the loan in the LOS and sets `externalId` and the loan number. It is refused with `400` and code `LoanApplicationIncomplete` until every section is signed off and every required field is answered. The body lists `blockers`, and `GET /loan-applications/{id}?include=completion` shows the same list beforehand. A loan that is already in the LOS is refused with `422`. If the LOS rejects the submit, the LOS loan is removed, the loan stays unsubmitted and you can submit again.

## LOS statuses

After the submit the status is the LOS status, in `loanInfo.loanStatus.name`. Henge groups the names into stages, in this order:

| Stage                          | Status names                                                                                                                 |
| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------- |
| Lead                           | Lead New, Lead Other                                                                                                         |
| Application                    | App Started, Loan Officer Review, Loan Open, Loan Prequal, Loan Preapproval, Loan Submitted, Loan Pre-Processing, Loan Other |
| Processing                     | Loan Processing, Loan Document Check, Loan Document Check Failed                                                             |
| Underwriting                   | Loan Pre-Underwriting, Loan Underwriting, Loan Condition Review, Loan Final Underwriting                                     |
| Approved                       | Loan Approved                                                                                                                |
| Clear to Close                 | Loan Pre-Doc QC, Loan Clear To Close                                                                                         |
| Docs / Closing                 | Loan Docs, Loan Docs Ordered, Loan Docs Drawn, Loan Docs Back, Loan Final Docs, Loan Funding Conditions                      |
| Funded                         | Loan Funded, Loan Recorded, Loan Closed                                                                                      |
| Post-Closing / Sold            | Loan Sold, Loan Purchased, Loan Ready For Sale, Loan Shipped and the investor and purchase review statuses                   |
| On Hold                        | Loan On Hold, Loan Suspended, Loan Counter Offer                                                                             |
| Cancelled / Denied / Withdrawn | Loan Canceled, Loan Denied, Loan Withdrawn, Loan Archived, Lead Cancel, Lead Declined                                        |

A status the list does not name belongs to no stage. Do not fail on one you have not seen. Filter the loan list by name with the `statuses` parameter.

## What you can call, by state

| Action                                                     | Needs                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ---------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Read and update loan fields, tasks, notes, vault documents | Any state.                                                                                                                                                                                                                                                                                                                                                                                                                       |
| Pricing                                                    | Any state.                                                                                                                                                                                                                                                                                                                                                                                                                       |
| Rate float and lock request                                | TPO loans only. On any other loan both are refused with `400` and the code `NotTpo`. A lock request is also refused (`409`) when one is already requested, when the loan is locked, and outside lock-desk hours, 13:30 to 23:59 UTC. A float is allowed at any hour.                                                                                                                                                             |
| E-sign: create a draft, send it                            | Any state. Needs vault documents and signers with an email. Both calls are billed and need their own scope, `send:esign-packages`. Nothing is sent when you create the draft. The response carries an `editorUrl`: open it to place each signer's signature field in the e-sign provider's editor, then call send. A send is refused (`422`) unless the package is still a draft, and also when a signer has no signature field. |
| Credit report order                                        | A credit report task on the loan that has no report yet.                                                                                                                                                                                                                                                                                                                                                                         |
| Automated underwriting run                                 | A submitted loan. Before the submit it is refused with `400`. Needs the scope `run:aus`. The run takes two calls to `POST .../aus/du/submit`: the first, with the body `{}`, sends nothing and returns a preview with a single-use `confirmationToken` (valid 15 minutes, for the same loan and acting user). Call again with that token to run it.                                                                              |
| Change of circumstance request                             | A submitted loan, until it is funded or ended. It is open from Processing through Clear to Close, and also earlier once the loan has an `externalId`. It is not available in Docs / Closing or On Hold.                                                                                                                                                                                                                          |
| Appraisal request                                          | After the initial loan estimate is signed.                                                                                                                                                                                                                                                                                                                                                                                       |

Each endpoint's page in the reference names the scope it needs.

## Webhooks

You subscribe to events per company with `POST /webhook/subscriptions`. The objects and events are:

| Object                         | Events                          |
| ------------------------------ | ------------------------------- |
| `LoanApplication`              | `Created`, `Changed`, `Deleted` |
| `LoanApplicationTask`          | `Created`, `Changed`, `Deleted` |
| `LoanApplicationVaultDocument` | `Created`, `Changed`, `Deleted` |

Each delivery is a `POST` with `eventId`, `occurredAt`, `companyId`, `entityId`, `objectType` and `eventType`. `objectType` and `eventType` are objects with an `id` and a `name`. It carries no loan data. A successful submit fires `LoanApplication.Changed`.

```json
{
  "companyId": "3f2b8c1e-0000-0000-0000-000000000000",
  "entityId": "6b1c0c0e-0000-0000-0000-000000000000",
  "objectType": { "id": "a1b2c3d4-0000-0000-0000-000000000000", "name": "LoanApplication" },
  "eventType": { "id": "e5f6a7b8-0000-0000-0000-000000000000", "name": "Changed" },
  "eventId": "9d0e1f2a-3b4c-4d5e-8f6a-7b8c9d0e1f2a",
  "occurredAt": "2026-11-28T10:15:30.1234567Z"
}
```

The ids are guids and the names above are examples. Match on `entityId` and read the object to see what changed.

* `eventId` identifies the event. If the same event reaches you twice it has the same `eventId`, so keep the ids you have handled and drop a repeat.
* `occurredAt` is when the change was saved, in UTC. Deliveries can arrive out of order; compare `occurredAt` when order matters.
* Expect new fields to appear. Ignore the ones you do not know.

A change to the LOS status that comes from the LOS does not fire a webhook. Poll `GET /loan-applications/{id}` or the filtered list to follow the status.

### Verifying a delivery

Every delivery carries the `x-api-key` header if you set an `apiKey` with `PUT /webhook`. To check that a delivery really came from Henge, create a signing secret:

1. `POST /webhook/signing-secret` (scope `update:webhooks`). The response holds `signingSecret`, which starts `whsec_`. It is returned only this once, so store it then. `GET /webhook` shows `hasSigningSecret` but never the secret.
2. From then on each delivery carries `Henge-Signature: t=<unix seconds>,v1=<signature>`.
3. On each delivery, take `t` and every `v1` from the header. Compute the lowercase hex HMAC-SHA256 of `t`, a `.`, and the raw request body exactly as received (before any JSON parsing), with the whole secret as the key. Accept the delivery if your value equals any `v1` (compare in constant time) and `t` is within 5 minutes of your clock. Otherwise reject it.

To rotate, call `POST /webhook/signing-secret` again. For 24 hours after a rotation the header carries one `v1` for the new secret and one for each secret it replaced in that time, so a receiver still using an earlier secret keeps accepting deliveries while you switch.

A Node.js check:

```javascript
const crypto = require("crypto");

function verify(rawBody, header, secret, toleranceSeconds = 300) {
  const parts = header.split(",").map((p) => p.split("="));
  const t = parts.find(([k]) => k === "t")?.[1];
  const signatures = parts.filter(([k]) => k === "v1").map(([, v]) => v);
  if (!t || Math.abs(Date.now() / 1000 - Number(t)) > toleranceSeconds) return false;
  const expected = crypto.createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex");
  return signatures.some((s) => s.length === expected.length &&
    crypto.timingSafeEqual(Buffer.from(s), Buffer.from(expected)));
}
```

Webhook delivery is best effort. See [Limits and reliability](https://api-docs.hengelending.com/api/guides/limits-and-reliability.md#webhooks).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://api-docs.hengelending.com/api/guides/loan-lifecycle.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
