Environment Variables

Environment variables are variables with unique values within a specific environment. They are used as extra configurations for each environment, allowing the customization of requests to easily switch between different contexts. Creating them is not mandatory, but their use facilitates the process of designing and managing APIs.

The API Manager allows creating environment variables to be used in various parts of our platform:

List of interceptors that allow the use of environment variables:

Traffic

Security

Mediation

Transformation

Time allowed
Spike arrest
Rate limit
Payload size
Cache write
Billing hits

XML Threat protection
JSON Threat protection
Time Token
IP Filtering
Encrypt
Data Obfuscation
CSRF Token

Service mashup
Service callout
Internall API Call

Query param
Header
Destination

Imagine several APIs deployed to an environment share the same target destination and, at some point, that destination changes. Without environment variables, it would be necessary to change the target destination in each API. However, if the destination had been set as an environment variable, just change the value of that variable in the specific environment, and all APIs will be automatically updated.

Registering environment variables

To register environment variables, you must create a variables map or import an existing one from another environment.

To add a map:

  1. Click the ADD MAP button;

  2. In the screen that opens, define the name for the map.

add map

Now you can create environment variables as key-value pairs, both of type string.

new variables

The Type field allows you to change the variable type to one of the options below:

  • DEFAULT: the default type for all variables. Doesn’t change their behavior.

  • SECURED: encrypted value, decrypted only by a Connector’s flow, adding more security when storing its credentials since the value isn’t retrievable in any other way.

You can also add a certificate corresponding to the communication between the gateway and the backend. When the environment variable is used, it will be applied:

  1. Click the icon certificate icon;

  2. Select the registered certificate on the Certificates screen;

To import a map from another environment:

  1. Click the IMPORT MAP button;

  2. When you start typing the environment name, the system will load the necessary information;

  3. After selecting the map, click IMPORT MAP.

import map

The environment variables will be loaded. You will be able to:

  • view them by clicking the icon to extend the tab next to the map’s name;

  • edit them by clicking the icon edit icon;

  • delete them by clicking the icon delete icon;

  • add new variables to a map by clicking the icon more info icon and then the + button.

On this same tab, you can edit the map’s name and description, or delete it.

Managing environment variables

When you create variables in an environment, they are associated with the environment as a whole, not with a specific API. Therefore, it is important to follow good management and organization practices. We recommend using a clear and consistent naming pattern for all variables. This makes it easier to identify and use them correctly.

Usage example

Consider two environment variables: one named destination, with a valid address, and one named rateLimit, with value 2.

add variable

The environment variable $destination can be used as an API endpoint. When a request is made, the gateway will direct the call to the configured address. To set this up, just reference the environment variable as the API’s Target Destination, as shown in the image below:

config destination variable

The environment variable $rateLimit can be used in the interceptor of the same name to set the call limit, replacing the configured value (in this case, 2).

rate limit
  • Access Target Destination in the Flows section when editing or creating an API. In the diagram representing the request and response flows, click the icon backend button.

  • All environment variables must be preceded by the $ symbol when referenced in APIs or interceptors.

  • The gateway reuses connections by default. For more information, see our FAQ.

Thanks for your feedback!
EDIT

Share your suggestions with us!
Click here and then [+ Submit idea]