Basic Use of the JavaScript Library

For basic functionality of the JavaScript library for the real-time state API, only the following two functions are necessary.

A complete list of table names and their data structures can be found in System State Model of the Real-Time API.


Make one call to the BomgarState() function to provide the API with connection and authentication information and with the tables you wish to receive updates for.


  • options ( Object )
    • bearerToken (String)) - Required
    • host ( String ) - Required.
    • port ( Integer ) - Optional. Defaults to 443.
    • company ( String ) - Required.
    • tables ( String | String[] ) - Optional. Can be an array of table names or the string all. Defaults to all.

For more information on how to generate the bearerToken, please see Authenticate to the Remote Support API.


  • ( Observable<Object> ): An observable sequence of all model changes as objects, parsed from the original JSON.

You must call .subscribe() on this returned observable object to actually initiate the connection to the server. Calling BomgarState() merely defines the necessary connection and authentication parameters.


//Provide the API with the connection and authentication parameters
var allChangesObservable = BomgarState({
    host: '',
    port: 443, // Optional
    company: 'companyname',
    bearerToken: 'bearerToken',
    tables: ['customer_client', 'representative'] // Or 'all'

// This triggers the actual connection and authentication:
var subscription = allChangesObservable.subscribe();

.subscribe([onChange], [onError], [onCompleted])

Calling the subscribe() method on the observable returned by BomgarState() initiates the connection and authentication with your B Series Appliance over a WebSocket. If successful, the API then sends your table list to the server. subscribe() also allows you to optionally register callback functions for model changes, errors, and connection closures.


  • onChange ( Function ): Function that the API invokes for every model change received from the server. The function should accept one argument: an object describing the model changes. The structure of this object is described in the Model Updates section of Protocol of the Real-Time State API.
  • onError ( Function ): Function that the API invokes 0 or 1 times if a fatal error occurs during connection, authentication, or table registration.
  • onCompleted ( Function ): Function that the API invokes once when the connection closes normally.


  • ( Object ): Returns an object representing the subscription. If you need to programmatically close the connection, call .dispose() on this object.


// This causes the connection and authentication to occur.
var subscription = allChangesObservable.subscribe(
    // This onChange function is invoked every time any model change - insertion, update deletion, or truncation - occurs in any table you have registered for
    function onChange(changeObject) {
        switch (changeObject.type) {
            case 'model_update':
                // Test for 'insert', 'update', or 'delete' properties on changeObject, then find the table name and local data accordingly
            case 'truncate_model':
                // Delete all local data in all tables
    function onError(error){
        console.error('An error occurred: %s', error);
    function onCompleted() {
        console.log('Connection closed. No more messages will be received.');

// Later, if you need to close the connection manually:
// subscription.dispose();