New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XMLHttpRequest (XHR) is broken in pre-request scripts in v4.5.1 #2232
Comments
Postman scripts were not supposed to make requests. The request itself is there to do that. Since we now run the scripts within underlying NodeJS scope, XHR is not longer valid. Instead of using an XHR call to fetch variables, can you add an actual request to fetch the variables of possible? |
I could, however, the tokens that we get are very short lived (60 seconds), so unless there is an automatic way to chain requests together, the pre-request script is ideal. Here is actually what we do in the pre-request script currently:
To do this manually with multiple requests is very tedious and error prone and leaves a less than desirable user experience. If Postman is now running under nodeJS, then is there anything stopping us from using node's 'http' module? ** UPDATE: ** |
Hrm...just had a look at the Authorization section again (we originally tried it and while it worked, it had some drawbacks). However there are still few items that make it less than desirable for us:
It was actually these two reasons that led us to develop the pre-request script above that broke. |
Okay. Did you have a look at postman.setNextRequest? Allows you to jump to one request from another. What if you set auth request and jump to that after test and return to where you want? If that helps, we discuss more. |
I did not know about setNextRequest. I am not sure I am following what you are saying with regards to |
Sorry for being so vague in my last reply. The feature I'm referring to is - https://www.getpostman.com/docs/workflows |
Hrm, that works but it is still cumbersome. Perhaps I should try to explain a little more about how we use Postman. First we are NOT using the whole testing part of it at this time. We are using it more as a developer tool at this time. Here is a typical flow.
All of our requests share the same method of getting a token. Therefore, the suggestion to use test scripts and the We also use postman to check on individual API calls that have failed for our clients or ourselves. In this case we use a very similar flow as above, simply because they are one off requests. As mentioned above, the Authorization tab is 90% of the way there for us, so we'll probably use that. However, if feature requests could be made for the following functionality, I believe it would make POSTMAN much easier to use:
|
@dijitalmunky That's super helpful. Let us think about this use case more and figure out the best solution. |
We have the exact same issue as the OP. Because Postman does not have an easy way to make a POST with credentials and extract a bearer token (as part of the built-in authorization schemes) we are forced to add a pre-request script to all of our calls:
And because there is not a reusable library of our functions, we've jammed that function into an environment variable that does the following:
This is an incredibly common way of auth'ing, so unless I'm missing something in a new version—have been afraid to upgrade because xhr.open is now broken—then we need a less cumbersome solution than presented in the replies to OP. Thanks! |
Basically, I think improving/generalizing the authorization functionality will solve 90% of cases—but I still don't see why we can't make calls from the pre-request script or the post-run tests? There are all sorts of reasons one would want to do this. Is there really no way anymore? |
@prdonahue We are thinking of doing both: custom auth plus the ability to send requests from pre-requests/test scripts. Will post an update here soon. |
Any word? I've got near identical concerns. Checking/Getting/Setting a token. Thanks. |
I have a var jsonData = JSON.parse(responseBody);
tests["access_token"] = jsonData.access_token !== "";
postman.setEnvironmentVariable("JWT", jsonData.access_token); In all other requests that require JWT, I setup the
I just have to click |
Has there been any progress on this? I just updated to the latest version and XMLHttpRequest is still broken. There are a lot of use cases for being able to execute one request before another and postman.setNextRequest does not cover this. Something like postman.executeRequest(requestName) would solve this issue. |
Yep still broken for me. |
Agreed, an update on progress/decisions would be nice. While more automation around the flows defined by oauth2.0/oidc would be nice and a definite timesaver, we have gotten used to the auth helpers (https://www.getpostman.com/docs/helpers) and needing to constantly get new and delete expired tokens. |
I've started looking at alternatives, I can only assume XMLHttpRequest was broken deliberately so they can push "extra" features for some kind of pro/subscription model. |
@lloydjatkinson No. We did not want to build another set of meta-tools when people start sending API requests within scripts. We have a better solution now through the new pm.api that is planned for release soon. We'll update the thread when it is out. |
@a85 Any update on this? I too am looking for a way to get and set a token before a request. "setNextRequest" would be sufficient except I need something that works outside of a collection run. |
This is very frustrating. I have a method similar to the above (put a function into a global variable and call it from all of our scripts pre-request script using eval). It works fine in the chrome app. Some of our developers are using the standalone postman app though (which I believe is the supported standard moving forward) ... and it doesn't work there (XMLHttpRequest is not defined). setNextRequest is useless for this workflow, as we want to call the actual request we want and then to have it call the authentication request. The best way I can see to get this working (apart from allowing some kind of http request access) would be to be able to call another request by name from the pre-request script (or some other method). eg. Is there a solution for this forthcoming? |
Same here. I use Postman for Mac. It doesn't have I want to collect the urls from the API response and verify all of them are accessible. That said, requests to them return HTTP 200. And I can't do such a basic test. |
Same here. Perhaps it's just in the backlog and not a lock-in strategy? Please add XMLHttpRequest back in. |
+1 |
Hi, I am having the same problem. One of my suprises was that there was not real custom authorization part. |
This is now possible in Postman v5.2.0 and above, with |
@aaiezza Are you on the Chrome app? This feature is exclusive to native apps. |
I think I am. Where can I download the native app? CorrectionActually , when I start Postman on macos, I see a warning that Chrome apps are being deprecated and to download the free native app for continued support and better performance. |
Yes, you can download the native app from: https://getpostman.com/apps |
@kunagpal, gotcha. So I actually did use that link to install Postman. I download, unzip, and drop the .app file into Applications and run it. For instance, I still don't see that Thoughts? |
Hi @aaiezza, The one that's the native app will have 'Applications' written besides it. And also once you launch the native app,
Whereas this won't happen for the native app. |
Hi @sivcan, I actually do not see a Chrome App version at all. I do not think I have any chrome apps installed. I did run your test though! |
Eureka! Except now my issue is that environment variables are no longer resolved in the Pre-request scripts. |
@aaiezza - I can confirm that the environment variables are being resolved on Postman Canary. You can see the response below that the url is being correctly hit with the variables resolved. If not this, then is it something else that you're trying to do ? Thanks |
@sivcan, Forgive me for being unclear. |
In the latest version of Postman App on Mac OSX, the code
new XMLHttpRequest()
return a new empty object, not an actual XHR object as expected.Version/App Information:
Steps to reproduce the problem:
In v4.5.1 I get the following instead (on the main Postman window:
and this as the output in the console window:
** NOTE ABOUT THE SCRIPT **
We use a similar script to this to make some requests to our auth server and set some Postman variables before the request executes so that the actual request will authenticate properly.
Unfortunately, we use a synchronous xhr call because there is no way we could find to make postman wait for all the async code in the pre-request script to complete before triggering the actual request.
Ideally, we'd like to be able to return a promise from the pre-request script that Postman could wait for before executing the main request. Alternatively, giving the pre-request script a callback function that could be invoked when the pre-request script is done would also be acceptable.
The text was updated successfully, but these errors were encountered: