---
title: Call Total API from Total.js
project: Total API
version: 2026
section: guides
language: en
license: 
url: https://totaljs.es/docs/total-api/2026/guides/call-from-totaljs/
updated: 2026-11-19T06:09:14.885Z
---

# Call Total API from Total.js

> Configure the token and call any service with API('TAPI') or TotalAPI() in a Total.js application.

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:

```text
totalapi : YOUR_TOKEN
```

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

```js
var response = await API('TAPI', 'weather', 'Bratislava').promise();
```

With a callback:

```js
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:

```js
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:

```js
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](../../reference/messages/#mail) service instead of an SMTP server:

```text
totalapi  : YOUR_TOKEN
$tapimail : true
```

## Send the audit logs to Total API

With `$tapilogger` set to `true`, the audit logs of the application (`AUDIT()`) go to the [logger](../../reference/messages/#logger) service:

```text
totalapi    : YOUR_TOKEN
$tapilogger : true
```
