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.
- 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.
- 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
- 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);
- to demonstrate, add as a postresponse script to the request:
console.log(JSON.stringify(pm.environment.toObject()));
- 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: