postman-app-support icon indicating copy to clipboard operation
postman-app-support copied to clipboard

[Feature] Function to show notification/toast and prompting dialogs in scripts

Open jooleeanh opened this issue 7 years ago • 19 comments

App Details:

Postman for Mac
Version 5.5.0 (5.5.0)
OS X 10.12.6

Notification/Toast

Situation: I have some code that updates an environment variable (a user token) during the test script in some of my requests, and this happens without the postman user knowing (unless they already know or look at the test script).

It would be useful to have a function that shows a notification/toast in the app's UI, such as the one when there's an error in the script: image The parameters would be: function showToast([String] message, [Number] duration, [Enum] color) {}

Prompt dialog

Situation: I have some environments that represent a production environment, and some requests (PUT/POST/DELETE) can be dangerous to execute on them. Since the selected environment is not always obvious (if we're going back and forth between postman and other applications), it's possible to send calls that we wish we didn't.

It would be nice to have a function that prompts the user (in this situation, used in the pre-request script) with a message, OK and Cancel choice. This would need a resulting callback along with another function to properly cancel a request.

The function could look like: function prompt([String] message) {}

jooleeanh avatar Dec 15 '17 13:12 jooleeanh

Thanks for the suggestion @jooleeanh.

numaanashraf avatar Dec 15 '17 14:12 numaanashraf

I see even more use for the prompt not only as a 'ok' 'cancel' situation but also a prompt for a specific 'value'.

use-case: in a REST api you usually work with an entity more than 1 call at a time. We often create an entity (f.e. User). while running it's tests, we 'set' it's ID in an environment variable. when you later request a single user you can request it by it's created ID. However if you open the collection to manually testrun the result of a single user, you have not set the environment variable. Thus in a pre-request script you could test if the environment has that variable and otherwise prompt for it.

sanderhouttekier avatar Apr 23 '18 15:04 sanderhouttekier

@saelfaer - we ran into this exact same issue. The solution came up with was to throw an error object, which Postman will print the message for. -

if (!pm.environment.get("some_variable")) { throw new Error("Some Variable Not Set"); }

bt-dd avatar Nov 29 '18 16:11 bt-dd

Any update on this ? Felt the need again on another project.

jooleeanh avatar Feb 19 '21 10:02 jooleeanh

I would really appreciate this kind of functionality, especially if it gave us the option to actually prompt for a value, since this would make building Postman API collections really interactive.

Throwing errors is just a rather non-elegant workaround to the user experience this could enable.

I'd suggest to implement a more flexible interface for this functionality:

// Just the OK button style prompt
// @param message text to display to the user 
function prompt(message: string): void

// Prompt asking user for an input
// @param message text to display to the user
// @param options.inputType which input type to display to user, restrict to most simple options for starters
// @param options.inputLabel string to display directly above the input field
function prompt<T =  string|number|boolean>(message: string, options: { inputType: 'text'|'number'|'boolean', inputLabel: string }): T

Use case for me: Request needs multiple path variables from Postman globals. Pre-request I want to check pm.globals for all necessary path variables so that they are not empty string or undefined and request input from the user for this global if it does not contain a value yet. This way other developers working with the Postman collections could have an easy way to make fully functional calls to my APIs on the first try, without searching all places the variables could pop up (path, query params, headers, body).

maxsommer avatar Mar 05 '21 09:03 maxsommer

Another use case: we're sending the same HTTP request to different stages (dev, acceptance, production). The URL and other properties for the different stages are configured via environment variables. I would like to add a prompt to the pre-request script that warns before sending the request to production, in order to make sure that one doesn't do this by mistake.

cristian-pirnog avatar Sep 22 '21 09:09 cristian-pirnog

Is there a chance to see this feature released in 2023 ? Hope you will soon :) Thx

PsyOhm23 avatar Jan 19 '23 14:01 PsyOhm23

Is this purely notifying the user of something like a warning or info? Console right now is the best place to log this, but I'm guessing its lack of indication/affordance once an important msg is logged is the reason why you are looking for a toast.

Also, Toast is a bit tricky, as it might lead to a very bad user experience if over used.

giridharvc7 avatar Jan 19 '23 18:01 giridharvc7

Thx for you answer

I have booleans in my global environments to switch to some configurations or not (mock mode, intranet mode...)

I would like to be notified if one of these configurations are activated to warn me that I'm not in the base configuration.

PsyOhm23 avatar Jan 23 '23 15:01 PsyOhm23

+1 for this feature request. would be nice to be able to trigger popups before or after a script execution.

Throwing an error for incorrect environment is great, but not for informational details.

mwaarna-tgm avatar Feb 08 '24 21:02 mwaarna-tgm

+1 for this feature request!

kovdmm avatar Feb 11 '24 21:02 kovdmm

@kovdmm it will help us solutionize better if you can mention your usecase as well?

@mwaarna-tgm can you elaborate on "Throwing an error for incorrect environment is great, but not for informational details". What details did you wanted to highlight in your usecase?

vedkribhu avatar Feb 22 '24 04:02 vedkribhu

@mwaarna-tgm can you elaborate on "Throwing an error for incorrect environment is great, but not for informational details". What details did you wanted to highlight in your usecase?

Essentially would love a notification for warnings / success calls. Currently we use console.log, but not everyone has it open to keep watch on it. Something along this Vue JS notifcation that we could call from the tests: http://vue-notification.yev.io/

mwaarna-tgm avatar Feb 22 '24 16:02 mwaarna-tgm

Similar to kovdmm

  • Three environments
  • Common requests re-used across different environments via the Environment drop box in upper right hand corner.
  • Dev / Test Env, request away, POST, PATCH, no problem.
  • But if they chose Prod, there's potential to do damage depending on the Request.
  • Secure teams and access levels and all that, yes, but accidents can happen.

In user story format:

As a System Product owner, I don't want my Developers updating my Production data due to fat fingers or not understanding the nature of the request, so the RBAC my System relies on for security is not compromised, resulting in destructed data.

Mindful Toast on Production select or pre-request script could cause undue friction.

Alternate approaches could include:

a. Relate Postman IDE/DOM background colour to an Environment value. Admins enter their desired Environments and chosen Background colours, fully custom. Then on change Environment, background colour change, in your face; fore-armed is fore-warned approach. Other thick clients have this type of configuration; you log in, you see Red: think "Hey, don't put production data here, you're in the Test environment" etc etc.

b. Lock Writable methods to Roles (or some equiv Postman security construct) So POST, PUT, PATCH and DELETE execution request could perhaps be limited to a select group (or anyone by default) Then by Environment perhaps even. (POST OK in Development for Role X, but not POST in Production) So sure they could see the request (so discoverability not compromised), not be limited to adding new writable requests (so collaboration is cool), but at the point of executing them in a given Environment; that gets determined by their Role.

combility avatar Mar 01 '24 02:03 combility

+1 for this

leubeem avatar Apr 08 '24 18:04 leubeem

+1

relliv avatar Jun 04 '24 23:06 relliv

+1

YourYoungerBrothersPug avatar Jun 12 '24 14:06 YourYoungerBrothersPug

+1 for this feature 👍

Tosox avatar Jun 21 '24 11:06 Tosox

+1

Thomasmuur avatar Jul 11 '24 14:07 Thomasmuur

Also +1 from me!

But I cannot see any respons from Postman development?

Harm10 avatar Aug 02 '24 15:08 Harm10

+1

pablomolinas avatar Aug 07 '24 13:08 pablomolinas

+1

wsilva-fms avatar Aug 18 '24 20:08 wsilva-fms

+1

wredmondln avatar Nov 22 '24 15:11 wredmondln

+1

rifateroglu avatar Jan 22 '25 19:01 rifateroglu

+1

AceOubahaTLI avatar Apr 09 '25 22:04 AceOubahaTLI

+1

rajjaiswalsaumya avatar May 23 '25 01:05 rajjaiswalsaumya

+1

gabrielassed avatar Jul 28 '25 00:07 gabrielassed

+1, still relevant

hexrw avatar Aug 25 '25 14:08 hexrw

+1 for this feature 👍

Dauthjan avatar Aug 26 '25 22:08 Dauthjan

Why would you allow a login to a user who can make mistakes. The best option I would think is if you think someone is not responsible enough do not grant them a production login token. Best way to prevent a system by not allowing access and not warning.

Another use case: we're sending the same HTTP request to different stages (dev, acceptance, production). The URL and other properties for the different stages are configured via environment variables. I would like to add a prompt to the pre-request script that warns before sending the request to production, in order to make sure that one doesn't do this by mistake.

rajjaiswalsaumya avatar Aug 27 '25 04:08 rajjaiswalsaumya