Help Center/ API Gateway/ User Guide/ Opening APIs/ (Optional) Configuring the Environment and Environment Variables
Updated on 2025-01-10 GMT+08:00

(Optional) Configuring the Environment and Environment Variables

An environment refers to the usage scope of an API. An API can be called only after it is published in an environment. APIs can be published in different customized environments, such as the development environment and test environment. RELEASE is the default and formal publishing environment of the system.

Environment variables are specific to environments. If environment variables are defined in backend information of an API, you need to add the variables to the environment. You can create variables in different environments to call different backend services using the same API.

Example: an API whose variable Path is defined in the backend request path. If variable Path is configured for environment 1 and is assigned value /Stage/test, use the backend request path /Stage/test to call this API in this environment. If variable Path is configured for environment 2 and is assigned value /Stage/AA, use the backend request path /Stage/AA to call this API in this environment.

Figure 1 Use of environment variables

Creating an Environment

  1. Go to the APIG console.
  2. Select a dedicated gateway at the top of the navigation pane.
  1. In the navigation pane, choose API Management > API Policies.
  2. Click the Environments tab.
  1. Click Create Environment and configure basic information based on the following table.

    Table 1 Environment information

    Parameter

    Description

    Name

    Environment name. Start with a letter and use only letters, digits, and underscores (_). 3 to 64 characters.

    Description

    Environment description, which contains 1 to 255 characters.

  2. Click OK.

    After the environment is created, it is displayed in the environment list.

    When a user needs to call an open API, the API in the RELEASE environment is called by default. To access an API in another environment, add the X-Stage parameter to the header of the API request, where the parameter is the environment name. For example, to access an API in the Develop environment, add X-Stage: Develop to the header of the API request.

Creating an Environment Variable

  1. Go to the APIG console.
  1. Select a dedicated gateway at the top of the navigation pane.
  1. Choose API Management > API Groups.
  2. Click a group name to go to the Group Information page.
  3. In the Environment Variables area, select an environment. If no environment is available, click Create Environment to create one.
  4. Click Add Environment Variable and enter the variable information based on the following table.

    • Environment variable names and values will be displayed in plain text in API requests. Do not include sensitive information in the variable names and values.
    • APIG does not support API debugging with environment variables.
    Table 2 Adding an environment variable

    Parameter

    Description

    Name

    Variable name. Ensure that the name is the same as the name of the variable defined for the API. The variable name is equivalent to #Name# in an API definition. Characters between the number signs are case-sensitive. The variable name will be replaced with the variable value after API publication.

    The variable name contains 3 to 32 characters. It can contain letters, digits, underscores (_), and hyphens (-), and must start with a letter.

    Value

    Use letters, digits, underscores (_), hyphens (-), slashes (/), periods (.), and colons (:). (Max. 255 characters)

  5. Click OK.

Follow-Up Operations

You can publish an API in the environment for calling.