I want to use pm.sendrequest within a calling function and return the response

I want to use pm.sendrequest within a calling function and return the response
Can I do this?

Context:
I get a list of entries, with another request hanging off entries that meet certain criteria.
Then I want to get the second request, and return the body of that for more tests, depending on certain criteria.

So I get first call for list,
parse list of entries in response - If object meets criteria use a field in it to make second call,
try second call (pm.sendRequest), and return the body for the tests I really want to do.

Can I use pm.sendRequest and return the response body to a routine that runs tests? The way I see it at the moment pm.sendRequest doesn’t allow .

also, I am using pm.sendRequest several times in a separate function to call requests in turn, but I am only getting back the original request content.

It looks like I am failing to initialise the function after first use - so help with this would be good too…

ok problem solved.
As usual with some reading…

  • the same “result” doesn’t return: pm.sendrequest is asynchronous so the “result” is from the original get

  • Looping through tests with postman.setNextRequest(“requestname”) works fine when running the collection - a good example is here through this link - thanks @cantrobot

1 Like