Hi,
One of my requirement is to call an async login API as a pre-request script in Postman windows client. Through this code I want to set the collection variable (jwt-token). The problem is that Postman doesn’t wait for the completion of the pre-request call and hence the actual request is throwing an error of ‘Un-authorized access’.
Below is the code:
(async ()=>{
const loginRequest = {
method: ‘POST’,
url: pm.collectionVariables.get(“loginUrl”),
header: {
‘Content-Type’: ‘application/json’
},
body:{
mode:‘raw’,
raw: JSON.stringify({ email: “”, password: “”})
}
}
await pm.sendRequest(loginRequest,(error, response)=>{
pm.collectionVariables.set(“jwt-token”, response.token)
})
})()