# Trigger test from POST request to mock server

**URL:** <https://community.postman.com/t/trigger-test-from-post-request-to-mock-server/69800>\
**Category:** Help Hub\
**Tags:** tests, variables\
**Created:** [October 16, 2024, 4:13pm UTC](https://community.postman.com/t/trigger-test-from-post-request-to-mock-server/69800 "2024-10-16T16:13:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![owenhdiba](https://avatars.discourse-cdn.com/v4/letter/o/3e96dc/32.png) [@owenhdiba](https://community.postman.com/u/owenhdiba)\
**Post date:** [October 16, 2024, 4:13pm UTC](https://community.postman.com/t/trigger-test-from-post-request-to-mock-server/69800/1 "2024-10-16T16:13:47Z")

</div>

> **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](https://learning.postman.com/docs/design-apis/mock-apis/mocks/overview) and [Create a mock](https://learning.postman.com/docs/design-apis/mock-apis/mocks/create-a-mock).  
> Working with an AI coding agent? The [Postman plugin](https://github.com/postmanlabs/postman-plugin) can build and run mocks for you.  
> For current help, see the [Postman docs](https://learning.postman.com/docs/), try the free [Postman tools](https://www.postman.com/tools) (no account needed), or join us on [Discord](https://discord.gg/58aNNsRBGR).

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.

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [October 21, 2024, 3:14pm UTC](https://community.postman.com/t/trigger-test-from-post-request-to-mock-server/69800/2 "2024-10-21T15:14:59Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![owenhdiba](https://avatars.discourse-cdn.com/v4/letter/o/3e96dc/32.png) [@owenhdiba](https://community.postman.com/u/owenhdiba)\
**Post date:** [October 24, 2024, 10:05am UTC](https://community.postman.com/t/trigger-test-from-post-request-to-mock-server/69800/3 "2024-10-24T10:05:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [October 24, 2024, 3:01pm UTC](https://community.postman.com/t/trigger-test-from-post-request-to-mock-server/69800/4 "2024-10-24T15:01:39Z")

</div>

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](https://learning.postman.com/docs/collections/running-collections/collection-webhooks/) to learn how you can trigger a collection run using a webhook.

---

<div class="post-metadata">

**Author:** ![owenhdiba](https://avatars.discourse-cdn.com/v4/letter/o/3e96dc/32.png) [@owenhdiba](https://community.postman.com/u/owenhdiba)\
**Post date:** [October 28, 2024, 10:08pm UTC](https://community.postman.com/t/trigger-test-from-post-request-to-mock-server/69800/5 "2024-10-28T22:08:38Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [November 11, 2024, 10:36am UTC](https://community.postman.com/t/trigger-test-from-post-request-to-mock-server/69800/6 "2024-11-11T10:36:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [December 11, 2024, 10:37am UTC](https://community.postman.com/t/trigger-test-from-post-request-to-mock-server/69800/7 "2024-12-11T10:37:17Z")

</div>

Closed on December 11, 2024, 10:37am UTC

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