Anuj K.C.
Anuj K.C.

Reputation: 488

calling jasper report rest api through node js

I am very much new to the concept of jasper report. My team had already build some reports in jasperserver. the only thing I needed is to call reports. From a node server. I tried code from Jasper Rest API, run a report

 router.get('/', function(req, res, next) {

    request.post({url: "http://localhost:3030/jasperserver/rest/login", 
        qs: {j_username: "jasperadmin", j_password: "jasperadmin"}},
        function(err, res, body) {
            if(err) {
                return console.error(err);
            }
            else{
            request.get("http://localhost:3030/jasperserver/rest_v2/reports/SampleQueryReport.pdf",
                function (error, response, body1) {

                    if (!error) {
                          console.log("downloading")
                    }
                    else{
                        console.log(response.statusCode);
                        console.log(error);
                    }
            })
        }
    });


});

I want to get the report in pdf format. But when I tried this code am getting 401 unauthorized error. I am using express js,node js, npm module request, which I globally declared in app.js. But I can log to the jasper soft directly with this credentials through url.

Upvotes: 0

Views: 3484

Answers (1)

Anuj K.C.
Anuj K.C.

Reputation: 488

I understood what the problem was. It shows unauthorized error because in the second request it has no cookie. That is in the first request login take place and a cookie is generated. Which is not passed in the second request. So when I passed cookie with that request it worked. My mistake.

Upvotes: 2

Related Questions