---
title: Use environments and variables
project: TotalAPI
version: Latest
section: guides
language: en
license: 
url: https://totaljs.es/docs/totalapi/latest/guides/variables/
updated: 2026-12-02T15:40:16.062Z
---

# Use environments and variables

> A variable is a value with a name that you write once and use in many requests. An environment is a set of them, for example one for your computer and another for production.

## Use a variable

Write its name between double braces: `{{base}}/api/users`. It works in the address, the query, the headers, the auth, the body and the form of a Total.js action.

A name has letters without accents, digits, `_`, `-` and `.`.

## Change the variables

1. Press the button next to **Environment**, or ⌘E on the Mac and Ctrl+E on Windows and Linux.
2. Choose the environment on the left.
3. Press **+ Add a variable**, and write its name and its value.
4. Press **Done**.

## Have more than one environment

Press **+ New environment** and write its name. If the one you were in has the variable `base`, the new one has it too, empty, for its own address. Add the other variables with the same names.

Then choose the environment in the list above the requests. The same requests go now to the other place, with the other values. Each environment also [keeps its own cookies](/totalapi/latest/guides/sign-in/).

> **Remove this environment** takes it out with its variables. It asks first, and there is no way back.

## Keep a value secret

Mark **Secret** for tokens and passwords, before or after you write the value. It is kept in the secure store of your system, and the file of the collection has only the name.

- A value that was in the file before you marked it is no longer there, but it can still be in the history of Git, or in a copy.
- If you change the name of a secret variable, its value goes with it.
- If you take **Secret** off, the field is empty: the value does not go to the file unless you write it.
- Secret values stay on your computer. Whoever opens the collection on another one writes their own.

## Values made at each send

These need no environment. In one request, the same name has the same value everywhere.

| Variable | What it is |
| --- | --- |
| `{{$uid}}` | An identifier like those that `UID()` makes in Total.js |
| `{{$guid}}` | A GUID |
| `{{$now}}` | The date and time, in ISO format |
| `{{$timestamp}}` | The milliseconds since 1970 |
| `{{$random}}` | A number from 0 to 999999 |
| `{{$email}}` | An address for tests, at `example.com` |

## A variable that does not exist

If the address, a header, the body or the auth uses a name that the environment does not have, the request is not sent and TotalAPI says which name it is. In the query, in a form and in the data of an action it does not notice: the request goes without the value.
