Can I use pm.sendRequest() to send requests synchronously?

The pm.sendRequests are asynchronous in nature.

In the following snippet,

pm.sendRequest(req1, done);
pm.sendRequest(req2, done);

both req1 and req2 are sent out immediately without waiting for them to complete. In order to make req2 wait for req1 you have to nest pm.sendRequest(req2) inside the callback of req1. It will be something like,

pm.sendRequest(req1, function () {
  pm.sendRequest(req2, done);
});

Although this solves your problem, it can get unreadable and complex over time. Iā€™m interested in finding alternatives to solve this. Have you tried seeting the three requests in order in a collection and running them?

6 Likes