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

# Originate your first loan

> Go from your first v2 call to a funded term loan in sandbox

This quickstart creates a borrower, reports an approved application, opens a credit user account, and defines a term loan. Then it draws the principal with a funding and posts it in sandbox. Every call runs in sandbox, Lead's test system, so nothing here moves real money.

It doesn't cover uploading loan documents, sending the money on to the borrower, or reporting repayments. Those are in [Originate and service an on-sheet loan](https://docs.lead.bank/v2/guides/lend/on-sheet-loan-origination-and-servicing.md), which is the full version of this flow. To get sandbox credentials first, see [Set up sandbox](https://docs.lead.bank/v2/get-started/sandbox/setup.md). This page is the v2 version. The v1 quickstart, [Originate your first loan](https://docs.lead.bank/get-started/quickstart/originate-your-first-loan.md), uses the `/v0` endpoints.

## Before you start

* Get sandbox credentials and make one successful call. See [Set up sandbox](https://docs.lead.bank/v2/get-started/sandbox/setup.md).
* Have your program's `product_config_id`. A program is one product or set of products you run with Lead. Your Technical Account Manager gives you the ID. There is no endpoint to look it up.
* Ask your Technical Account Manager which account number Lead has enabled to receive fundings, and have its ID.

## What you'll do

1. Get a token with the scopes this flow needs.
2. Create the borrower as an entity.
3. Report the underwriting decision as an application.
4. Open the user account.
5. Define the loan as a user credit balance.
6. Draw the principal with a funding.
7. Post the funding in sandbox.
8. Confirm the money moved.

## Steps

### Step 1: Get a token

One token covers the whole flow if you request every scope up front.

```bash Sample request theme={null}
curl --request POST \
  --url https://api.sandbox.lead.bank/v1/oauth/token \
  --header 'Content-Type: application/json' \
  --data '{
    "grant_type": "client_credentials",
    "client_id": "CLIENT_ID",
    "client_secret": "CLIENT_SECRET",
    "scope": "entity/read_write application/read_write user_account/read_write user_credit_balance/read_write funding/read_write"
  }'
```

**Modify your code:**

* Replace `CLIENT_ID` and `CLIENT_SECRET` with your sandbox credentials.
* Store `access_token` from the response as `ACCESS_TOKEN` and send it on every call in this flow.

```json Sample response theme={null}
{
  "access_token": "ACCESS_TOKEN",
  "token_type": "Bearer",
  "expires_in": 86400
}
```

**Result:** `200`. The token is valid for `expires_in` seconds, which is 24 hours by default.

### Step 2: Create the borrower as an entity

The borrower is an individual who will hold the loan, so send `intended_eligibility: ["account_holder"]`. Lead then checks that the entity has everything an account holder needs. If it doesn't, the request fails now, not at account opening.

```bash Sample request theme={null}
curl --request POST \
  --url https://api.sandbox.lead.bank/v2/entities \
  --header 'Authorization: Bearer ACCESS_TOKEN' \
  --header 'Idempotency-Key: 9f3c2a4e-1b7d-4e6a-8c2f-5d1e0b7a9c3e' \
  --header 'Content-Type: application/json' \
  --data '{
    "type": "individual",
    "first_name": "Riley",
    "last_name": "Example",
    "date_of_birth": "1990-04-02",
    "contact_methods": [
      { "type": "email", "email": "riley@example.com" }
    ],
    "physical_address": {
      "line_1": "100 Example Way",
      "city": "Anytown",
      "state": "CA",
      "postal_code": "99999",
      "country": "US"
    },
    "identification": {
      "type": "us_entity",
      "tax_identification": { "type": "ssn", "value": "TAX_ID" }
    },
    "intended_eligibility": ["account_holder"],
    "risk_score": "low",
    "kyc": { "result": "passed", "screened_at": "2026-10-16T15:00:00Z" },
    "ofac": { "result": "passed", "screened_at": "2026-10-16T15:00:00Z" }
  }'
```

**Modify your code:**

* Replace `TAX_ID` with the borrower's SSN, nine digits. For an ITIN, set `tax_identification.type` to `itin`.
* Set `kyc` and `ofac` to the result and time of your own screening.
* Set `risk_score` from your own risk rating.
* Generate a new `Idempotency-Key` for this request. A UUID works. Every `POST` from here on needs its own key. Reuse a key only to retry the same request.

```json Sample response (trimmed) theme={null}
{
  "id": "entity_3XkTBcRw5nYs1LvKqM7hZjDp0Ug",
  "type": "individual",
  "intended_eligibility": ["account_holder"],
  "eligibility": {
    "account_holder": { "status": "eligible", "failed_checks": [] },
    "authorized_signer": { "status": "eligible", "failed_checks": [] },
    "authorized_user": { "status": "eligible", "failed_checks": [] },
    "minor_account_holder": { "status": "ineligible", "failed_checks": [
      { "check": "check_date_of_birth_above_maximum", "entity_id": "entity_3XkTBcRw5nYs1LvKqM7hZjDp0Ug", "details": "The entity exceeds the maximum age for minor_account_holder." }
    ] }
  },
  "created_at": "2026-10-16T15:00:00Z"
}
```

**Result:** `200`. `eligibility.account_holder.status` is `eligible`. Store `id` as `ENTITY_ID`.

### Step 3: Report the underwriting decision as an application

You underwrite in your own system and report the result. An application is reported in a terminal status, here `approved`. Amounts are in minor units, so a \$5,000 limit is `500000`.

```bash Sample request theme={null}
curl --request POST \
  --url https://api.sandbox.lead.bank/v2/applications \
  --header 'Authorization: Bearer ACCESS_TOKEN' \
  --header 'Idempotency-Key: 2b6d4f8a-3c5e-4a7b-9d1f-6e2c8a4b0d7e' \
  --header 'Content-Type: application/json' \
  --data '{
    "status": "approved",
    "product_config_id": "PRODUCT_CONFIG_ID",
    "entities": {
      "account_holder_ids": ["ENTITY_ID"]
    },
    "underwriting": {
      "is_secured": false,
      "is_mla": false,
      "currency": "USD",
      "grade": "A",
      "limit": 500000,
      "max_limit": 500000
    },
    "decision": {
      "decided_at": "2026-10-16T15:05:00Z",
      "details": "Meets program underwriting criteria"
    },
    "documents": []
  }'
```

**Modify your code:**

* Replace `PRODUCT_CONFIG_ID` with the value from your Technical Account Manager, and `ENTITY_ID` with the ID from Step 2.
* Set `underwriting.grade`, `limit`, and `max_limit` from your decision, and `decision.details` to the reason for it.
* Send `documents` as `[]`. The full guide covers uploading loan documents.
* Generate a new `Idempotency-Key`.

```json Sample response (trimmed) theme={null}
{
  "id": "application_4GhJkLmN8pQrStUvWxYz1AbCd2E",
  "status": "approved",
  "entities": {
    "account_holder_type": "consumer",
    "account_holder_ids": ["entity_3XkTBcRw5nYs1LvKqM7hZjDp0Ug"],
    "authorized_signer_ids": []
  },
  "created_at": "2026-10-16T15:05:00Z"
}
```

**Result:** `200`. `account_holder_type` is `consumer` because the only account holder is an individual. Store `id` as `APPLICATION_ID`.

### Step 4: Open the user account

The user account is the borrower's credit relationship with Lead. Two fields decide what it is: `requested_features` says it's underwritten credit, and `balance_sheet_model` says Lead holds the loan.

```bash Sample request theme={null}
curl --request POST \
  --url https://api.sandbox.lead.bank/v2/user_accounts \
  --header 'Authorization: Bearer ACCESS_TOKEN' \
  --header 'Idempotency-Key: 7a1e3c5b-9d2f-4b8a-a6c4-0e3f1d5b7a9c' \
  --header 'Content-Type: application/json' \
  --data '{
    "application_id": "APPLICATION_ID",
    "requested_features": ["credit_with_underwriting"],
    "balance_sheet_model": "held_for_investment",
    "product_config_id": "PRODUCT_CONFIG_ID",
    "entities": {
      "account_holder_ids": ["ENTITY_ID"]
    },
    "underwriting": {
      "is_secured": false,
      "is_mla": false,
      "grade": "A",
      "currency": "USD",
      "available_credit": 500000,
      "limit": 500000,
      "max_limit": 500000
    },
    "documents": []
  }'
```

**Modify your code:**

* Replace `APPLICATION_ID` with the ID from Step 3, and `ENTITY_ID` and `PRODUCT_CONFIG_ID` as before.
* Send all seven fields in `underwriting`.
* Generate a new `Idempotency-Key`.

```json Sample response (trimmed) theme={null}
{
  "id": "user_account_2xYv6Kn3Jp7QuS2lY5mAbC0dE4f",
  "status": "active",
  "application_id": "application_4GhJkLmN8pQrStUvWxYz1AbCd2E",
  "features": ["credit_with_underwriting"],
  "balance_sheet_model": "held_for_investment",
  "created_at": "2026-10-16T15:06:00Z"
}
```

**Result:** `200`. `status` is `active` and `features` is what Lead granted. Store `id` as `USER_ACCOUNT_ID`.

### Step 5: Define the loan as a user credit balance

The user credit balance holds the loan's terms, and later its running position. A `non_revolving` loan needs all its terms up front: maturity date, maximum funding amount, duration, finance charge, and repayment schedule. This example is $5,000 over 12 months at 9.99%. That's 12 monthly payments of $439.56, and \$274.72 in total interest.

Rates are decimal fractions, so 9.99% is `0.0999`. The three rate fields mean different things:

| Field | What it is | In this example |
| - | - | - |
| `interest_rate` | The contractual rate, before compounding | `0.0999` |
| `effective_interest_rate` | The rate with compounding | `0.1046`, compounded monthly |
| `effective_apr` | The APR you disclosed to the borrower | `0.0999` |

`effective_apr` matches `interest_rate` here because this loan has no fees.

```bash Sample request theme={null}
curl --request POST \
  --url https://api.sandbox.lead.bank/v2/user_credit_balances \
  --header 'Authorization: Bearer ACCESS_TOKEN' \
  --header 'Idempotency-Key: 4c8a2e6d-0b3f-4d7c-8e1a-2f5b9c3d6e0a' \
  --header 'Content-Type: application/json' \
  --data '{
    "user_account_id": "USER_ACCOUNT_ID",
    "name": "Personal Term Loan - Riley Example",
    "currency": "USD",
    "autopay_method": "ach",
    "terms": {
      "structure": "non_revolving",
      "interest_rate": "0.0999",
      "effective_interest_rate": "0.1046",
      "effective_apr": "0.0999",
      "expected_maturity_date": "2027-11-01",
      "max_funding_amount": 500000,
      "duration": { "length": 12, "unit": "months" },
      "expected_finance_charge_amount": 27472,
      "repayment": {
        "expected_payment_frequency": "monthly",
        "expected_number_of_payments": 12,
        "expected_payment_amount": 43956,
        "expected_first_payment_date": "2026-12-01"
      }
    }
  }'
```

**Modify your code:**

* Replace `USER_ACCOUNT_ID` with the ID from Step 4.
* Set `terms` from your own loan. Every field is on [The user credit balance object](https://docs.lead.bank/v2/products/user-credit-balance/user-credit-balance-object.md).
* Generate a new `Idempotency-Key`.

```json Sample response (trimmed) theme={null}
{
  "id": "user_credit_balance_1HCpXwx2EK9oYluWbacgeCnFcLf",
  "user_account_id": "user_account_2xYv6Kn3Jp7QuS2lY5mAbC0dE4f",
  "status": "active",
  "amount": 0,
  "amount_breakdown": { "principal": 0, "interest": 0, "fees": 0 },
  "terms": {
    "structure": "non_revolving",
    "max_funding_amount": 500000
  },
  "created_at": "2026-10-16T15:07:00Z"
}
```

**Result:** `200`. The user credit balance is `active` with every amount at zero. Store `id` as `USER_CREDIT_BALANCE_ID`.

### Step 6: Draw the principal with a funding

A funding moves the principal from Lead's general ledger to an account number your program controls. `amount` is the whole principal. On a `non_revolving` balance, this funding plus any earlier ones can't add up to more than `max_funding_amount`.

```bash Sample request theme={null}
curl --request POST \
  --url https://api.sandbox.lead.bank/v2/fundings \
  --header 'Authorization: Bearer ACCESS_TOKEN' \
  --header 'Idempotency-Key: 6e0b4d8f-2a5c-4f9e-b7d3-1c4a8e2f5b0d' \
  --header 'Content-Type: application/json' \
  --data '{
    "user_credit_balance_id": "USER_CREDIT_BALANCE_ID",
    "account_number_id": "ACCOUNT_NUMBER_ID",
    "currency": "USD",
    "amount": 500000
  }'
```

**Modify your code:**

* Replace `USER_CREDIT_BALANCE_ID` with the ID from Step 5.
* Replace `ACCOUNT_NUMBER_ID` with the account number Lead enabled for fundings, from Before you start.
* Store the funding ID when it comes back. There is no list endpoint for fundings.
* Generate a new `Idempotency-Key`.

```json Sample response theme={null}
{
  "id": "funding_0o5Fs0EELR0fUjHjbCnEtdUwQe3",
  "user_credit_balance_id": "user_credit_balance_1HCpXwx2EK9oYluWbacgeCnFcLf",
  "account_number_id": "account_number_5TrEwQ8aSdFgHjKlZxCvB3nM6q",
  "currency": "USD",
  "amount": 500000,
  "status": "processing",
  "created_at": "2026-10-16T15:08:00Z"
}
```

**Result:** `200`. `status` is `processing`. In production, Lead posts it. In sandbox, it waits for you. Store `id` as `FUNDING_ID`.

### Step 7: Post the funding in sandbox

Nothing in sandbox moves on its own, so move the funding to `posted` yourself with the advance call. It's the one call on this page that exists only in sandbox.

```bash Sample request theme={null}
curl --request POST \
  --url https://api.sandbox.lead.bank/v2/simulate/fundings/FUNDING_ID/advance \
  --header 'Authorization: Bearer ACCESS_TOKEN' \
  --header 'Idempotency-Key: 8d2f6a0c-4e7b-4a1d-9c5e-3b6f0d8a2c4e' \
  --header 'Content-Type: application/json' \
  --data '{ "next_status": "posted" }'
```

**Modify your code:**

* Replace `FUNDING_ID` with the ID from Step 6.
* Keep this call out of your production code. In production it returns `404`.
* Generate a new `Idempotency-Key`.

```json Sample response theme={null}
{}
```

**Result:** `200` with an empty object. The funding is now `posted`. Lead sends `funding.posted` when funding events are enabled for your program. Your Technical Account Manager can tell you whether they are.

### Step 8: Confirm the money moved

Read the funding back. Don't wait for a webhook: retrieving the object is the reliable check, in sandbox and in production. Then check that Lead recorded the draw on the user credit balance.

```bash Sample request theme={null}
curl --request GET \
  --url https://api.sandbox.lead.bank/v2/fundings/FUNDING_ID \
  --header 'Authorization: Bearer ACCESS_TOKEN'
```

**Modify your code:**

* Replace `FUNDING_ID` with the ID from Step 6.
* Confirm the funding is `posted` before you send money on to the borrower. The `200` from Step 6 doesn't mean the money moved.
* Do not post a user credit transaction for the draw yourself. Lead posts a `funding` user credit transaction for you. It can arrive a few seconds after `funding.posted`.

```json Sample response (trimmed) theme={null}
{
  "id": "funding_0o5Fs0EELR0fUjHjbCnEtdUwQe3",
  "amount": 500000,
  "status": "posted",
  "posted_at": "2026-10-16T15:09:00Z"
}
```

**Result:** `200` with `status` `posted`. A funding posted in sandbox has no `core_transaction_id`. In production it names the core transaction that moved the money. To see the draw, call `GET /v2/user_credit_balances/USER_CREDIT_BALANCE_ID`. `amount_breakdown.principal` is `500000`. If it's still `0`, wait a few seconds and call again.

## What happens next

In production, Step 7 doesn't exist. Lead moves the funding to `posted` when the money reaches your account number, and sets `core_transaction_id`. If funding events are enabled for your program (your Technical Account Manager can tell you), Lead also sends `funding.posted`. The funding is the only object on this page with an event, so retrieve the entity, application, user account, and user credit balance when you need their current state. See [Funding statuses](https://docs.lead.bank/v2/products/fundings/statuses.md).

## Common errors

Errors you can hit in this flow:

| What you see | Why | Fix |
| - | - | - |
| `422 parameters_invalid` on Step 2, with `eligibility_check_failed` entries | The entity is missing something an account holder needs | Each entry names the check. Add the field and retry. See [Entity eligibility](https://docs.lead.bank/v2/products/entity/eligibility.md). |
| `422 parameters_invalid` on Step 4, with `dependent_parameter_required` | `credit_with_underwriting` needs `application_id`, `balance_sheet_model`, and `underwriting` | Send all three. |
| `422 lead_control_restricted` on Step 4 or Step 6 | A setting Lead controls for your program blocks the request. On Step 4, your program isn't enabled for v2 user accounts. On Step 6, your program has no funding destination set up, or the account number isn't enabled for fundings. | Contact your Technical Account Manager. |
| `422 limit_exceeded` on Step 6 | The fundings on this balance would add up to more than `max_funding_amount`. | Lower `amount`. `max_funding_amount` can't be changed. |
| `422 object_state_mismatched` on Step 7 | The funding is already `posted` | Nothing to do. A funding moves to `posted` once. |
| `400` | A `POST` is missing its `Idempotency-Key` header. | Send a new key with each `POST` from Step 2 on. See [Idempotency](https://docs.lead.bank/api-reference/using-the-api/idempotency-v2.md). |

Every call after Step 1 uses the v2 error body. See [Errors](https://docs.lead.bank/api-reference/using-the-api/errors-v2.md). The token call in Step 1 uses Lead's older error format.

## Test in sandbox

Every step on this page runs in sandbox. For the full set of funding tests before you go live, see [Test and go live with fundings](https://docs.lead.bank/v2/products/fundings/test-and-go-live.md).

## Next step

[Build the full flow](https://docs.lead.bank/v2/guides/lend/on-sheet-loan-origination-and-servicing.md), with loan documents, the disbursement to the borrower, and repayment reporting.

## Related

* [Originate and service an on-sheet loan](https://docs.lead.bank/v2/guides/lend/on-sheet-loan-origination-and-servicing.md): the full lending flow this page is the short version of
* [Test and go live with fundings](https://docs.lead.bank/v2/products/fundings/test-and-go-live.md): moving a funding to `posted` in sandbox, and a full test run
* [Move objects and trigger events in sandbox](https://docs.lead.bank/v2/get-started/sandbox/advance-and-simulate.md): the two sandbox-only calls, their rules, and their errors
* [Entity eligibility](https://docs.lead.bank/v2/products/entity/eligibility.md): what an account holder needs and the checks Lead runs
* [Idempotency](https://docs.lead.bank/api-reference/using-the-api/idempotency-v2.md): how the `Idempotency-Key` header works on v2 requests
