Run API tests using Postman Monitors
Postman Monitors provide a way to automatically run post-response scripts and perform tests at regular intervals, or only when triggered by the Postman CLI. When you set up a monitor, you choose a collection with the requests and post-response scripts you want to run, and you specify how frequently Postman runs the collection. You’ll be notified if a test fails or the monitor run encounters an error, and all results are recorded on the monitor’s dashboard.
Below are some ways you can use monitors to test your APIs and ensure they’re functioning correctly.
For examples of monitors in action, visit the Postman API Monitoring Examples public workspace to find example collections for some common monitoring use cases. You can collaborate on the collections in the workspace by creating a fork, or modify the collections for your team’s use by exporting and importing them into your internal workspace.
Monitoring an API endpoint
To monitor a specific endpoint, create a collection with different variants of the same endpoint in different requests, such as requests using different query parameters, headers, or request bodies, to test responses for each variant and ensure complete test coverage. To learn more about testing requests, see Write scripts to test API response data in Postman.
Monitoring an entire API
This is similar in approach to monitoring a specific endpoint, with the subtle difference of storing the common API host in an environment variable, such that the requests across different API endpoints differ in their path, among other request parameters. Such a sequence also makes it possible to chain data across requests, which enables testing an entire API as a whole.
Running API tests
When testing APIs with dependent requests, you can save part or all of a response as a variable and reuse it in later requests. This is useful for passing data such as IDs, tokens, or other values between requests.
Postman stores variables as strings. To work with complex data like objects or arrays, convert them to a string using JSON.stringify() before saving them, and use JSON.parse() to read them later. Once stored, you can reuse this value in subsequent requests, for example as part of a request body.
Monitoring HTTP response codes
Response code tests can be done by checking the value within post-response scripts.
Monitoring latency
As an alternative to request timeouts, website response latency can be monitored within post-response scripts.