Extracting the query params of pre-defined examples for a request

Is it possible to extract info about the examples you have defined for a request using the “pm.*” commands in the pre-request tab?

Goal: I have a mock server with a POST request set up and have multiple examples (each of them has a query parameter called “example_name” which is a string, and has a defined value). I want to send different responses back depending on what name the request body contains when the POST request’s endpoint is hit.

For example: If the request contains “example_name: example4” in the body, then I want to return the example which has the query parameter “example_name” set to “example4”.

But I would prefer not to hardcode these name values in the pre-request tab. Is it possible to extract the query parameters for all the examples? Something like “pm.examples.queryParams()” and then get a dictionary like: { “example1” : {“example_name”: “example1”}, … , “example4”: {“example_name”: “example4”}, … } or something similar?

I haven’t tried this, but have a look at the following.

Mocking with the Postman API | Postman Learning Center

Step 4 seems to indicate that if you send your API_Key it will return details about your current mocks.

Have a look at that and see if it returns the information you need.

Just tried this, but it doesn’t give you the body of the examples.

You can call the collection API directly and get the details of all of the information in the collection (as its just a json file) but targeting the examples elements will be fun as its a fairly complex json structure. It means that the examples have to be in the collection.

It would be nice if you could get the example info directly from the mock server instead, but I can’t see a way of doing that.