Archived topic — some details may be out of date.
Mock servers built from saved collection examples are still supported. Postman now also has code-based mocks: JavaScript request handlers plus a config.yaml, stored as files in your Git repository, which you can run locally or deploy. Create one in the app, or use the Postman CLI to generate one from an OpenAPI spec, collection or dataset (postman mock generate) and run it (postman mock run). See About mocks and Create a mock.
Working with an AI coding agent? The Postman plugin can build and run mocks for you.
For current help, see the Postman docs, try the free Postman tools (no account needed), or join us on Discord.
I have an API that I’m testing. I have a test on postman that sends a POST request to my API along with a callback url on a Postman mock server. The request sends an initial response, does some processing, and then sends data by doing a POST request to the callback url on the mock server. I can see that the mock server is correctly receiving the request.
I want to know if there’s some way I can set environment variables using the request data to the mock server and then trigger another test to the api using these environment variables in the request body.
What I want is that when the Postman mock server receives a POST request from my API, it runs a “post-Response script”, that will set some environment variables and then trigger another request to be sent to my API.
Mock servers might not be the most efficient tool for this use case. Webhooks however can be used.
You can use the Postman API to create a webhook. A request sent to that webhook endpoint will trigger a collection run, and you can have requests in that collection run test scripts, make API calls, etc
You can follow this guide to learn how you can trigger a collection run using a webhook.
Thanks. Found that really helpful. Only thing I can’t get my head around is how to send a POST request to a url template like /webhook_url/{request_id} instead of just /webhook_url/, but for it to still trigger the collection run. Any ideas?
Hi @owenhdiba. I am not sure I understand your question correctly. This ideally should heavily depend on the environment the webhook is being triggered from and how it handles variables. Everything in the curly braces are variables and needs to be replaces with the actual variable value. So far a valid request is made to the webhook, it should trigger a collection run.
OR
Are you looking to pass a variable to the webhook url that triggers the collection run?