> For the complete documentation index, see [llms.txt](https://developers.stub.africa/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.stub.africa/sdk-documentation/reference.md).

# Reference

### Initialisation

#### `stub.init(options)`

Initialises the SDK. Call this before using any other method.

```javascript
window.stub.init({
  appId: '<appid>',          // required
  businessId: '<businessid>',// required
  token: '<token>',          // required
  test: false,
  month: 1,
  year: 2025,
  colours: ['#00A86B', '#6477E3'],
  font: "'Public Sans', Arial, sans-serif",
  emptyImage: {
    light: 'https://your.site/light.png',
    dark: 'https://your.site/dark.png'
  },
  renderImmediately: false
});
```

If `renderImmediately` is `true` you don't need to call `stub.render()` to render the widgets. But make sure that the DOM is ready when you call `stub.init()`, otherwise the widgets will not render.

### Core methods

* **`stub.render()`** – Mount the widgets into the DOM.
* **`stub.refresh()`** – Reload the data displayed in the widgets.
* **`stub.set(options)`** – Update the month, year or authentication token.
* **`stub.getDetails()`** – Retrieve details about the current business.
* **`stub.hasBankAccounts()`** – Returns `true` if the business has any bank accounts on file.
* **`stub.hasLinkedBankAccounts()`** – Returns `true` if any bank account is linked and can sync.
* **`stub.isInitialised()`** – Indicates whether the SDK has been initialised and loaded.

```javascript
// set() options

stub.set({
    month: 3,
    year: 2055,
    token: '<TOKEN>',
})
```

### Bank actions

* **`stub.linkBankAccounts()`** – Start the bank linking flow in the current window.
* **`stub.manageBankAccounts()`** – Open the manage accounts screen in a new tab.

### Events

Use `stub.addEventListener(fn)` to listen for events and `stub.removeEventListener(fn)` to remove a listener. The callback receives an object with `event`, `srcWidget`, `srcElement` and `timeStamp` fields.

Events include:

* `init`, `loading`, `loaded`
* `uncategorised-income-list-opened`, `uncategorised-income-list-closed`, `income-list-opened`, `income-list-closed`, `income-info-opened`, `income-info-closed`, `income-added`, `income-edited`, `income-deleted`, `income-categorised`, `sales-report-opened`
* `uncategorised-expenses-list-opened`, `uncategorised-expenses-list-closed`, `expenses-list-opened`, `expenses-list-closed`, `expenses-info-opened`, `expenses-info-closed`, `expense-added`, `expense-edited`, `expense-deleted`, `expense-categorised`, `expense-report-opened`
* `profit-info-opened`, `profit-info-closed`, `profit-and-loss-report-opened`
* `cashflow-info-opened`, `cashflow-info-closed`, `cashflow-report-opened`
* `balance-sheet-report-opened`, `trial-balance-opened`
* `bank-link-started`, `bank-sync-started`, `bank-sync-completed`, `bank-edit-started`, `bank-refresh-started`, `manage-bank-accounts-started`

### TypeScript usage

You can use the SDK from TypeScript by declaring the `stub` object on the `Window` interface and downloading the type definition from `https://embed.stub.africa/stub-widgets.d.ts`.

```typescript
declare global {
  interface Window { stub: stub }
}

window.stub.init(options);
window.stub.render();
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers.stub.africa/sdk-documentation/reference.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
