Jairo Andres Ruiz Machado
Many times when dealing with APIs or microservices we need to save cookies that they send us in response to certain requests, such as authentication or session cookies to validate subsequent requests. This can lead to a tedious process of manually copying the cookies each time a request is sent, and even more tedious if you have to replace these same values if you are testing with multiple instances or users.
The result of this script when run is as follows:
We start with an empty collection.
We send the request, the script runs automatically after receiving the response.
The collection specific to that domain is now inside the Postman cookie collection.
The script not only adds cookies and is able to replace the values if they belong to the same domain, but also adds collections of different domains that do not exist in the cookie jar without having to add additional logic.
This therefore helps streamline a workflow where cookies from one or more domains need to be saved for testing, QA or other purposes.