Jump to content

How to pass access token in a request from Jasper report server to JSON data API after sending a login request

Go to solution Solved by A3an,

Recommended Posts

I am trying to create reports where data is coming from JSON API.

I am having a JSON API server in the following format:

  1. A login request is sent to the server including username and password
  2. After authentication, an access token is sent back as a response.
  3. This token is then sent with data requests in the headers.
  4. 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

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

  • Solution

Hi jamshaidiqbal120

I 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

  • 1 year later...
  • 1 year later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...