Prompt values before request

First of all: Hi! :slight_smile:

It looks like I cannot find the right search terms, because my searches have been unsuccessful so far.

Is there a way to display something like a form before sending a request to define values for local variables that are necessary for this request?

I tried the JavaScript function prompt(), but it was not recognized by Postman. Alternatively, I would set the variables in the pre-request script and let the users adjust them there, but this causes the request to change and the user will get a prompt to save it.

Hopefully I could describe my need in a more or less understandable way. Any hints for a solution are welcome. :slight_smile:

2 Likes

Also wondering about this. Does it exist?

Hiya,

There’s no way to prompt for values at runtime. The closest thing to a quick pop-up is to open the Environment by hitting the eyeball in the top right and making adjustments prior to sending a request or running a collection.

Best,

Kevin

Is prompt feature avaialble in postman now?

It’s now been 10 years since this feature was requested on GitHub. We should be celebrating its anniversary. It’s also the 4th most requested feature on GitHub, and the question posted here, despite being much newer and a duplicate, has amassed 13.5K views.

Literally any API I can think of has a variable that changes between requests:

  • /users/:id
  • /users?country=:country

Instead, I have to edit my requests all the time, and when try to close them, I get prompted to save my “changes” - so you do know how to build a basic prompt!

For the life of me, I can’t understand why the Postman team is dragging their feet on this basic, basic feature while wasting valuable engineering time adding useless AI bots to the app that literally nobody asked for.

6 Likes

I’m not sure but using this info… Adding External Libraries in Postman | Postman Blog
perhaps can someone find an external library that have the “prompt” functionality… (Up to know… i didn`t find it.)… I have try several, but are requesting for “prompt” function itself…

one of the problems here is that it makes the data entry of just a few variables difficult… because you have to scroll through the entire collection / environment and all those variables. This takes up valuable brain power / effort when you really need to be focusing on how to make things work and not searching for which variable to replace in a huge list of all the variables being used by all the requests in the process.

This is an itch I have been needing to scratch. I don’t have a way to make a true prompt but here is a work around I have come up with to get a smaller edit that focuses just on adding / editing the specific variables I need to edit at a specific step.

  1. Add a simple GET request to the collection for http://localhost or some other location that will just accept and throw away the data and that your comfortable with it being sent to.
  2. Add just the variables you want to work with at this point of the process to the “Query Params”. These are the variable names you want to add or edit and their values. For example:
somekey: somevalue
anotherkey: anothervalue
  1. Add as a pre-request script to the request:
function addQueryParametersToEnvironment(param) {
  pm.environment.set(param.key, param.value);
  console.log(param.key, pm.environment.get(param.key));
}

pm.request.url.query.all().forEach(addQueryParametersToEnvironment);
  1. to demonstrate, add as a postresponse script to the request:
console.log(JSON.stringify(pm.environment.toObject()));
  1. run the request.

You should now see in the console log that your keys / values have been added / edited in the environment.

example console output:

 
"somekey" "somevalue"
 
"anotherkey" "anothervalue"
 
GET http://localhost/?somekey=somevalue&anotherkey=anothervalue
200
211 ms
 
{"somekey":"somevalue","anotherkey":"anothervalue"}

So basically, you can use this request now in your colelction as a substitute for prompt capability to provide a bit more focus on the specific variables you want to change.

Once you have this in place, future requests you just edit the parameters or give people instructions to edit the parameters on this request.


Here’s the example as a collection export:

{
	"info": {
		"_postman_id": "3ead7fec-06d0-4c7f-a2eb-2c7f5bc1f108",
		"name": "PromptSubstitute",
		"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json",
		"_exporter_id": "12148752"
	},
	"item": [
		{
			"name": "Prompt1",
			"event": [
				{
					"listen": "prerequest",
					"script": {
						"exec": [
							"function addQueryParametersToEnvironment(param) {\r",
							"  pm.environment.set(param.key, param.value);\r",
							"  console.log(param.key, pm.environment.get(param.key));\r",
							"}\r",
							"\r",
							"pm.request.url.query.all().forEach(addQueryParametersToEnvironment);"
						],
						"type": "text/javascript",
						"packages": {}
					}
				},
				{
					"listen": "test",
					"script": {
						"exec": [
							"console.log(JSON.stringify(pm.environment.toObject()));"
						],
						"type": "text/javascript",
						"packages": {}
					}
				}
			],
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "http://localhost?somekey=somevalue&anotherkey=anothervalue",
					"protocol": "http",
					"host": [
						"localhost"
					],
					"query": [
						{
							"key": "somekey",
							"value": "somevalue"
						},
						{
							"key": "anotherkey",
							"value": "anothervalue"
						}
					]
				}
			},
			"response": []
		}
	]
}

and a visual image of where you edit the prompt:

and not to say that this is optimal…
I’d much prefer to be able to simply do:

pm.environment.set("somekey", prompt(message));
1 Like