Skip to main content

Build the collection button

The Starter Integration puts a "Send to collection" button beside an unpaid invoice. Your server sends the invoice to Debitura in one request. Debitura works out what the client still has to do (sign up, approve the connection, sign an agreement, verify identity or fix the invoice) and returns one link to open. You follow the request until it becomes a case.

Use this when: you want collection in your product without building onboarding, agreement or error-handling screens. You'll build: one server call, a button that opens a link, and one webhook handler. New to Starter? Do the quickstart first.

How it works​

After the client finishes a step, read the request again. Eligible requests progress and the current read supplies the next solutionUrl, if more is needed. Your button opens that returned link; a webhook alone is not proof that every setup step has finished.

1. Send one invoice​

Call POST /collection-requests from your server with your API key. Never call it from browser code. The API reference lists every field.

POST https://testreferral-api.debitura.com/collection-requests
XApiKey: <your-test-partner-key>
Idempotency-Key: collection-example-inv-0042
Content-Type: application/json

{
"externalTenantId": "example-client-42",
"client": {
"name": "Example Client Ltd",
"country": "GB",
"supportEmail": "accounts@example.invalid"
},
"user": {
"name": "Example User",
"email": "accounts@example.invalid"
},
"invoices": [{
"creditorReference": "EXAMPLE-INV-0042",
"debtor": {
"type": "Company",
"name": "Example Debtor Ltd",
"countryAlpha2": "GB",
"address": "10 Example Street",
"city": "London"
},
"amountToRecover": 1500.00,
"currencyCode": "GBP",
"date": "2026-06-01T00:00:00Z",
"dueDate": "2026-06-30T00:00:00Z",
"isTest": true
}]
}

What to know about the request:

  • One invoice per request. invoices is an array with exactly one item. If your user selects several invoices, send one request each.
  • Your identifiers. externalTenantId is your stable ID for the client, and creditorReference is the invoice number. You use both to look a request up later.
  • Client details are used once. client and user set up a new account. They never overwrite an account that already exists.
  • Retries are safe when you reuse the same Idempotency-Key. For 24 hours, the same key returns the original response; a changed payload with that key is refused. Because it is the original response, it can show an earlier step than where the client is now, so use a current read to check progress.
  • Return navigation after the hosted pages is set on your partner account, not per request. Never build onboarding or signing URLs yourself.

2. Open the next action​

The response says where the request stands and, if the client has something to do, gives you the link. For a new client:

{
"id": "33333333-3333-4333-8333-000000000042",
"status": "awaiting_onboarding",
"solutionType": "onboarding",
"solutionUrl": "https://testreferral.debitura.com/Onboarding/CompanyDetails/55555555-5555-4555-8555-555555555555",
"externalTenantId": "example-client-42"
}

Store the request id. After the response arrives, show a link the user can click to continue; opening a popup after an asynchronous call may be blocked. Use the current returned URL, never one assembled from IDs. Suggested labels and actions:

statusSuggested labelAction
awaiting_onboardingSet up accountOpen returned solutionUrl
awaiting_approvalApprove connectionOpen returned solutionUrl; Debitura also emails the submitting user an invitation
awaiting_signatureSign agreementOpen returned solutionUrl; name the agreement from solutionType
awaiting_kycComplete identity detailsOpen returned solutionUrl
needs_fixingCorrect and submit invoiceOpen returned solutionUrl. Saving corrections alone creates no case
submittedSubmitted — check case statusShow the invoice's caseStatus and its individual case link; this does not mean active collection
processingProcessingWait and refresh with GET; do not navigate
rejectedNot acceptedShow the invoice's returned reason and issues, when present; no navigation
expiredConnection approval expiredExplain the expiry; no navigation. A fresh request can ask for approval again

If an action has a null URL, keep its label and refresh; never invent a link. An unrecognised status or solution type also needs a fresh read and explicit handling, not a guessed destination.

Details that matter:

  • Signatures. solutionType tells you which agreement: sdca, sdca_update, power_of_attorney or jurisdiction_pricing_appendix.
  • Existing clients. When the matched account isn't linked to you yet, nothing is created until the client approves. Debitura emails one approval invitation to the submitting user, and the same link is your solutionUrl. Until they approve, the response doesn't reveal which account matched. Only approvals expire (normally after 7 days); onboarding, signing and drafts have no deadline from the request.
  • KYC. The case waits while identity details are missing. Submitting them releases it; the collecting partner's review of those details is a separate, later step.
  • submitted is not "collecting". The invoice's caseStatus can still show verification or another early case stage.
  • HTTP codes. 201 means submitted, 202 means action or processing remains, and 422 can mean rejected. Branch on the body's status, not on the HTTP code alone.

Business context: see Case eligibility for which invoices Debitura accepts.

3. Follow progress​

Read the current state by request ID, or find the newest request for a client and invoice:

GET https://testreferral-api.debitura.com/collection-requests/{requestId}
XApiKey: <your-test-partner-key>
GET https://testreferral-api.debitura.com/collection-requests?externalTenantId=example-client-42&creditorReference=EXAMPLE-INV-0042
XApiKey: <your-test-partner-key>

Subscribe to collection_request.updated. It reports request status or invoice-outcome changes and carries the authorised request representation. Some action-only changes, such as moving from SDCA to PoA signing, can appear in GET without a new request-update event. Case events (case.created, case.updated, case.closed) keep working as usual. Verify signatures and deduplicate as for every Debitura webhook.

Plan for these recovery paths:

  • Verify, deduplicate, refresh. Verify the webhook signature, deduplicate by event.id, then GET the affected request using your server-side partner credentials and update its invoice row. Deliveries can repeat; do not apply a payment or create another case because an event arrived twice.
  • GET is the recovery path. Refresh all selected request IDs after the user returns from hosted setup, and provide a refresh/recheck while requests remain pending. Do this even if no webhook arrived. Do not resend an invoice just to read progress: a keyed POST replay can return its original snapshot.
  • Shared steps can settle at different times. After KYC, eligible held cases can progress through reconciliation if immediate processing failed. Keep pending rows visible and read again; completing one form is not an immediate all-invoices guarantee.
  • Webhooks and test data. Request updates reach your active subscriptions in both Test and Production; an invoice's isTest does not decide where they go. A webhook test with collectionRequestId reaches Test subscriptions only, and only in the test environment.

4. Handle failures​

What happensWhat it meansWhat to do
400The request itself is unreadable: malformed JSON, wrong types, missing externalTenantId or creditorReference, more than one invoice, or size limitsFix your request; nothing was stored
needs_fixingThe invoice is readable but needs correctingOpen solutionUrl; the client fixes it on Debitura
rejectedDebitura can't take this invoice, e.g. the country isn't covered or the amount is below the minimumShow the returned reason
Timeout or 5xxA dependency failedRetry with the same Idempotency-Key, or read the request first. Don't tell your user it worked

Sending several invoices​

Keep your bulk button: five selected invoices mean five independent POST /collection-requests calls, each with a one-item invoices array and its own stable idempotency key. Keep the original selection index, invoice reference, request ID, response and any HTTP failure together. Response-arrival order must not decide which action opens. Scope each selection to one client and environment; your server must authorise that client and each request on every read.

What one shared step advances​

For five requests from the same client, completing onboarding and its shared agreements can advance all eligible requests without sending their invoices again. One approval-and-completion for an existing client can likewise continue the requests waiting on that connection. Valid existing agreements can be reused, but another collecting partner or jurisdiction can require an additional PoA or pricing appendix. KYC can be reused where applicable; reconciliation can finish eligible holds after a processing failure.

For example, after shared setup and a refresh, the five rows might be:

Invoice, in selection orderCurrent outcomeWhat remains
INV-001submittedShow its case and caseStatus; ordinary verification can remain
INV-002awaiting_signature / power_of_attorneySign the returned agreement for its collector/jurisdiction
INV-003awaiting_kyc / kycComplete required identity details, then refresh
INV-004needs_fixing / fixCorrect and explicitly submit this draft; saving is insufficient
INV-005rejectedShow its own returned reason; do not retry unchanged data as a new invoice

Offer INV-002's signing action first, retain the other rows, then refresh and choose again. This illustrates independent outcomes, not five invoices inside one response. Completing any one form does not guarantee all five are in active collection.

Choose one setup action​

This is a policy for your button, not a server batch contract:

  1. Read current results and choose an actionable returned URL in this order: onboarding → approval → signing → KYC → fixing. Break ties by original invoice selection order. Signing includes sdca, sdca_update, power_of_attorney and jurisdiction_pricing_appendix.
  2. If several requests return exactly the same setup URL, offer one navigation for that URL. Keep every invoice and its next action visible; equal-looking agreement types do not prove the URLs are shared.
  3. After the user returns, GET all known selected request IDs. Recompute the next action from those reads. On a progress event, refresh the affected request; a shared setup step warrants refreshing its sibling requests too.
  4. Leave processing, null-URL and failed reads pending for recheck. Show rejected/expired outcomes and reasons separately. When all requests are submitted, show per-invoice results and optional individual case links; do not choose an arbitrary case as the batch destination.

The example below selects from rows populated by your server. current means the latest successful GET, not a replayed POST receipt. Set refreshError and withhold that row's old navigation if GET fails; keep its last result visible. Only clear that error after a successful read. The server keeps API credentials and request-to-client ownership checks; neither belongs in browser code.

Select from current per-invoice results
const actionOrder = [
['awaiting_onboarding', ['onboarding']],
['awaiting_approval', ['approval']],
['awaiting_signature', ['sdca', 'sdca_update',
'power_of_attorney', 'jurisdiction_pricing_appendix']],
['awaiting_kyc', ['kyc']],
['needs_fixing', ['fix']],
];

function nextSetupAction(rows) {
const candidates = [];
for (const row of rows) { // rows stay in original selection order
if (row.refreshError || !row.current) continue;
const {status, solutionType, solutionUrl} = row.current;
const priority = actionOrder.findIndex(([state, types]) =>
state === status && types.includes(solutionType));
if (priority < 0 || typeof solutionUrl !== 'string') continue;
try {
const url = new URL(solutionUrl);
if (url.protocol !== 'https:' || url.username || url.password) continue;
} catch { continue; }
candidates.push({row, priority, url: solutionUrl});
}
// Stable selection order breaks ties; network completion time is irrelevant.
candidates.sort((a, b) => a.priority - b.priority);
const next = candidates[0];
if (!next) return null; // keep showing each row; wait/refresh as needed
return {
url: next.url,
requestIds: candidates.filter(c => c.url === next.url)
.map(c => c.row.current.id),
};
}

// Re-render after every refresh. No navigation happens until the user clicks.
const next = nextSetupAction(rows);
continueLink.hidden = !next;
continueLink.removeAttribute('href'); // remove a previously displayed action
if (next) continueLink.href = next.url; // use <a>, same tab, no window.open

Populate rows in selection order before sending. Each call updates only its own row; Promise.allSettled can retain successful responses alongside failed calls. Treat a structured rejected request as a result even if its HTTP status is 422. An unstructured HTTP failure stays attached to that invoice; it must not erase neighbouring request IDs. If the submission outcome is uncertain, look up the request by client and invoice reference or retry the original body/key within its idempotency window. Never use a fresh key just to recover progress.

Clear the displayed Continue link while refreshing so it cannot open a stale action. Render the per-invoice table even when nextSetupAction returns null: null can mean waiting, a failed read or no remaining setup, rather than “all succeeded”. Keep each other returned action available on its own row.

What the client receives​

There is no immediate “collection started” email just because your API request was received or became submitted. When the collecting partner starts collection, the existing case-start email identifies that collector and links to the case and applicable agreements. It includes the collection fee recorded for that case; this is separate from your referral revenue share. Accepted flat, hourly and hybrid quotes retain their recorded amounts, estimates, process costs and fee details rather than being described as a generic percentage.

Several cases can arrive in a grouped email per client and collecting partner, with each case's own fee. The normal grouped path runs hourly with a four-hour quiet period; it is not an immediate receipt or a guaranteed delivery deadline. Existing alternate case-start confirmation paths keep their own triggers. Case email preferences and suppression can prevent delivery. These notifications apply to Starter and Full Integration; your platform still presents the current next-action links and tracks request/case progress.

The communication responsibilities also cover welcome messages, signing reminders and Starter's existing-client approval invitation. For commercial fee context, see How success fees are calculated.

5. Add Full endpoints when you need them​

Starter and Full share the same client relationship. With the same externalTenantId, you can mint a bearer token and use Customer API operations for this client at any time, with no new onboarding. Typical next steps:

A new Starter request recognises an existing case for the same client, invoice reference and test/live classification, whichever route created it. It returns that case and leaves the case's origin, attribution and rate unchanged. Starter doesn't change how the Full endpoints respond.

Try it without code​

The Ledgerline demo shows the button in a fictional accounting product. Turn on Developer view to see example requests and responses for each step. The demo sends no API traffic, so it doesn't prove your own integration works; verify that against test before production.

What's next​