Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need Example of passing Jasper Reports Parameters for REST v2 API using JSON

When I look at the documentation for passing parameters to the Jasper Report REST 2 API here: http://community.jaspersoft.com/documentation/jasperreports-server-web-services-guide/v550/running-report-asynchronously I see that I need to have a "parameters" dict. The example in the link shows the XML which is not all that useful since it's unclear exactly what the equivalent JSON should look like. The closest I could find is in this link: http://community.jaspersoft.com/documentation/jasperreports-server-web-services-guide/v56/modifying-report-parameters. Now, I am sending the equivalent of that to the server (and every other permutation I can think of), and I continue to get a "400 Client Error: Bad Request" back. I could really use an exact example of the python code to generate the required "parameters" parameter for say "my_parameter_1="test_value_1".

Here is my current POST data (with a few params missing for brevity). I know this is correct since the report works fine if I omit the "parameters" parameter:

    {
      'outputFormat': 'pdf', 
      'parameters': [{'name': 'ReportID', 'value': ['my_value_1']}], 
      'async': 'true', 
      'pages': '', 
      'interactive': 'false'
    }
like image 243
staggart Avatar asked Dec 15 '22 20:12

staggart


1 Answers

Nice Job there Staggart. I got it now. Because I wasn't reading with max. scrutinity, I wasted some additional time. So the interested coder is not only advised to be aware of the nested, syntactictally interesting reportParameter-property, but especially that the value-property inside that is an array. I suppose one could pass some form of Lists/Arrays/Collections here?

What irritated me was, if I should construct more than one "reportParameter" property, but that would be nonsense according to Does JSON syntax allow duplicate keys in an object.

So just for the record, how to post multiple parameters:

{
    "reportUnitUri": "/reports/Top10/Top10Customers",
    "async": true,
    "freshData": true,
    "saveDataSnapshot": false,
    "outputFormat": "pdf",
    "interactive": false,
    "ignorePagination": true,
    "parameters": {
        "reportParameter": [
            {
                "name": "DATE_START_STRING",
                "value": ["14.07.2014"]
            },
            {
                "name": "DATE_END_STRING",
                "value": ["14.10.2014"]
            }
        ]
    }
}

If someone accidently is struggling with communicating with jasper via REST and PHP. Do yourself a favour and use the Requests for PHP instead of pure CURL. It even has a fallback for internally using Sockets instead of CURL, when latter isn't available.

Upvote for you Staggart.

like image 166
JackLeEmmerdeur Avatar answered Apr 07 '23 12:04

JackLeEmmerdeur