BorrouPartner APISandboxDraft

Draft documentation for partners integrating against the sandbox. It can change before /v1 is published; the contract, openapi.yaml, is the reference.

Overview / Guides / Get started

Sandbox quick-start

v0.2 draftOne loan through the sandbox with API calls only, with the Bruno collection and the code snippets.

Take one loan through the sandbox with API calls only, then read it while it runs. Plan on less than an hour, most of it reading.

What you need

  • A sandbox credential from TFG: a client_id (bpc_test_…) and a client_secret. Keep the secret in your secret manager. It never goes in a file you commit.
  • The sandbox base URL: https://api.borrou.capital.
  • Optionally, an endpoint of your own to receive webhooks: https on the default port (443), with no user name or password in the URL, on a public DNS name that resolves only to public addresses (422 invalid_destination otherwise). Without one, the run still works: the environments point webhook_url at a placeholder on example.com, so deliveries are queued and listed, and do not reach you.
  • Bruno (the app, or its CLI through npx), and Node 20 or later for the CLI.

Run the collection

The collection is plain text in bruno/: open the folder in the Bruno app, choose the Sandbox environment, set client_id, set client_secret as a secret value, set webhook_url if you have an endpoint, and run the collection. Or, from the bruno folder:

export BORROU_CLIENT_ID=bpc_test_...
export BORROU_CLIENT_SECRET=...   # from your secret manager
npx @usebruno/cli@4 run -r --env Sandbox \
  --env-var client_id="$BORROU_CLIENT_ID" --env-var client_secret="$BORROU_CLIENT_SECRET" \
  --reporter-skip-headers Authorization

Every request checks its answer, so the run doubles as a smoke test of your access. A report written with --reporter-json records response bodies, the webhook signing secret's included: keep it out of shared places.

What happens

FolderStepsWho acts
01 AuthenticationThe access token, cached for the runYou
02 Catalogue and quoteYour products, the checked BTC price, a quote and its quote_token; the public keys collateral addresses are signed withYou
03 WebhooksA subscription and its signing secretYou
04 OriginationAn application for a synthetic borrower; a retry with the same Idempotency-Key, replayed; the same key with another request, refused; the KYC hand-off; the borrower's KYC and TFG's review (simulated); the loan; its contract; the borrower's signature (simulated); the deposit address, with Borrou's signature on it; the deposit (simulated); the collateral position; next_action: TFG_APPROVES_PAYOUTYou, then the simulators for the borrower, the providers, the custodian and TFG's reviewer
05 PayoutThe payout's status; advance; the loan, ACTIVEOn Borrou's sandbox, advance plays both: the payout's two approvals by the sandbox's two simulated TFG users, then the custodian
06 Servicing readsWhat the loan owes, coverage, interest periods, the schedule, margin calls, statements, repayment instructionsYou (read-only)
07 Upper limitThe loan's position against its upper limit; a top-up (simulated) to put it above; an increase request; the borrower's one-time code read back (sandbox only); the borrower's acceptance with the code; the increase withdrawn againYou, and the simulator for the borrower
08 Events feed and listsThe events feed from the oldest (waiting up to 90 seconds for the first), the next page, a catch-up to this run's loan.created; your loans, one page at a timeYou
09 Webhook deliveriesThe subscription's deliveries (waiting up to 90 seconds for the first), a replay, the subscription disabledYou
10 Retail flowOnly with the credential of a partner whose product is the retail one (bullet, accepted with a one-time code); skipped otherwise. The product and a quote, an application, the KYC hand-off and review (simulated), the loan, the click-wrap contract, the one-time code sent, read back (simulated) and entered, the deposit (simulated), next_action: TFG_APPROVES_PAYOUT and the payout's destination, your settlement account; then advance, the loan ACTIVE with its maturity, strike and trigger prices, the payout EXECUTED, and the repayment instructionsYou, then the simulators

With the credential of a partner whose product is accepted with a one-time code, the whole collection still runs: folder 04 stops at the contract (its signing-link steps skip themselves), folder 05 and the servicing folders skip, and folder 10 takes a loan of its own from the quote to the payout. The retail flow also runs on its own, with that partner's sandbox credential (ask TFG):

npx @usebruno/cli@4 run 10-retail-flow -r --env Sandbox \
  --env-var client_id="$BORROU_RETAIL_CLIENT_ID" --env-var client_secret="$BORROU_RETAIL_CLIENT_SECRET" \
  --reporter-skip-headers Authorization

The sandbox says what the retail product's terms mean and what the loan shows once it is active.

The payout. In live, every payout needs two different people at TFG to approve it before the custodian is instructed. On Borrou's sandbox those two approvals are simulated: advance (folder 05, and the retail flow) enters and approves the payout as the sandbox's two simulated TFG users, through the same two-person checks, then plays the custodian; the loan becomes ACTIVE and the servicing and upper-limit folders run. Folder 07 leaves the loan as it found it (the increase withdrawn), so it can run again.

On a sandbox where those simulated approvals are off, the run stops at the payout instead: after folder 04 the loan reads COLLATERAL_DEPOSITED with next_action: TFG_APPROVES_PAYOUT, advance answers 409 sandbox_step_unavailable, and folders 06 and 07 are skipped. Ask your TFG contact to approve the payout of your loan (the LN- reference the run printed), then resume:

npx @usebruno/cli@4 run 05-payout 06-servicing 07-upper-limit -r --env Sandbox \
  --env-var client_id="$BORROU_CLIENT_ID" --env-var client_secret="$BORROU_CLIENT_SECRET" \
  --env-var loan_reference=LN-.... --reporter-skip-headers Authorization

After the payout, the repayment. In live, TFG records the repayment and returns the collateral, two people each. On Borrou's sandbox POST /v1/sandbox/loans/{reference}/repayment (proposed, may change) plays the borrower's transfer and the two simulated TFG users' entry and confirmation of it, and advance then plays the collateral's return: the loan ends CLOSED.

Each run creates one synthetic application and loan, and disables the webhook subscription it made. Every loan that is not closed, liquidated, cancelled or rejected counts against your capacity: cancel one still waiting for its payout with POST /v1/loans/{reference}/cancel when you no longer need it, and ask your TFG contact to close active sandbox loans you are done with.

The snippets

snippets/ has the same building blocks in three languages, with no framework:

Client (token cache, idempotent writes with retries, cursor pagination)Webhook verificationTry it
TypeScript (Node 20+, built-in fetch)typescript/borrouClient.tstypescript/webhooks.tsnpx tsx typescript/quickstart.ts
Python 3.9+ (requests)python/borrou_client.pypython/borrou_webhooks.py (standard library only)python3 python/quickstart.py
Java 17+ (java.net.http, no dependencies)java/BorrouClient.javajava/BorrouWebhooks.javajavac -d out java/*.java && java -cp out Quickstart

Each quickstart reads BORROU_BASE_URL, BORROU_CLIENT_ID and BORROU_CLIENT_SECRET from the environment, reads your products, a quote, your events and your loans, and with a sandbox credential submits one synthetic application twice with the same key, to show the replay.

Every deposit and top-up address comes signed by Borrou; verify it before your app shows it (Verifying an address): typescript/addressVerification.ts, python/borrou_addresses.py (needs cryptography) and java/BorrouAddresses.java.

Each verification is tested against signatures made by Borrou's own signing code (snippets/fixtures/webhook-signatures.json, snippets/fixtures/address-attestations.json):

python3 -m pip install cryptography
python3 -m unittest discover -s snippets/python
javac -d out snippets/java/*.java && java -cp out BorrouWebhooksTest snippets/fixtures/webhook-signatures.json
java -cp out BorrouAddressesTest snippets/fixtures/address-attestations.json
  • Rules and checklist: the rules of the integration in one place, and a checklist to finish with (written for coding agents; useful to people too).
  • Error codes: every error code, when it happens and what to do.
  • Verifying an address: how to check a collateral address's signature before your app shows it, and the verification code the borrower compares.
  • The sandbox: what each simulator does, its guards, and what it never does.
  • Versioning: what may change inside /v1, and how anything else is announced (proposed).
  • openapi.yaml, handed over with these documents (and, where Borrou publishes it, at GET /openapi.yaml): the contract.