Is there a way to store a newly-created password in a variable, especially if that password is not returned as part of the response body?
I am quite new to working with variables in Postman. Am currently working with a test API where I create a new user (having “name”, “email”, and “password” as the request body), and then after I log in with the credentials I have created above (that is, “email” and “password”).
Under the pre-request script, I create a random name, a random email and a random password and assign these to respective variables like so:
So this is what my request body looks like:
And this is what my response body looks like:
Now, I want to get the random password that is created (but not displayed in the response body) and store it in a variable such that I can pick it up later and use it while logging in the same newly-created user.
When I attempt to log in with the newly-created random email and password like this:
{
"email":"{{email}}",
"password":"{{password}}"
}
, I get a Bad Request error code (400) and my response body looks like this:
{
"Message": "The request is invalid.",
"ModelState": {
"log.password": [
"An error has occurred.",
"An error has occurred."
]
}
}
yet I intend to log in as the new user (Response code should be 200 and the user details should be displayed).
I have tried to look around online for such a solution but I seem not to find an appropriate answer. Any help is highly welcome and greatly appreciated.