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);
});
I had similar problem. I have noticed that 0Auth2 using client_credentials worked for a single request, but I couldn't make it work on Collection level. What I have noticed is that on request level it was using 'Content-Type': 'application/x-www-form-urlencoded'.
I have made it work like this:
The authorization is sth like: Basic c2VydmljZSlongstringTJBMjBSano4WQ== . I've got from console after generating single auth request first with clientSecret.
I'm then using {{accessToken}} template for the Collection's Access Token and "Inherit auth from parent" on request level