jamshaidiqbal120 Posted September 17, 2020 Share Posted September 17, 2020 I am trying to create reports where data is coming from JSON API.I am having a JSON API server in the following format:A login request is sent to the server including username and passwordAfter authentication, an access token is sent back as a response.This token is then sent with data requests in the headers.After the access token verification, API responds with the requested JSON data.here is a diagram explaining this concept. My Question Is there any way I could achieve this without breaking the sequence by sending the requests from the JasperReport server. I am using version 7 and is in a docker container. I am not much familiar with this kind of stuff from jasperserver. Any suggestions would be really appreciated. Thanks a lot everyone Link to comment Share on other sites More sharing options...
Solution A3an Posted September 18, 2020 Solution Share Posted September 18, 2020 Hi jamshaidiqbal120I had to figure this out like a month ago and this took me days to set up correctly....You need 2 data adapters. The first one is the POST request to get the token, the second one is the GET request where you have to put the token as http header.So once you've set up this correctly, you wil be able to use the token in the GET request. I assume this token is only valid for about 15 minutes.The POST request:Content-Type is very important to add because certain API applications return no result if this is missing.If this works well and you can show the access token on your report we can proceed with the GET Request.The URL Parameters speaks for themselfs. The http headers here below:I don't know the kind of token you have to use but mine was a bearer token.You can also use Postman to simulate this. Hopefully you will get a result. (POST and GET)Now comes the tricky part...The problem with Bearer token is that you only get a token without Bearer in front of it. So you must add "Bearer "+ token as parameter => Note the whitespace in "Bearer "So you create a parameter. Give it a name: token and the value is the token you get from the POST Request.To use the second data adapter to make the GET call, I've used a list element. This list element is the datasource of the GET request.I had tried a sub-report but no luck.I can provide you a working example but the report is on another laptop I don't have with me right now.Let me know if you've got it to work.Greets A3an Link to comment Share on other sites More sharing options...
jamshaidiqbal120 Posted September 19, 2020 Author Share Posted September 19, 2020 @A3an It would be really great help if you upload a working example as you get to your laptop. thanks a lot. Link to comment Share on other sites More sharing options...
A3an Posted September 21, 2020 Share Posted September 21, 2020 Hi jamshaidiqbal120Please see attached pdf.Greets A3an Link to comment Share on other sites More sharing options...
svelxgixoxdbbbqrjv Posted May 20, 2022 Share Posted May 20, 2022 I'm trying to follow this and have it working fine in Studio but I just get "There was an error on the server" when I publish. Totally stuck! Can you help? Thanks! Link to comment Share on other sites More sharing options...
celocia1pc Posted July 6 Share Posted July 6 Hi, is this applicable on the Community Edition? Link to comment Share on other sites More sharing options...
jamshaidiqbal120 Posted July 6 Author Share Posted July 6 @celocia1pc yes. I have been working on this using Community edition Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now