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 using therequestscope. - These variable values are available only during request execution. The data is not saved to a file.
- To use this, open collection settings or the request view, then select the
Pre Runtab and use theScriptingtab.
tc.setVar("name", "Thunder Client", "request");
tc.setVar("baseUrl", "http://localhost:8744", "request");Last updated on