I’ve got pre-requests with 2 pm.sendRequest. One of them depends on variable from first response.
They work with setTimeout.
//I set Timeout because updateInfoRequest needs to wait and get it from h2hRequest response
setTimeout("updateInfo", 3000)
updateInfoBody = {"orderId":pm.collectionvariables.get("orderId")}
updateInfoRequest = {
there is connection info
body:JSON.stringify(updateInfoBody)
}
pm.sendRequest(h2hRequest, function(error, h2hResponse){
pm.collectionvariables.set(h2hResponse.json().orderId
})
function updateInfo(){
pm.sendRequest(updateInfoRequest, function(error, updateInfoResponse){
})
}
h2hRequest works. It takes orderId.
It doesn’t put in orderId variable after the first call. But I see the value in collection variables.
If run it again - orderId is in variable. But it is the last orderId not new.
I use only Request Tab, not flow or anything else.
How to make pre-request get new orderId every time?
clear or unset commands doesn’t help.
Local pre-request variable answers ReferenceError.
Postman for Windows version 10.10.9. Works without internet connection. I can’t update version following company policy
The sendRequest() function is asynchronous in nature, which means the functions don’t wait for the response before continuing to execute the rest of your code. Which also means you cannot guarantee the order that the two sendRequest() will execute or that request A) has completed before you run request B).
Look up asynchronous requests in the forum.
You should see several topics and examples on how to ensure that the requests run in the correct order.
For Postman 10.10.9 I found the solution. setTimeout for updateInfo function updateInfo(){ pm.sendRequest({Put all request info in here}, function(error, updateInfoResponse){ })}
The orderId isn’t updated if I declare updateInfoRequest not in timeout sendRequest.
setNextRequest doesn’t work in my old Postman.