Using a variable in a workflow

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 most straightforward way to achieve this is to use the APImetrics API for Environment Variables as part of a Workflow.

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.

Step 1 - Use Conditions to Capture the Values

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.


Step 2 - Set an Environment Variable to the Captured Value

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

Step 3 - Use the Environment Variable in your API calls

You can then use the variable in your other API calls. See our guide to global variables.