# Need to give explicit wait between two pm.sendrequest() to make executable sequential

**URL:** <https://community.postman.com/t/need-to-give-explicit-wait-between-two-pm-sendrequest-to-make-executable-sequential/6029>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [June 21, 2019, 5:57am UTC](https://community.postman.com/t/need-to-give-explicit-wait-between-two-pm-sendrequest-to-make-executable-sequential/6029 "2019-06-21T05:57:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lalith\_Vignesh](https://avatars.discourse-cdn.com/v4/letter/l/ecae2f/32.png) [@Lalith\_Vignesh](https://community.postman.com/u/Lalith_Vignesh)\
**Post date:** [June 21, 2019, 5:57am UTC](https://community.postman.com/t/need-to-give-explicit-wait-between-two-pm-sendrequest-to-make-executable-sequential/6029/1 "2019-06-21T05:57:01Z")

</div>

Hi  
I am using pm. sendRequest() inside two test functions.

**Working Snippet**

transferinsufficientbalance()  
function transferinsufficientbalance() {  
const expression =  
pm.globals.get(“idempotent”);  
eval(expression);  
const req = {  
url: pm.environment.get(“url”) + '/_**/v1/’,  
method: ‘POST’,  
header: {‘psmUserID’:'**__’  
},  
body: {  
mode: ‘raw’,  
raw: JSON.stringify({ “from”:{“psmUserID”: " **", “useDefault”:true ,“network”:“stellar”},“to”:{“psmUserID”:"** _",“useDefault”:true,“network”:“stellar”},“size”:“100000”,“assetID”:"\*\*\*\*\*",“idempotentID”:pm.globals.get(“idempotentID”)})  
}  
};  
pm.sendRequest(req, function (err, res) {  
console.log(err ? err : res.json());  
pm.test(“Validate whether sender doesnt have enough balance”, function () {

```
    if (res.code == 200) {

      pm.expect(res.json().status.type).to.eql("failed");
        pm.expect(res.json().status.errorCode).to.eql(1007);
        pm.expect(res.json().status.errorMessage).to.eql("The sender doesn't have enough balance");
             }
    else {
        pm.expect(res).to.have.property('code', 200);
         }
    
    });
});

```

}  
// 3.To Validate whether account is present for the given psmUserID  
accountpresentinuserid()  
function accountpresentinuserid() {  
const expression =  
pm.globals.get(“idempotent”);  
eval(expression);  
const req = {  
url: pm.environment.get(“url”) + '/_ **/v1/** __’,  
method: ‘POST’,  
header: {‘psmUserID’:'__**’  
},  
body: {  
mode: ‘raw’,  
raw: JSON.stringify({ “from”:{“psmUserID”: "", “useDefault”:false,“accountID”:“123” ,“network”:“stellar”},“to”:{“psmUserID”:"",“useDefault”:false,“accountID”:“000”,“network”:“stellar”},“size”:“1”,“assetID”:"**_\*\*",“idempotentID”:pm.globals.get(“idempotentID”)})

```
    }
};
pm.sendRequest(req, function (err, res) {
    console.log(err ? err : res.json()); 
 pm.test("Validate whether account is present for the given psmUserID", function () {
    if (res.code == 422) {
     console.log(res.json());
      pm.expect(res.json().errorCode).to.eql(1010);
        pm.expect(res.json().errorMessage).to.eql("Sender's blockchain account not found");
             }
    else {
        pm.expect(res).to.have.property('code', 422);
         }
    
    }
});

```

}

Now i am facing the issue of pm.sendRequest() not running in one after other.  
Can i know how to give explicit wait time inbetween the request

---

<div class="post-metadata">

**Author:** ![VincentD123](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vincentd123/32/1845_2.png) [@VincentD123](https://community.postman.com/u/VincentD123)\
**Post date:** [June 25, 2019, 10:17am UTC](https://community.postman.com/t/need-to-give-explicit-wait-between-two-pm-sendrequest-to-make-executable-sequential/6029/2 "2019-06-25T10:17:37Z")

</div>

HI @Lalith_Vignesh,  
Not really clear what you’re trying to do there, the formatting looks a bit odd.  
But in any case, the `pm.sendRequest()` method is asynchronous, so if you need the requests to be called one after the other (ie. synchronously), you can either set them up as proper requests in your collection, or you if you really want to use `pm.sendRequest()` you need to perform the second one inside the callback function of the first one.  
eg.

```auto
let req1 = {...};
let req2 = {...}; // optionally define req2 before calling req1
pm.sendRequest(req1, function (err1, res1) {
   .... 
   let req2 = {...}; // or // optionally define req2 after receiving response to req1
   pm.sendRequest(req2, function (err2, res2) {
      .... 
   });
   .... 
});

```

---

<div class="post-metadata">

**Author:** ![Lalith\_Vignesh](https://avatars.discourse-cdn.com/v4/letter/l/ecae2f/32.png) [@Lalith\_Vignesh](https://community.postman.com/u/Lalith_Vignesh)\
**Post date:** [June 25, 2019, 10:32am UTC](https://community.postman.com/t/need-to-give-explicit-wait-between-two-pm-sendrequest-to-make-executable-sequential/6029/3 "2019-06-25T10:32:41Z")

</div>

Thanks for the update.But need to know how do we perform same request with different test data if we call the function inside the function.  
Ex  
Three sets of test data for the same post request.if i use three sendrequest inside a single function as per your suggestion.Please let me know how and which testdata will be accessed.

---

<div class="post-metadata">

**Author:** ![VincentD123](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vincentd123/32/1845_2.png) [@VincentD123](https://community.postman.com/u/VincentD123)\
**Post date:** [June 25, 2019, 6:28pm UTC](https://community.postman.com/t/need-to-give-explicit-wait-between-two-pm-sendrequest-to-make-executable-sequential/6029/4 "2019-06-25T18:28:29Z")

</div>

no worries, the two requests share the same variable scope, so you can define req1 and req2 at any place in the code before they are used. I have added it to the example code. Just try it out and see how you go with it.
