To send a request via the sandbox, you can use pm.sendRequest.
pm.test("Status code is 200", function () {
pm.sendRequest('https://postman-echo.com/get', function (err, res) {
pm.expect(err).to.not.be.ok;
pm.expect(res).to.have.property('code', 200);
pm.expect(res).to.have.property('status', 'OK');
});
});
Without additional options, this will sent a GET request to the URL specified. If you prefer to be more explicit, you can use the complete syntax:
pm.sendRequest({
url: 'https://postman-echo.com/post',
method: 'POST',
header: 'headername1:value1',
body: {
mode: 'raw',
raw: JSON.stringify({ key: "this is json" })
}
}, function (err, res) {
console.log(res);
});
Hi,
@jprealini Thank you for the reply. Apologies, I did find what my issue was but I forgot to come and update here.
Basically, I had to surround my pm.sendRequest around a try, catch block.
If it's not surrounded then it was not writing to the console of an issue with the sendRequest.
And about your questions,
My intention is to run a script after a postman request to initialize my env vars which I will subsequently use in other API calls.
But as I said there was an issue with the call and without try/catch there was no information shown in the console.
I really appreciate you replying back and checking! Thank you.