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 String value to 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 password.
You can also reference this parameter in Code view with the following syntax:
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).
Create a Snippet
- Open a project.
- Open a test.
- Click the first component you want to include in your snippet.
- Hold down the
[SHIFT]key and click on the last component you want to include. This will highlight your snippet selection.
- Click Export snippet from selection.
- Give the snippet a name.
- Select Save Snippet.
That's it! Now that your snippet has been created, you can use it in every test within the Project.
- 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.
For each snippet, two actions are available:
- Paste Snippet: Allows you to paste the entire component inside the test, which you can then edit as needed. The pasted components will lose any reference to the original snippet.
- Invoke Snippet: Creates a Call component that will invoke the snippet. If the snippet changes, all the tests containing the Call component to that snippet will inherit the changes.
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 to the + Add Request Headers section below the request component.
- Select Basic Authentication from the list.
- Enter the details for
password, then select Save.
- Once the Authorization Header appears, highlight it in the UI, then select the Export snippet from selection icon in the toolbar.
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 insert or invoke this snippet in future tests that require a Basic Authentication header.
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.