Navigation

Connect SDK

The Connect SDK opens a secure iframe for users to link their biller accounts. Credentials never touch your code.

Installation

npm install @billerapi/connect-sdk
yarn add @billerapi/connect-sdk
pnpm add @billerapi/connect-sdk

Quick Start

Initialize the SDK with your client ID, create a connect handler with a link token, and call open().

import { BillButler } from '@billerapi/connect-sdk';

// 1. Initialize with your client ID
const billbutler = new BillButler({
  clientId: 'your_client_id',
  environment: 'sandbox',
});

// 2. Create a handler with the link token from your server
const handler = billbutler.create({
  linkToken: 'lt_xxx', // from POST /link/token/create
  onSuccess: (publicToken, metadata) => {
    // Send publicToken to your server to exchange for an access token
    console.log('Linked!', metadata.accountId, metadata.institutionName);
    fetch('/api/exchange-token', {
      method: 'POST',
      body: JSON.stringify({ publicToken }),
    });
  },
  onExit: (error) => {
    if (error) {
      console.error('Connect error:', error.code, error.message);
    } else {
      console.log('User closed the modal');
    }
  },
  onEvent: (eventName, metadata) => {
    console.log('Connect event:', eventName, metadata);
  },
});

// 3. Open the Connect modal
handler.open();

Server-side setup

Before opening the SDK, your server must create a link token via POST /link/token/create with your client credentials. See the Getting Started guide.

Configuration

Pass a BillButlerConfig object to the constructor.

PropertyTypeRequiredDescription
clientIdstringYesYour BillerAPI client ID
environment'development' | 'sandbox' | 'production'NoTarget environment (auto-detected if omitted)
baseUrlstringNoCustom base URL (used to derive connect URL)
apiUrlstringNoCustom API URL (overrides environment default)
connectUrlstringNoExplicit connect app URL (overrides baseUrl derivation)

Connect Options

Pass ConnectOptions to billbutler.create().

PropertyTypeRequiredDescription
linkTokenstringYesToken from POST /link/token/create
onSuccess(publicToken, metadata) => voidYesCalled when user completes linking
onExit(error?) => voidNoCalled when user exits or an error occurs
onLoad() => voidNoCalled when the modal iframe is loaded
onEvent(eventName, metadata) => voidNoCalled for flow events (analytics)
theme'light' | 'dark'NoModal theme (defaults to light)

Handler Methods

billbutler.create() returns a ConnectHandler.

open(): Promise<void>

Opens the Connect modal iframe. No-op if already open.

close(): void

Closes the modal and cleans up. No-op if already closed.

isOpen(): boolean

Returns whether the modal is currently open.

Callback Data Types

ConnectMetadata (onSuccess)

FieldTypeDescription
accountIdstringUnique ID for the connected account
accountNamestring?Account display name
accountTypestring?e.g., 'checking', 'savings'
institutionNamestring?Biller/institution name
selected_accountsstring[]?IDs of selected accounts
consents{ accounts, bills }Granted consent scopes

ConnectError (onExit)

FieldTypeDescription
codestringError code (e.g., MODAL_OPEN_ERROR)
messagestringHuman-readable error message
detailsany?Additional error context

Integration Flow

The complete flow from creating a link token to retrieving bills.

1

Server: Create link token

POST /link/token/create with client credentials. Returns a link_token.

2

Client: Initialize SDK

new BillButler({ clientId, environment }) then billbutler.create({ linkToken, onSuccess, onExit })

3

Client: Open Connect modal

handler.open() — opens a secure iframe hosted by BillerAPI

4

User: Complete linking flow

Select biller → enter credentials → complete MFA → select accounts

5

Client: Receive public token

onSuccess(publicToken, metadata) fires. Send publicToken to your server.

6

Server: Exchange for access token

POST /link/token/exchange with public_token. Returns access_token, biller_id, link_id.

7

Server: Fetch bills

GET /bills/get with Authorization: Bearer <access_token>

Theming

The Connect modal supports light and dark themes via the theme option.

JavaScript
const handler = billbutler.create({
  linkToken: 'lt_xxx',
  theme: 'dark', // 'light' (default) or 'dark'
  onSuccess: (publicToken, metadata) => { /* ... */ },
});

Cleanup

Call destroy() when you're done with the SDK instance to close the modal and clean up event listeners.

JavaScript
// Clean up when component unmounts or SDK is no longer needed
billbutler.destroy();

Tip

In React, call billbutler.destroy() in a useEffect cleanup function to avoid memory leaks.

Related