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 everyone!
I would like to know if there is a solution to my problem, let me explain it:
I am using the pm.sendRequest and I would like to send params that are stored in an array called ids. But I did not find throughout the web how to accomplish that. I tried another way and it is working but not as desired, have a look:
As you could see, I am looping through each ID and sending a DELETE request. But I can send multiple params in just one request, like
...course.course?0=id1&1=id2&...
. For this, I can use the following code in one request:Question
How can I move the following block to the first example to make just one DELETE request? I mean, I want to use an alternative to
pm.request.url.addQueryParams()
to thepm.sendRequest()
within it.By the way, the array structure is simple: [1, 2, 3, ...], the index is autogenerated by the loop.