Skip to content

Events

Reference for the Bkper event system — how to subscribe to events in bkper.yaml, the full Event object structure with book/user/agent/data fields, the complete current event type list, and how to use previousAttributes for diffs.

Bkper fires events whenever something changes in a Book — transactions created, accounts updated, collaborators added, and more. These events are the foundation for building automations with event handlers.

Subscribing to events

You declare which events your app receives in the events list of your bkper.yaml:

events:
- TRANSACTION_CHECKED
- TRANSACTION_POSTED
- ACCOUNT_CREATED

When one of these events occurs in a Book where your app is installed, Bkper sends an HTTP POST to your configured webhook URL with the event payload.

The Event object

When an event handler receives an event, the payload has the following structure:

{
/** The id of the Book associated to the Event */
bookId?: string;
/** The Book object associated with the Event */
book?: {
agentId?: string;
collection?: Collection;
createdAt?: string;
datePattern?: string;
decimalSeparator?: "DOT" | "COMMA";
fractionDigits?: number;
id?: string;
lastUpdateMs?: string;
lockDate?: string;
name?: string;
ownerName?: string;
pageSize?: number;
period?: "MONTH" | "QUARTER" | "YEAR";
periodStartMonth?: "JANUARY" | "FEBRUARY" | "MARCH" | "APRIL"
| "MAY" | "JUNE" | "JULY" | "AUGUST" | "SEPTEMBER"
| "OCTOBER" | "NOVEMBER" | "DECEMBER";
permission?: "OWNER" | "EDITOR" | "POSTER" | "RECORDER"
| "VIEWER" | "NONE";
properties?: { [name: string]: string };
timeZone?: string;
timeZoneOffset?: number;
};
/** The user in charge of the Event */
user?: {
avatarUrl?: string;
name?: string;
username?: string;
};
/** The Event agent, such as the App, Bot or Bank institution */
agent?: {
id?: string;
logo?: string;
name?: string;
};
/** The creation timestamp, in milliseconds */
createdAt?: string;
/** The event data */
data?: {
/**
* The object payload. Depends on the event type.
* For example, ACCOUNT_CREATED receives an Account payload.
*/
object?: any;
/** The object previous attributes when updated */
previousAttributes?: { [name: string]: string };
};
/** The unique id that identifies the Event */
id?: string;
/** The resource associated to the Event */
resource?: string;
/** The type of the Event */
type?: EventType;
}

The event payload is the same structure exposed by the REST API. If you use TypeScript, add the @bkper/bkper-api-types package to your project for full type definitions:

app.post('/', async c => {
const event: bkper.Event = await c.req.json();
// handle event...
});

Event types

The list below is the complete current set of event types for API v5.

EventDescription
FILE_CREATEDA file was attached to the book.
FILE_UPDATEDAn attached file was updated.
TRANSACTION_CREATEDA draft transaction was created.
TRANSACTION_UPDATEDA transaction was updated.
TRANSACTION_DELETEDA transaction was deleted.
TRANSACTION_POSTEDA draft transaction was posted and now affects balances.
TRANSACTION_CHECKEDA posted transaction was checked (reviewed and locked).
TRANSACTION_UNCHECKEDA checked transaction was unchecked and becomes editable again.
TRANSACTION_RESTOREDA deleted transaction was restored.
ACCOUNT_CREATEDAn account was created.
ACCOUNT_UPDATEDAn account was updated.
ACCOUNT_DELETEDAn account was deleted.
QUERY_CREATEDA saved query was created.
QUERY_UPDATEDA saved query was updated.
QUERY_DELETEDA saved query was deleted.
GROUP_CREATEDA group was created.
GROUP_UPDATEDA group was updated.
GROUP_DELETEDA group was deleted.
COMMENT_CREATEDA comment was added.
COMMENT_DELETEDA comment was deleted.
COLLABORATOR_ADDEDA collaborator was added to the book.
COLLABORATOR_UPDATEDA collaborator’s permissions were updated.
COLLABORATOR_REMOVEDA collaborator was removed from the book.
INTEGRATION_CREATEDAn integration was created in the book.
INTEGRATION_UPDATEDAn integration was updated.
INTEGRATION_DELETEDAn integration was deleted.
BOOK_CREATEDA book was created.
BOOK_AUDITEDA balances audit completed for the book.
BOOK_UPDATEDBook settings were updated.
BOOK_DELETEDThe book was deleted.

Event data

The data.object field contains the resource that was affected. Its shape depends on the event type:

  • Transaction events: The full Transaction object
  • Account events: The full Account object
  • Group events: The full Group object
  • Comment events: The Comment object
  • Collaborator events: The Collaborator object

For update events, data.previousAttributes contains the fields that changed and their previous values — useful for computing diffs or reacting only to specific field changes.

The agent field

Every event includes information about which agent triggered it. This is important for preventing loops — if your event handler creates a transaction, that will fire a new event, and you need to check event.agent.id to avoid reacting to your own actions.