Call Total API from Total.js
Configure the token and call any service with API('TAPI') or TotalAPI() in a Total.js application.
On this page
Total.js applications have a built-in client for Total API. You only add your token to the configuration.
Configure the token
Add the totalapi key to the config file of your application:
totalapi : YOUR_TOKENCall a service
API('TAPI', service, data) calls a service. The first argument is always TAPI, the second one is the name of the service and the third one its data.
With await:
var response = await API('TAPI', 'weather', 'Bratislava').promise();With a callback:
API('TAPI', 'weather', 'Bratislava').callback(function(err, response) {
if (err)
console.log('Error:', err);
else
console.log(response.temperature);
});TotalAPI(service, data, callback) does the same in a shorter form:
TotalAPI('weather', 'Bratislava', function(err, response) {
console.log(err, response);
});Data as text
When the data is text, a number or a boolean instead of an object, the client sends it as { value: ... }. These two calls are the same:
API('TAPI', 'weather', 'Bratislava');
API('TAPI', 'weather', { value: 'Bratislava' });Errors
When Total API refuses a request, the error is its message, for example Invalid token when the token is missing or wrong.
Send the emails of the app through Total API
With $tapimail set to true, the emails that the application sends with MAIL() go through the mail service instead of an SMTP server:
totalapi : YOUR_TOKEN
$tapimail : trueSend the audit logs to Total API
With $tapilogger set to true, the audit logs of the application (AUDIT()) go to the logger service:
totalapi : YOUR_TOKEN
$tapilogger : true