Example of creating a report resource via REST V2

1

I am trying to deploy a JRXML from my computer to a Jasper Server using REST V2.  Does anyone have a POST example that creates a report unit resource and at the same time upload a specified file to the server?

chirag_1's picture
Joined: Jan 7 2014 - 4:41am
Last seen: 4 years 10 months ago

1 Answer:

1

The easyest way to create Report Unit witn JRXML file in one request follows:

POST

Content-Type: application.repository.reportUnit+json

{

      "label": "Sample",

     "jrxml": {
       "jrxmlFile":{
         "label": "MyJRXML",
          // encode your file in Base64 and put here
         "content": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPCEtLSBDcmVhdGVkIHdpdGggSmFzcGVyc29mdCBTdHVkaW8gdmVyc2lvbiA1LjUuMC0tPgo8amFzcGVyUmVwb3J0IHhtbG5zPSJodHRwOi8vamFzcGVycmVwb3J0cy5zb3VyY2Vmb3JnZS5uZXQvamFzcGVycmVwb3J0cyIgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZSIgeHNpOnNjaGVtYUxvY2F0aW9uPSJodHRwOi8vamFzcGVycmVwb3J0cy5zb3VyY2Vmb3JnZS5uZXQvamFzcGVycmVwb3J0cyBodHRwOi8vamFzcGVycmVwb3J0cy5zb3VyY2Vmb3JnZS5uZXQveHNkL2phc3BlcnJlcG9ydC54c2QiIG5hbWU9IkJsYW5rX0E0IiBsYW5ndWFnZT0iZ3Jvb3Z5IiBwYWdlV2lkdGg9IjU5NSIgcGFnZUhlaWdodD0iODQyIiBjb2x1bW5XaWR0aD0iNTU1IiBsZWZ0TWFyZ2luPSIyMCIgcmlnaHRNYXJnaW49IjIwIiB0b3BNYXJnaW49IjIwIiBib3R0b21NYXJnaW49IjIwIiByZXNvdXJjZUJ1bmRsZT0icm8vY2hpY3UvYnVuZCIgdXVpZD0iNzc2ODE1OWYtMDJlNS00NTc0LWFhZjQtYzk1MDg3ODhkNTJjIj4KCTxwcm9wZXJ0eSBuYW1lPSJjb20uam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GJhY2tncm91bmQ+CgkJPGJhbmQgc3BsaXRUeXBlPSJTdHJldGNoIi8+Cgk8L2JhY2tncm91bmQ+Cgk8dGl0bGU+CgkJPGJhbmQgaGVpZ2h0PSI3OSIgc3BsaXRUeXBlPSJTdHJldGNoIi8+Cgk8L3RpdGxlPgoJPHBhZ2VIZWFkZXI+CgkJPGJhbmQgaGVpZ2h0PSI4NiIgc3BsaXRUeXBlPSJTdHJldGNoIi8+Cgk8L3BhZ2VIZWFkZXI+Cgk8Y29sdW1uSGVhZGVyPgoJCTxiYW5kIGhlaWdodD0iNjEiIHNwbGl0VHlwZT0iU3RyZXRjaCIvPgoJPC9jb2x1bW5IZWFkZXI+Cgk8ZGV0YWlsPgoJCTxiYW5kIGhlaWdodD0iMTI1IiBzcGxpdFR5cGU9IlN0cmV0Y2giLz4KCTwvZGV0YWlsPgoJPGNvbHVtbkZvb3Rlcj4KCQk8YmFuZCBoZWlnaHQ9IjQ1IiBzcGxpdFR5cGU9IlN0cmV0Y2giLz4KCTwvY29sdW1uRm9vdGVyPgoJPHBhZ2VGb290ZXI+CgkJPGJhbmQgaGVpZ2h0PSI1NCIgc3BsaXRUeXBlPSJTdHJldGNoIi8+Cgk8L3BhZ2VGb290ZXI+Cgk8c3VtbWFyeT4KCQk8YmFuZCBoZWlnaHQ9IjQyIiBzcGxpdFR5cGU9IlN0cmV0Y2giLz4KCTwvc3VtbWFyeT4KPC9qYXNwZXJSZXBvcnQ+Cg==",
         "type":"jrxml"
      }
   }
}

 

ztomchenco's picture
Joined: Sep 27 2011 - 3:55am
Last seen: 5 years 5 months ago

Thanks for that, I probably would never have found that as I could not find the jrxmlFile in the Web API documentation.

For anyone trying to do this in XML it would be the following
POST
URL: http://host:port/jasperserver/rest_v2/resources/pathToWhereTheReportIsGo...
Content-Type: application/repository.reportUnit+xml

<reportUnit>
<label>Sample</label>
<jrxmlFile>
<label>Sample</label>
<type>jrxml</type>
<content>Base64EncodedStringOfJRXMLFile</content>
</jrxmlFile>
</reportUnit>

chirag_1 - 5 years 5 months ago

These examples are not working for me: I keep getting 404 Not Found Jasper page with the "Specified page not found" message on it. Nevertheless, the REST itself is working OK (e.g., http://host:port/jasperserver/rest_v2/serverInfo returns proper server information).

What can be the reason of it?

P.S.

<serverInfo>
<build>20130501_0456</build>
<dateFormatPattern>yyyy-MM-dd</dateFormatPattern>
<datetimeFormatPattern>yyyy-MM-dd HH:mm:ss</datetimeFormatPattern>
<edition>PRO</edition>
<editionName>Professional</editionName>
<expiration>2019-10-30 03:59:00</expiration>
<features>Fusion AHD EXP DB</features>
<licenseType>Commercial</licenseType>
<version>5.1.0</version>
</serverInfo>

b2445554 - 4 years 8 months ago

Answer: I've re-checked this on Jasper v5.5.0, works fine.

b2445554 - 4 years 8 months ago
Feedback
randomness