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

# Run the complete integration example

> Run a Sandbox client from Hub authorization through underwriting, evidence, Signal deal snapshots and billing, using returned IDs and safe command retries.

Use this reference client to connect a borrower, submit an origination, retrieve its results, enroll monitoring and reconcile billing in AMLOK Sandbox. It combines the endpoint examples into one journey and preserves command identities across interruptions.

## Download the example

Save these files together:

* [amlok-journey.mjs](https://docs.amlok.io/downloads/amlok-journey.mjs)
* [journey-inputs.json](https://docs.amlok.io/downloads/journey-inputs.json)
* [consumer-journey-inputs.json](https://docs.amlok.io/downloads/consumer-journey-inputs.json)
* [synthetic-statement.pdf](https://docs.amlok.io/downloads/synthetic-statement.pdf)

Use Node.js 22 or newer, which supplies fetch, FormData, Blob and structuredClone. No package installation is needed. The file is a reference client, not a distributed product SDK.

## Provision the test environment

An Owner obtains the API origin, creates a Sandbox key, and publishes a Hub containing configuration.sandbox.test\_integration\_id. Approve your return URL and both credit\_assessment and continuous\_monitoring purposes. For this complete example, the Owner key needs borrowers:read/write, connections:read/write, configuration:read/write, insights:read/write, results:read, evidence:read/write, data:read, signal:read/write, billing:read, exports:read/write and reliability:read.

Set AMLOK\_BORROWER\_TYPE=person and use a fresh state file to run the consumer fixture, which uses gross monthly income, monthly debt payments and a synthetic debt\_to\_income rule. Check configuration for the corresponding application schema and supported policy dimensions.

The default development input file uses a Canadian business, a fixed-rate term loan, annual\_revenue application data and a dscr rule. Match the application schema, pricing schema and metric IDs to those returned by configuration. Update the input file if your environment uses different schemas.

```bash theme={null}
export AMLOK_API_BASE_URL="<institution-issued Sandbox origin>"
export AMLOK_API_KEY="<server-side Sandbox key>"
export AMLOK_EMBEDDING_VERSION_ID="<published test Hub version>"
export AMLOK_RETURN_URL="<approved return URL>"
node amlok-journey.mjs prepare amlok-journey-state.json
```

The placeholders above are provisioning values, not working credentials. Prefer a secret manager instead of shell history on shared systems. The state file contains synthetic inputs and resource IDs but no API key or launch URL. Keep it private; use a distinct file for each new journey.

## Connect, submit and reconcile

Prepare creates the borrower, product/policy versions and embedding session. Open the printed short-lived URL privately and select **Connect test institution**. Affirm both purposes. Then run:

```bash theme={null}
node amlok-journey.mjs complete amlok-journey-state.json
```

Complete retrieves the authoritative session, uploads the supplied PDF, submits the origination and waits within a bounded interval. It reads the risk package, all evidence and a complete data snapshot, obtains a change-feed checkpoint, enrolls Signal, appends a lender deal snapshot, reads monitoring runs and alerts, prepares a JSON risk-package export and a controlled download capability, and reads payments, usage and transactions against one billing snapshot.

Expected output identifies the origination, package, monitor, deal snapshot and billing snapshot, plus record counts and available credits. IDs and counts come from your API responses.

The journey stops visibly on requires\_action, waiting\_for\_credits or failed. Follow [recovery instructions](https://docs.amlok.io/api-reference/processing-lifecycle.md), then rerun complete with the same state file. Never replace an accepted origination simply because your client timed out. The example uses bounded transport retries and request receipts; production applications should use a transactional database/outbox for durable state instead of a local JSON file.

## Browser integration and event handling

Use the [browser helper](https://docs.amlok.io/downloads/hub-embed.js) and [Hub protocol](https://docs.amlok.io/api-reference/integration-hub.md) to integrate into your own UI. Your authenticated backend supplies the session and verifies completion. Use the downloadable [Node.js verifier](https://docs.amlok.io/downloads/verify-webhook.mjs) or [Python verifier](https://docs.amlok.io/downloads/verify_webhook.py) with a durable event inbox before acknowledging webhooks.

## Test failures deliberately

Set AMLOK\_SCENARIO to a documented [Sandbox scenario](https://docs.amlok.io/api-reference/sandbox-journeys.md) and use a new state file. This client exercises the main happy path and exposes structured blocking states. The scenario manifest and acceptance checklist cover additional security, failure, expiry, event and billing behaviors. Use the [integration checklist](https://docs.amlok.io/api-reference/integration-acceptance.md) to verify your application's handling of each outcome.


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