Creating an Environment Variable
Function
Publishing an API in different environments may involve various environment variables, such as API service deployment address and request version.
Define environment variables when creating an API. When the API is called, the environment variables will be replaced with the variable values to distinguish environments.
Environment variables are defined for an API group and apply to all APIs in the group.
- Environment variable names must be unique for an API group in the same environment.
- Environment variable names are case-sensitive. For example, ABC and abc are two different variables.
- APIs that use environment variables cannot be debugged.
- You must enclose an environment variable in number signs (#) so that it can be replaced with the actual value of the environment in which the API is published. For example, if the URL of an API is https://#address#:8080 and the value of variable address is 192.168.1.5 in the RELEASE environment, the real URL of the API is https://192.168.1.5:8080 after publishing.
URI
The following table lists the HTTP/HTTPS request method and URI of the API.
Request Method |
URI |
---|---|
POST |
/v1.0/apigw/env-variables |
Request
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
env_id |
Yes |
String |
Environment ID |
group_id |
Yes |
String |
API group ID |
variable_name |
Yes |
String |
Variable name A variable name consists of 3–32 characters, starting with a letter. Only letters, digits, hyphens (-), and underscores (_) are allowed. 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 publishing. |
variable_value |
Yes |
String |
Variable value A variable value consists of 1–255 characters. Only letters, digits, and special characters (_-/.:) are allowed. |
Example request:
{ "env_id": "cca3616a-f368-4b32-9064-b2a631cb3eeb", "group_id": "73c58022-f20d-495a-a188-85d718647f09", "variable_name": "address", "variable_value": "192.168.1.5" }
Response
Parameter |
Type |
Description |
---|---|---|
id |
String |
Environment variable ID |
env_id |
String |
Environment ID |
group_id |
String |
API group ID |
variable_name |
String |
Variable name |
variable_value |
String |
Variable value |
Example response:
{ "id": "104185e5-3e8f-4c63-a7e5-ef4117bf870c", "env_id": "cca3616a-f368-4b32-9064-b2a631cb3eeb", "group_id": "73c58022-f20d-495a-a188-85d718647f09", "variable_name": "address", "variable_value": "192.168.1.5" }
Status Codes
Status Code |
Description |
---|---|
201 |
Created |
400 |
Bad Request |
401 |
Unauthorized |
403 |
Forbidden |
404 |
Not Found |
500 |
Server Internal Error |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot