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

**URL:** <https://community.postman.com/t/can-i-use-pm-sendrequest-to-send-requests-synchronously/225>\
**Category:** Help Hub\
**Created:** [November 14, 2017, 3:12pm UTC](https://community.postman.com/t/can-i-use-pm-sendrequest-to-send-requests-synchronously/225 "2017-11-14T15:12:11Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![zhyzhko](https://avatars.discourse-cdn.com/v4/letter/z/54ee81/32.png) [@zhyzhko](https://community.postman.com/u/zhyzhko)\
**Post date:** [December 23, 2020, 3:24pm UTC](https://community.postman.com/t/can-i-use-pm-sendrequest-to-send-requests-synchronously/225/21 "2020-12-23T15:24:56Z")

</div>

it helped, thank you!  
just created the function as in your comment and call it within 1st pm.sendRequest

---

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [May 31, 2021, 9:55pm UTC](https://community.postman.com/t/can-i-use-pm-sendrequest-to-send-requests-synchronously/225/22 "2021-05-31T21:55:11Z")

</div>

I think this post could resolve this issue: [Async Operations!](https://community.postman.com/t/async-operations/24314)

---

<div class="post-metadata">

**Author:** ![hoffdacosta](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@hoffdacosta](https://community.postman.com/u/hoffdacosta)\
**Post date:** [August 22, 2022, 3:19pm UTC](https://community.postman.com/t/can-i-use-pm-sendrequest-to-send-requests-synchronously/225/23 "2022-08-22T15:19:06Z")

</div>

Sorry, but did not solve. For example:

```auto
/* Common Decrypt Function */
postman.setEnvironmentVariable("utils", () => {
    var decryptRequest = () => {
        var response = JSON.parse(responseBody);

        pm.test("Encrypted response is not empty", function () {
            pm.expect(response).not.be.empty;
        });

        pm.test("Encrypted parameters copied successfully", () => {
            if (pm.expect(response).to.have.property('key')) {
                pm.collectionVariables.set('key', response.key);
                console.info("[key] " + response.key);
            }

            if (pm.expect(response).to.have.property('payload')) {
                pm.collectionVariables.set('payload', response.payload);
                console.info("[payload] " + response.payload);
            }
        });

        pm.test("Decrypted request executed successfully", () => {
            const decryptRequest = {
            url: pm.environment.get("url-platform") + '/client/decrypt',
            method: 'POST',
            async: false,
            crossDomain: true,
            header: {
                    'content-type': 'application/json',
                    'X-Test': pm.collectionVariables.get("xTest")
                },
            body: {
                    mode: 'raw',
                    raw: JSON.stringify({
                        key: pm.collectionVariables.get("key"),
                        payload: pm.collectionVariables.get("payload")
                    })
                }
            };

            let promisify = function request(options) {
                return new Promise(function(resolve, reject) {
                    pm.sendRequest(options, function (err, response) {
                        if (err) return reject(err);
                        setTimeout(resolve(response), 15);
                    });
                });
            }

            async function decrypt() {
                var res = await promisify(decryptRequest);
                if (pm.expect(res).not.be.empty) {
                    var decrypted = res.json();
                    pm.variables.set('decrypted', JSON.stringify(decrypted));
                    console.info("[decrypted] " + JSON.stringify(decrypted));
                } else {
                    pm.variables.set('decrypted', null);
                }
            }

            decrypt();
        });
    }
    return {
        commonPackage: {
            decryptRequest
        }
    };
});

/* Functional */
let utils = eval(environment.utils)();
utils.commonPackage.decryptRequest();

var result = JSON.parse(pm.variables.get("decrypted"));
console.info("[result] " + JSON.stringify(result));

```

Always return null! It does not run synchronous. Please, any suggestion?

---

<div class="post-metadata">

**Author:** ![vrush.haldankar](https://avatars.discourse-cdn.com/v4/letter/v/b4bc9f/32.png) [@vrush.haldankar](https://community.postman.com/u/vrush.haldankar)\
**Post date:** [October 11, 2022, 10:43am UTC](https://community.postman.com/t/can-i-use-pm-sendrequest-to-send-requests-synchronously/225/24 "2022-10-11T10:43:32Z")

</div>

Thank you … Thank you so much … for this solution , it saved my time, i didn’t even think it off…

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [August 23, 2023, 2:51pm UTC](https://community.postman.com/t/can-i-use-pm-sendrequest-to-send-requests-synchronously/225/25 "2023-08-23T14:51:42Z")

</div>

Closed on August 23, 2023, 2:51pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

[Previous page](https://community.postman.com/t/can-i-use-pm-sendrequest-to-send-requests-synchronously/225.md?page=1)
