Environment Variables
This feature is useful for getting and setting environment variables through scripting.
Get Environment variables
let apiKey = tc.getVar("API_KEY");
let token = tc.getVar("token");
Set Environment variables
// To save to active environment
tc.setVar(varName, value);
// To save to local environment
tc.setVar(varName, value, "local");
// To save to global environment
tc.setVar(varName, value, "global");
// To set collection or request level variables
tc.setVar(varName, value, "request");
Collection and Request Variables
- You can set
collection
andrequest
specific env variables in scripting usingrequest
scope. - These variable values are available during the execution of the request only. The data is not saved to a file.
- To use - open collection settings or request view -> then select
Pre Run
Tab and use theScripting
tab
tc.setVar("name", "Thunder Client", "request");
tc.setVar("baseUrl", "http://localhost:8744", "request");