Variables in API Testing

Use Variables in API Test Cases to Securely Manage Sensitive Data

Variables help you keep your API tests secure and flexible by letting you store values like tokens outside your test case. Instead of hard-coding confidential details, reference variables to make your tests safer and easier to maintain.

Open your API test case where you need to pass an access token in the authorization header.

Image

Click the variables option.

Image

Add a key (for example, `token`) and paste your actual token value. Click Create to save it.

In your test case, set the Authorization header as `Bearer ${token}` — use the variable name inside `${}`.

Image

(Optional) Define a variable to store data from the test result, such as naming it `result`. Set your expected response, for instance, status code `200`.

Image

Click Create to save your test case changes.

Image

Click Run to execute the test case.

Image

Review the Run history to verify the test used the variable and passed successfully.

Variables help you avoid exposing sensitive information in your tests and make future updates easy—just change the variable’s value, not every test case. Start using variables in your API test cases to improve both security and efficiency.

Supporting Videoarrow-up-right

Last updated