If you need to store a variable for use globally in other tests or outside of a workflow, APImetrics have provided a simple API to support this.
The process is simple:
- Step 1 - use conditions to capture the value
- Step 2 - set an environment variable to the captured value
- Step 3 - use the environment variable in your API calls
This could be used to set OAuth tokens for use in other calls where you have a workflow running every few hours to set the token or refresh token that is then used in a number of calls.
On the Conditions tab of the API Call edit page, you can check for values in your JSON or XML and save them to a variable.
This example shows two checks being made on the Response Body. The first test looks for the value and sets a variable to either REFRESH for the Refresh Token or ACCESS for the Access Token.
Next create a new API call to set the variable. This is basically an API call to our Environment Variable API.
This example sets the variable 'refresh_token' to the value set in the POST from the previous test.
You will need to add your APImetrics API key to the API call
You can then use the variable in your other API calls. See our guide to global variables.
Updated almost 2 years ago