Can not modify report unit on jasper server via Rest API

0

I want to modify a resource via api, The url like this :

http://<host>:<port>/jasperserver[-pro]/rest_v2/resources/path/to/resource

 and the method is PUT  and the request body

{
    "version" : 0,
    "patch":[
        {
        "field":"label",
        "value":"EEEEE"
        }
        ]
}

the response was shown like this

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><errorDescriptor><errorCode>not.a.file</errorCode><message>Resource /reports/cgd_eva/test_60_1 is not a file</message><parameters><parameter>/reports/cgd_eva/test_60_1</parameter></parameters></errorDescriptor>

What's wrong with this? or a report unit can not be modified.

Thanks.

 

paprajak's picture
Joined: Mar 5 2018 - 7:29pm
Last seen: 7 months 1 day ago

1 Answer:

0

There could be multi causes but possibly the specific error points to the content-type specified. The body should have the <reportUnit> in the resource descriptor. 

Here is a working example where I tried to modify the label of the existing report unit :

URL: http://<server>:8080/jasperserver-pro/rest_v2/resources/public/Reports/CustomerReport 

METHOD: PUT

Content-Type: application/repository.reportUnit+xml

BODY:

<reportUnit>
    <creationDate>2014-08-06T14:59:48</creationDate>
    <label>CustomerReport2</label>
    <permissionMask>1</permissionMask>
    <updateDate>2013-11-11T07:49:23</updateDate>
    <uri>/public/Reports/CustomerReport2</uri>
    <version>4</version>
    <dataSourceReference>
        <uri>/organizations/organization_1/datasources/JDBCFoodmartPostgres</uri>
    </dataSourceReference>
    <alwaysPromptControls>true</alwaysPromptControls>
    <controlsLayout>4</controlsLayout>
    <jrxmlFileReference>
        <uri>/public/Reports/CustomerReport_files/main_jrxml</uri>
    </jrxmlFileReference>
</reportUnit>

If your aim is to simply update specific elements only using 'patch' method, that didn't work for me either nor is this in the REST API guides. Its best to download the existing report resource descriptor, make the change and use the PUT method with content-type as "application/repository.reportUnit+xml" (or application/repository.reportUnit+json if  you prefer json format)   

For something like this, you need to fiddle around with the resource descriptors a bit to get it right..so a few attempts may be required.

vchiem's picture
4291
Joined: May 1 2017 - 5:33pm
Last seen: 5 hours 36 min ago
Feedback