Our Vault feature allows you to store variables and code snippets to use in your tests in one project, or across all projects. You can also store files for use in one project.
What You'll Need
- An existing API Testing project. For details on how to create one, see the Quickstart guide.
There are two types of API Testing vaults, the Company Vault and a project-specific Vault. While their UI is the same, they serve two different purposes.
The Company Vault is where you can store variables and test code snippets to use across all of your projects. You can access this tab from your API Testing home page, where all of your projects are listed.
The project Vault, which you can access from within a project, is where you can store project-specific variables, test code snippets, and files.
In the Variables section, you can define environment variables to use in your tests, so that you don't need to rewrite them every time.
The screenshot below shows the Company Vault; these variables are available across all projects.
Define a variable at the project-specific Vault when you need to use the same one across multiple tests. For example, you could save a password here as a variable and reuse it in multiple tests.
Additionally, you can import variables from Postman. See Importing Postman Collections, Variables, and Environments for more details.
If the same variable with the same name definition exists in both the Project Vault and Company Vault, then the value in the Project Vault will override the one in the Company Vault.
Create a Variable
- Open a project.
- In the left panel, click Vault.
- Select New Entry.
- Add a Key (e.g.,
- Add a Value (e.g.,
- Select Confirm.
Then in your tests, you'd reference the variable by the
Key using the following syntax:
Use Case: Product Variable
Consider a scenario where an
/product endpoint requires a specific
id query parameter.
While this is a perfectly valid request parameter, it can be hard to manage and update if you scale out your tests. Therefore, rather than continuously hard-coding this value into the Query Params field, a safer and more efficient approach is to export this value into to a variable.
The following is an example of how it might look in the project-specific Vault:
Now you can switch the Query Params field from a String value to a Variable and enter the variable name:
product_id (see the screenshot below). This allows you to have multiple tests in your project using the same product_id.
In the Snippets section of the Vault, you can create or import test component/code examples. A snippet is a test code fragment that you can create, import, and store in your Vault and reuse in multiple tests. Snippet length can range from one line of code to an entire test.
Much like with variable scope, snippets saved in a project Vault are only available in that project, and snippets saved in the Company Vault are available across all projects.
When you save a snippet from the Composer, it will be saved in the project Vault. While you cannot save a snippet from the Composer to the Company Vault, you can export there using the import/export feature (see screenshot below).
- Open a project.
- In the left panel, click Vault, then click Code Snippets.
- Click any of the fields and begin typing to edit the details. Your changes are saved automatically.
Use Case: Authentication Snippet
A good use case for the snippets feature is building an authentication flow; you don't need to rewrite all authentication steps for every single test. Instead, call the snippet that contains these authentication details. Another good example is integration testing, where you can reuse various tests to create one larger flow.
Below is an example of how to create an Authentication Snippet.
- First, create a new test with a request component that requires basic authentication. For examples, check the Sauce Labs REST API endpoints for ideas.
- Select Add Child Component below the request component.
- Select Basic Authentication from the list.
- Enter the details for
password, then select Confirm.
- Once the Authorization Header appears, click Save Changes.
- Hold down the Ctrl key, highlight the code in the UI and Save Snippet.
- Give the snippet a name and Save Snippet.
Consider a scenario where this login will be required for all the endpoints we have to test. It makes sense for this call to be stored in the Vault.
Now you can choose to Call Snippet or Paste Snippet in future tests that require the Login.
In the Drive section of a project-specific Vault, you can upload files to use in your tests. The file size limit for an individual file is 16 MB. The total limit for the Company Vault is 100 MB. This means if one project-specific Vault is using 100 MB of storage, other projects cannot upload addtional files.
Uploading a file
- Open a project.
- In the left panel, click Vault, then click Drive.
- Click Upload file.
- Upload the file using drag and drop or Choose file, or enter the URL, then click Upload.
You can work with your files in Vault Drive as follows:
If you upload a file via a URL, you can hover over source url to view the full address.
You can rename, download, or delete individual files.
To delete multiple files, select the checkbox next to the files, then click Delete Selected.