# 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: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
