How to integrate API tests hosted in Postman's Team Workspace to Azure DevOps?

My previous blog post covered how to use Postman in API testing and integrate API test execution to Azure DevOps pipeline. Described solution assumed that API tests where exported to JSON-file which was added to the source control. Handling and maintaining API test JSON files in source control is not the most straightforward solution. This blog post shows how you can use Postman Workspace to maintain your API tests in cloud and share access for the team.

What is Postman's Team Workspace?

Postman's Team Workspace is a collaboration space for the team in the cloud. With team workspace, you can invite team members to collaborate on your API work within a workspace. Depends on the Postman plan you can invite multiple team members to the Workspace. Currently Postman Free plan enables to invite up to three members. To use team workspace for more than three members, you'll need the Postman Team, Business, or Enterprise plan.

Workspace members can comment on elements, use and change elements, or even fork from existing elements. Versioned history of all your changes is also available so anyone you invite to your team workspace can collaborate safely and effectively. Source

Especially from API test point of view notice that Postman Plans has different limitations for how many calls to Postman API is allowed per monthly. If you have a Basic Plan you can call Postman API 10000 times per month.


Source: Postman API Platform - Plans and Pricing

How to create Team Workspace?

Team Workspace can be created directly from the native Postman client or from the web interface. You can decide visibility level of the workspace between the following choices: Personal, Private, Team or Public.


When workspace is created you can start creating Collections and API tests.


How to integrate API tests from Team Workspace to YAML based pipeline in Azure DevOps?

Integration overview

YAML based CI/CD pipeline orchestrates build, deployment and execution of the API tests which are hosted in the Postman Team Workspace. API-tests requires system-to-system authentication (client credential flow) in this case. 


Integration between Postman and Azure DevOps

Newman CLI tool supports directly Postman's Team workspace so you can just easily point configuration to workspace instead of JSON based API test files.

Before starting

You need to have Postman Collection Id and API key to able to use Postman API endpoint when executing API Tests.

Postman API key

Postman API key enables you to communicate with Postman API endpoint. API key can be generated from Team workspace settings page https://[my-workspace] After API key is generated persist key to Azure Keyvault. 

Note that API key will be invalidated after 60 days of inactivity by default.


Postman Collection Id

Postman Collection Id is a unique identifier for API test collection. Typically I have structured Postman Collections so that each API has an own collection. You can get collection Id from the Postman client or executing the following GET-operation


Integration steps

Configure the following tasks to your YAML-pipeline / template.

1. Install Newman CLI tool

Newman is a command-line Collection Runner for Postman. It enables you to run and test a Postman Collection directly from the command line. It's built with extensibility in mind so that you can integrate it with your continuous integration servers and build systems. Source

- task: Npm@1
  displayName: Install newman CLI
    command: custom
    verbose: false
    customCommand: install -g newman

2. Get Postman API key from Azure Keyvault

Later you can get Postman API key from the variable called $(postman-api-key) 

- task: AzureKeyVault@2
  displayName: 'Get Postman API key value'
      azureSubscription: ${{parameters.azureDevOpsServicePrincipalName}}
      KeyVaultName: ${{parameters.keyVaultResourceName}}
      SecretsFilter: 'postman-api-key'

3. Execute API tests

First parameter of Newman is Postman API address with API key and Collection Id. This sample command reads Postman environment variables from the file and appends some sensitive variables.

- task: CmdLine@2
  displayName: Execute integration tests
    script: newman run${{parameters.postmanCollectionId}}?apikey=$(postman-api-key) 
-e $(Build.SourcesDirectory)/${{parameters.environmentFilePath}} 
--env-var clientId=${{parameters.idpClientId}} 
--env-var clientSecret=$(${{parameters.idpClientSecretKeyName}}) 


If you want to use Postman based API tests then integration to Team workspace is really nice possibility. Basically you can maintain your API tests directly in Postman and latest version is always available when API tests are executed in Azure DevOps.