Link sessions and user actions
Linking a customer's bank account, and every kind of step a provider can ask your user to take.
A link session (lnk_…) is one attempt to connect a customer's bank account through a provider. It ends with the linked accounts, or with a reason it didn't work.
const session = await unirail.linkSessions.create(
{
customer: customer.id,
country: "GB",
institution: "ins_8XkQ2mPz4r", // optional: let the policy pick a provider for this bank
channel: "web",
returnUri: "https://example.com/bank-link/done",
},
{ context: { idempotencyKey: `link:${attempt.id}` } },
);Lifecycle
requires_action. The session has anextActionfor your user, such as a redirect to their bank. Show anydisclosuresfirst: some providers require you to display their terms before the user continues.- The user acts and comes back. They land on your
returnUri, or the provider SDK hands you a result. - Advance. Call
linkSessions.advancewith what you received:returnParams(the query parameters on your return URI, verbatim) orsdkResult(for example Plaid's public token). completedwithaccounts(the newacct_…ids), orfailed,cancelledorexpiredwith afailureexplanation.
Unirail also emits link_session.completed and link_session.failed, so a session the user finished on another device still reaches you.
User actions
nextAction (on link sessions and payment intents) is one of these:
kind | What your app does |
|---|---|
redirect | Send the user to url. They come back to your returnUri. |
sdk | Open the provider's SDK named in provider (for example Plaid Link) with token, then advance with sdkResult. |
decoupled | The user approves somewhere else, usually their banking app. Show message and wait for the event. |
qr | Render payload as a QR code for the user to scan with their banking app. |
app-handoff | Open url, which hands off to another app on the device. |
funding-instructions | Show the payto address, reference and amount the user should pay. |
form | Ask the user for the listed fields. |
add-payee-in-bank | The user has to add the payee in their own bank first. Show instructions. |
none | Nothing to do; wait for the next event. |
Actions that expire carry expiresAt. Set channel: "native" when your user is in a mobile app rather than a browser.