> ## 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.

# Setting up sandbox

> Get to a working v2 call in sandbox, with credentials and webhooks ready

Sandbox is Lead's test system, and this page takes you from your credentials to your first v2 call there. To see how sandbox differs from production, read [Environments and testing](https://docs.lead.bank/v2/get-started/sandbox/environments-and-testing.md). The steps before and after sandbox testing are on [Program launch](https://docs.lead.bank/get-started/program-launch.md).

## Before you start

Your Technical Account Manager sets up your sandbox after you and Lead have agreed on your funds flow and how your activity maps to Lead's objects. [Program launch](https://docs.lead.bank/get-started/program-launch.md) has the full sequence. Then:

* Send your Technical Account Manager the HTTPS URL where you want to receive webhooks. If you restrict API access by IP address, send the IPv4 subnets your calls come from too. See [IP allowlist](https://docs.lead.bank/api-reference/using-the-api/authentication.md#ip-allowlist) for the limits.
* Get your sandbox `client_id` and `client_secret` from your Technical Account Manager, and store them where only your servers can read them.
* Get your webhook endpoint's signing secret from your Technical Account Manager. You need it in Step 3.

Those two values are your sandbox credentials. The `client_id` says which program is calling. The `client_secret` proves the call really comes from you, so treat it like a password. You don't send either one on every request. In Step 1, you trade them for an access token, and the token is what goes on each call after that. Both work only with `https://api.sandbox.lead.bank`. Production has its own pair.

A program is one product or set of products you run with Lead, and each program gets its own credentials. See [Programs and partners](https://docs.lead.bank/v2/core-concepts/platform/programs-and-partners.md).

## What you'll do

1. Get an access token.
2. Make your first call.
3. Set up your webhook handler.

## Steps

**1. Get an access token**

Exchange your credentials for an access token. Request only the scopes you need. Its path starts with `/v1`, and the token it returns works on v2 requests.

```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": "core_account/read"
  }'
```

**Modify your code:**

* Replace `CLIENT_ID` and `CLIENT_SECRET` with your sandbox credentials.
* Set `scope` to the scopes you need, separated by spaces. This example asks for one. Each scope is listed on [Authentication](https://docs.lead.bank/api-reference/using-the-api/authentication.md#available-scopes).
* Reuse the token until it expires. Don't request a new token for each call.

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

**Result:** `200`. Store `access_token` as `ACCESS_TOKEN` for Step 2. The token is valid for `expires_in` seconds, which is 24 hours by default.

**2. Make your first call**

List your program's core accounts, the accounts Lead opened for your program. The call needs no request body, so it tests your token and base URL before you create anything.

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

**Modify your code:**

* Replace `ACCESS_TOKEN` with the token from Step 1.

```json Sample response (trimmed) theme={null}
{
  "objects": [
    {
      "id": "core_account_7HgFdSa4PoIuYtReWq1ZxCvBnM2",
      "name": "Tidewater Pay Operating",
      "type": "direct",
      "status": "active",
      "created_at": "2026-10-16T15:00:00Z",
      "updated_at": "2026-10-16T15:00:00Z"
    }
  ],
  "has_more": false
}
```

**Result:** `200` with a list of core accounts. Your token and base URL work.

**3. Set up your webhook handler**

A webhook is how Lead tells you something changed without you having to ask. When a [funding](https://docs.lead.bank/v2/products/fundings/overview.md) (your instruction to Lead to send loan principal) reaches `posted`, for example, Lead sends an HTTPS request to the URL you gave your Technical Account Manager. Your webhook handler is the code at that URL that receives it. Set it up before you run [Originate your first loan](https://docs.lead.bank/v2/get-started/quickstart/originate-your-first-loan.md). The funding that quickstart creates can send your first event, and a broken signature check is better found in sandbox than in production.

If your endpoint is behind a firewall, allow the sandbox webhook address listed on [Webhooks & Events](https://docs.lead.bank/api-reference/using-the-api/webhooks-v2.md#webhook-ip-addresses). Lead retries a delivery that doesn't get a `2xx` response, and the same event can arrive more than once. The schedule is on the same page.

**Modify your code:**

* Verify the `Lead-Signature` header on every delivery before you act on it, using your endpoint's signing secret. The steps are on [Webhooks & Events](https://docs.lead.bank/api-reference/using-the-api/webhooks-v2.md#webhook-authentication).
* Respond with a `2xx` status.
* Use the event `id` to skip a delivery you've already handled.

**Result:** Your handler verifies the signature, returns `2xx`, and ignores a repeated `id`. The first event arrives when an object in your program changes to a status that sends one. Not every status change does. [Webhooks & Events](https://docs.lead.bank/api-reference/using-the-api/webhooks-v2.md) lists the v2 events and the fields in an event body.

## What happens next

Nothing on this page creates an object or sends a webhook. [Originate your first loan](https://docs.lead.bank/v2/get-started/quickstart/originate-your-first-loan.md) creates a borrower, a loan, and a funding. If funding events are enabled for your program, the posted funding sends your first event. Your Technical Account Manager can tell you whether they are.

## Common errors

These are the errors you're most likely to see on this page:

| What you see | Why | Fix |
| - | - | - |
| `403` with `authentication_missing` | The request has no `Authorization` header. | Send the token as `Authorization: Bearer ACCESS_TOKEN`. |
| `403` with `token_invalid` | The token is expired or invalid, or it doesn't have the scope the endpoint needs. | Get a new token in Step 1 with the right scope. |
| `403` with `source_ip_not_permitted` | The call came from an address that isn't on your allowlist. | Call from an allowlisted subnet, or ask your Technical Account Manager to add yours. |
| `403` on the token request, with `insufficient_scope` | Your program isn't set up for one of the scopes you asked for. The token endpoint uses the v1 error format, described on [Errors](https://docs.lead.bank/api-reference/using-the-api/errors.md). | Remove the scope, or ask your Technical Account Manager to add it to your program. |

The other v2 errors are on [Errors](https://docs.lead.bank/api-reference/using-the-api/errors-v2.md).

## Test in sandbox

Every step on this page runs in sandbox. For the test run that follows, see [Test and go live with fundings](https://docs.lead.bank/v2/products/fundings/test-and-go-live.md).

## Next step

[Originate your first loan](https://docs.lead.bank/v2/get-started/quickstart/originate-your-first-loan.md) in sandbox, from a token to a posted funding.

## Related

* [Environments and testing](https://docs.lead.bank/v2/get-started/sandbox/environments-and-testing.md): how sandbox and production differ, and what sandbox simulates
* [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
* [Authentication](https://docs.lead.bank/api-reference/using-the-api/authentication.md): the token endpoint, every scope, and the IP allowlist limits
* [Webhooks & Events](https://docs.lead.bank/api-reference/using-the-api/webhooks-v2.md): how to verify a signature, retries, the v2 event body, and the event list
* [Program launch](https://docs.lead.bank/get-started/program-launch.md): the milestones from kickoff through sandbox testing to go-live, and when you get credentials
