In NodeJS using Unirest http library i am automating the Rest Apis. Currently i am stuck on how to pass the query parameters with rest url.
i have tried following solutions but non is working: solution 1
unirest('GET', 'https://my-domain.com/Api/learner/courses')
.header({
"content-type": "application/json",
"authorization": token
})
.queryString("pageNumber", "1")
.queryString("sortDirection", "ASC")
.queryString("status", "all")
.end(function (response) {
response.status.should.be.equal(200);
});
got the following error on above execution:
TypeError: unirest(...).header(...).queryString is not a function
solution 2:
unirest('GET', 'https://my-domain.com/Api/learner/courses{pageNumber}{sortDirection}{status}')
.header({
"content-type": "application/json",
"authorization": token
})
.routeParam("pageNumber", "1")
.routeParam("sortDirection", "ASC")
.routeParam("status", "all")
.end(function (response) {
response.status.should.be.equal(200);
});
got error:
TypeError: unirest(...).header(...).routeParam is not a function
solution 3:
const param = {
pageNumber: 1,
sortDirection: "ASC",
status: "all"}
unirest('GET', 'https://my-domain.com/Api/learner/courses{pageNumber}{sortDirection}{status}') .header({ "content-type": "application/json", "authorization": token }) .send(param) .end(function (response) { response.status.should.be.equal(200); });
got error:
Uncaught Error: Error: got 500 response
Any help would be much appriciated! thanks.