Configure Postman Collection targets
How to configure Postman Collection targets for Snyk API and Web
Use Postman Collections to define API endpoints for scanning with Snyk API & Web.
Configure Snyk API & Web to scan API endpoints using a Postman Collection. The configuration involves three main steps:
Prepare the Postman Collection
Configure an API target using the Postman Collection
Configure the API target with Postman environment variables
Example scenario
This example uses a Postman Collection with the following requests:
Authenticate and obtain an authentication token - requires a username and password in the request body.
Get a list of users - requires the authentication token in the request header.
Get user details - requires the authentication token in the request header and the user identifier as a parameter.
Prepare the Postman Collection
Prepare the Postman Collection to run the sequence of requests from start to end without errors. This ensures a clean export for configuring an API target in Snyk API & Web.
Create variables
Navigate to the Variables tab of the collection to create auxiliary variables:
username: hard-coded value of the username to obtain the token.password: hard-coded value of the password to obtain the token.user_id: value to get user details by ID. Leave the value as null because the script sets it dynamically.
Set the
usernameandpasswordvariables as Shared, so that the exported collection contains their hard-coded values. Set theuser_idvariable as Unshared, because the script sets the value dynamically.Navigate to Environments to create the variable for storing the authentication token, and other variables that you set in Snyk API & Web:
bearerToken: variable to store the authentication token. Leave the value as null because the script sets it dynamically.baseUrl: hard-coded value of the API URL.
Your collection and environment variables look like the following example:

Configure the authentication request
To obtain the authentication token, navigate to the authentication request and set the payload in the Body tab with the
usernameandpasswordvariables.
To set the returned authentication token in the
bearerTokenvariable, navigate to the Scripts tab of the authentication request and add the following JavaScript in the Post-response:After the token is configured, add the
bearerTokenvariable to all requests in the Headers tab.
Configure request parameters
In this example, the request to obtain user details requires the user identifier as a parameter.
To set the returned value in the
user_idvariable, navigate to the Scripts tab of the users request and add the following JavaScript in the Post-response:Navigate to the request that gets the user details and add the
user_idvariable as a parameter.
The following image shows an example of a request to get user details.

Test and export the collection
With all requests configured, run the collection to test it. If there are no issues, export the collection.
Add a Postman Collection target
After the Postman Collection is prepared and exported, add an API target.
Navigate to Targets and click Add.
Complete the Add target form:
Name: Enter a meaningful identifier for your target.
URL: Enter the base URL for your API.
API Type: Select API, then select Postman Collection.
Select Schema file upload.
File: Choose the file exported from Postman.
Click Add.
Configure Postman environment variables
This example added two variables to Environments: baseUrl and bearerToken. Because the baseUrl was hard-coded in Postman, you must also set its value in Snyk.
For security reasons, set the password variable using the credentials manager. Variables added to Environments take precedence over the variables added in the collection.
Manual configuration
Configure environment variables manually in the user interface:
Navigate to the target Settings.
In the Scanner section, select API SCANNING SETTINGS.
Enter the required Postman environment variables in the corresponding fields.
Automated configuration using script
Alternatively, import environment variables using an automated script:
In Postman, export the Postman environment to a file.
Retrieve the Python script to import Postman environment variables into Snyk. Find this script on the Probely API Scripts GitHub page.
Run the Python script and enter the following values:
Target ID: The Snyk identifier of the API target, which you find in the URL of the API target. For example, the target ID in
https://plus.probely.app/targets/2yzxnYgwmqbdis2yzxnYgwmqbd.Postman collection file: The file exported from Postman containing the environment variables.
Navigate to the Postman Environment Values section of the API target to see the newly added environment variables.
Verify the configuration
After configuration is complete, the target is ready to scan. Test your configuration and then run a scan to verify that all requests in the collection are tested.
In this example, the authentication request to set the bearerToken is the first in the list of the collection, so the scan can run all the requests. For production scenarios, Snyk recommends that you configure Postman authentication and enable API TARGET AUTHENTICATION and LOGOUT DETECTION in Snyk.
Last updated
Was this helpful?

