Class Api

The TVS.Api class provides a high-level application programming interface for communicating and interacting with the TrustID Cloud.

A TVS.Api object instance will retain any session information over its lifetime after a successful login has been carried out or a login has been performed. This means that subsequent operations can be performed without having to deal with session information directly.

var api = new TVS.Api();
api.login('username', 'password').then(function() {
    // subsequent calls to api object...
});

Error Responses

If an error occurs, the original JSON response from the TrustID Cloud is passed to the error handler. For example:

var api = new TVS.Api();
api.login('admin', 'password').then(function(loginResponse) {
    // ...
}, function(json) {
   console.log('error:', json.Message);
});

All error responses contain the following information:

{
    Success: false,          // success or failure?
    SessionExpired: false,   // true, if session has expired
    AccessDenied: false,     // true, if access has been denied
    Locked: false,           // true, if resource was locked
    Message: "...",          // Error message (text)
}

When an error occurs Success is always false and Message contains the full text description of the error message. Other flags might give more details of why the operation went wrong. For example, SessionExpired is set to true if access was denied because the session has timed out.

See Error Response for more information on response objects in general.

See also

API Object for examples of how to use the high-level application programming interface for the TrustID Cloud.

Promises for more information on how to work with promises. Most API operations are executed asynchronously and return a promise object that represents an operation that might not yet be completed.

Properties

Api.User

Instance of Class User that represents information about the currently authenticated user for the current session, or null if no session has been established yet.

Api.Branch

Instance of Class Branch that represents information about the branch the current user is associated with, or null if the current user does not belong to any branch, or no session has been established yet.

Api.Organisation

Instance of Class Organisation that represents information about the organisation the current user is associated with, or null if the current user does not belong to any organisation, or no session has been established yet.

Api.RemainingCredits

Instance of Class RemainingCredits that represents information about the current user’s remaining credits. Remaining credit information is automatically obtained during login, or when manually querying for remaining credit information.

Api.Config

Instance of Class Config that represents a number of configuration options for the current session and describes capabilities for the current user and the connected TrustID Cloud.

Methods

These are described in detail in the following sections: