Why does Postman change saved API requests - postman

I'm using Postman to test API and like its GUI and ease of use. But some things it does are completely incomprehensible to me. Example: I save an API request to a collection. Sometime later I try to recall it and it has changed. Why?
Scenario: testing against ElasticSearch API
GET _cat/indices.
Save to collection ElasticSearch.
Send other ES API requests.
Delete an index: DELETE /index0
Recall saved _cat/indices
Instead DELETE /index0 is recalled. Why?

It is possible that you turned off the "Always ask when closing unsaved tabs" option in Settings -> General. When this is off, it does not require you to hit Save, it will automatically save when the tab is closed.

Postman has tabs along the top, where each tab holds the data for a given request. When you edit the contents of a tab, you are editing the saved request as well. If you manually hit "save", the changes to the request are saved.
The way to avoid this would be to make sure that any time you are writing a new request and not intending to make it a change to an existing one, you do it in a new request tab (click the + button on the tab line), which you can then optionally save as a new named request.

To Turn Off Autosave, do the following:
Go to Settings -> General
Turn On Always ask when closing unsaved tabs.
Open a saved request, then change something in the request.
Close the request tab. Postman will ask if you want to save the changes. There will be a checkbox "to always discard unsaved changes". Tick the checkbox.
Click on "Don't Save".

Related

How to add a POST request in an existing collection?

I am trying to add POST request to an existing collection, Here by default only get request available. How can i change that?
You could either
Open a new tab (cntrl + T for Win, Ubuntu), select the new blank tab, choose POST request from the drop to the left of the url. Once you enter all details click on the down arrow next to save (right of the URL). Click on save as and name your request, add an optional description and then select the collection you wish to add it to.
We have different postman versions so I am unable to see the Add Request option in my drop down, but I recon you could click that and follow above steps.

Django: CSRF middleware and mixed POST/GET forms

I would like to crate a form whith two submit buttons: Save, let's say, and Back to edit. (The form is meant for a preview / confirm view of stuff that is currently being edited).
For obvious reasons the Save button has a formaction attribute with value post and the other button get. For the post action to work, I include the usual csrfmiddlewaretoken in the form.
So far all works well, the only problem is that the csrfmiddlewaretoken value is now included in the GET requests (which seems to be discouraged for security reasons).
Currently I add some custom javascript that finds all submit buttons with get action and adds a click handler that removes the csrfmiddlewaretoken from the field before submit. This seems a rather wierd and roundabaout way to do things.
Question: Is there a better / more standard / more stable way to handle this situation?
Edit: Why do I want to use get requests for some form actions?
Well, I would like to stick to the rule to use POST requests (only) for requests that change data (and in that case respond with a redirect).
As an example, think of a form where the user can edit ("page A") some fields, and then can press "preview" (a GET action), which leads "page B" where the same form is presented, but readonly, with a preview image generated by the system. If the user is happy, they can press "save" (a POST action) which will actually save the data, or they can press "back" (a GET action, similar to the Browser's back button), to continue editing the data. I would not be happy to implement this "Back" operation as POST, as this messes up the interaction with the actual Browser back button etc.
In this simple example, one could of course ask the user to use the browser back button instead of a form button, or (probably?) use javascript to simulate a browser back. But with slightly more complicated flow control a simple "back" is not an option.
The problem is that you send GET request from the form that contains your CSRF token. I would rather recommend PUT request than GET request. The CSRF token value is not exposed on the URL because the PUT request allows the body value to be passed.
About HTTP PUT method

C++ Outlook MailItem replace body and discard on close

I have an addon in Outlook which adds warning to mailbody and links in the email when email is coming from external or untrusted sources.
Anyway, when I replace something in body, when email is opened in full view (no reading pane, double click full view of mail item), I hook mailItem close even and I discard changes, everything works well. (mailitem.onclose(olDiscard))
When I do this with reading pane on, when I discard the changes, Outlook still either saves the changes or when user is trying to close Outlook it asks user "Do you want to save changes to ....." and if user clicked on multiple emails during this period, it shows popup question for ALL emails user clicked and we replaced its body.
What's the solution here? What can I do to fix this? I want to make changes to link and to body, but discard them when user clicks away on another email. End goal is not having Outlook to ask user "Do you want to save changes ..." popups. Please advise.
I can't also make changes to inspector, because inspector is read-only.
P.S. plugin is written in C++.
The solution is to avoid modifying the message body if you do not want to keep the changes.
If you want to show a warning to the user, add a task pane to the inspector. Or simply stamp the message with a category - it will be shown in the inspector.
The Outlook object model doesn't provide anything for handling hyperlinks clicks. As a possible workaround you may consider implementing the following functionality:
When the item is selected or opened in Outlook you may replace the original URL with your own where you can pass the original URL as an encoded parameter if needed. So, if it is allowed to open the URL you can redirect the request further. Note, you can use the SelectionChange event of the Explorer class which is fired when the user selects a different or additional Microsoft Outlook item programmatically or by interacting with the user interface. This event also occurs when the user (either programmatically or via the user interface) clicks or switches to a different folder that contains items, because Outlook automatically selects the first item in that folder. However, this event does not occur if the folder is a file-system folder or if any folder with a current Web view is displayed.
Also you may consider handling the Open event of Outlook items which is fired when an instance of the parent object is being opened in an Inspector. When this event occurs, the Inspector object is initialized but not yet displayed. The Open event differs from the Read event in that Read occurs whenever the user selects the item in a view that supports in-cell editing as well as when the item is being opened in an inspector.
Another possible solution is to register a custom URL handler. So, basically, your registered application will be launched instead of a web browser where you can decide whether to launch a web browser and follow the URL or not. See Installing and Registering Protocol Handlers for more information.

Postman collections: how do I save my requests into a collection?

I'd like to create a collection of requests in order to save them and share with collaborators.
I havent find any button, menu action to add new requests (or current request ) to the newly created folder Collection?
not so much intuitive...
I was able to do this by hitting the X to close a request. This popped up a warning asking if I want to save my request. I clicked on Save Changes, which then allowed me to save my request to a collection.
in the latest version of postman press ctrl+s -> and choose a collection to save into.
First create collection then create new request you will get option to save request "Save in existing collection" select your collection name and save it

Selenium Python: auto click allow for notification requests

I a have small scraper for Facebook that uses chromedriver.
However every time I login after a couple of seconds I have to click some button to allow Facebook notifications. Is there a way to do it automatically?
I've seen some suggest to press tab three times and then enter but I don't know when exactly I'll be prompted by the request and I don't want to press stuff at the wrong time.
Is there anything that can be one when creating the webdriver?
Most likely, this is because every time you start a new ChromeDriver instance you get an entirely new Chrome profile, just like if you opened a new private browsing session. So all the client specific settings that the page you want to test has defined via cookies will be lost and have to be set again. (The main reason why this is a good thing is that for automated testing, you'd like the page to be in the same state every time a new test visits it.)
There are however ways to emulate cookies for testing with WebDriver.
Example
Consider the page http://www.cnn.com for example. Every time you run a new test against that page, a bar at the bottom of the page will pop up asking you to accept their cookie policy:
The page stores the fact that you once clicked the "I agree" button in a cookie itself. You can use the Chrome content settings to identify which cookies a certain web page sets. Details on that can be found here: https://superuser.com/questions/244062/how-do-i-view-add-or-edit-cookies-in-google-chrome
For this particular page, the name of the responsible cookie is "CNNtosAgreed" and the value it is set to once you click the "I agree" button is "true".
In your WebDriver script you can use the manage cookies functionality to set specific cookies, so that the page you're testing thinks you have been visiting it before.
In the Java client bindings this would look like that:
Java
driver.get("http://edition.cnn.com/");
driver.manage().addCookie(new Cookie("CNNtosAgreed", "true", ".cnn.com", "/", null));
driver.get("http://edition.cnn.com/");
Notice how the first time Chrome navigates to the page, the confirmation dialog pops up, but not the second time.
Here are some examples of what the cookie API exactly looks like in Python: How to save and load cookies using python selenium webdriver