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);
});
This app requires a two-step login, first to get verify domain, which gives you token to do proper username/password login. Then you get your main token for any further request on gated content.
This is my postman setup:
Pre-script
Main Request
[Headers Tab]
Authorization: Bearer {{domain_token}}
Note: {domain_token} was set by pre-script
[Body tab]
{
"email": "email",
"password": "password"
}
Post-script (Tests)
let {data: {token}} = JSON.parse(responseBody);
pm.environment.set("access_token",token);
From this point any request can make use of the {access_token} from the environment.
I want to improve it with refresh token so that my login persists for as long as refresh allows. Suggestions are welcome.