Trigger test from POST request to mock server

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.

Hi @owenhdiba. Welcome to the Postman Community.

What you are trying to achieve is not very clear to me. You want a call to a mock server to trigger a collection run?

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?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.