I am getting 401 unauthorized error message, is this a config issue?



  • I am using express framework with request package. When I sent post request with json data to my template on jsreportonline.net, I am getting 401 unauthorized error message. Can you tell if I miss anything in my code? below is my code snippet:

    const order = await findOrderById(id);
    const requestData = { template: { "shortid": "9reQ3QE" }, "data": order };
    const options = {
        uri: "https://binshu.jsreportonline.net/api/report",
        method: "POST",
        json: requestData
    }
    request(options).pipe(res);
    

    Thank you for your help!


  • administrators

    hi! it looks like you are not passing authentication options in the request, you need authentication credentials to be able to use jsreportonline, so you can update your options to something like this:

    const options = {
        uri: "https://binshu.jsreportonline.net/api/report",
        method: "POST",
        auth: {
          username: '<your username or email here>',
          password: '<your password here>'
        },
        json: requestData
    }
    


  • Thank you very much for the help. FYI, it only works if I use my email as my username property value. But it doesn't work if I use my jsreportonline user name as the property value.



  • It should work also with user you created in jsreportonline.
    You just need to make sure you have permissions to all the entities that you use in your render operation.
    Are you able to login and render that particular 9reQ3QE template?


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.