Jump to content

How to install jrs-rest-php client?

Recommended Posts


I have reports set up with iReport on our jaspersoft server. I have the server info and such to log in. I want to create a php web page that displays all information about scheduled reports on our jaspersoft server so we can keep track of it internally.

I have downloaded https://github.com/Jaspersoft/jrs-rest-php-client and read the documents. I have watched the tech talk video and I sitll am having trouble. I placed the folder in our local FTP sandbox for testing and create a test.php page. This is what I have on the page:

require_once "autoload.dist.php";
header('Content-Type: text/html');
use JaspersoftClientClient;
$c = new Client(
$report = $c->reportService()->runReport('/reports/MyReport', 'html');
echo $report;  
When I navigate to it, this is the error that I am getting:
Fatal error: Class 'JaspersoftClientClient' not found in /home/content/90/11012290/html/analytics/test.php on line 8
Can someone advise me on what I did wrong? Thank you
Link to comment
Share on other sites

  • Replies 10
  • Created
  • Last Reply

Top Posters In This Topic

If you are using the most recent version of jrs-rest-php-client, the constructor has changed. However, it seems that the autoloader is not being loaded properly... it could be an OS-specific issue. There are a few ways you could solve this: 1) in autoload.dist.php you can replace the line:

 $location = JASPERCLIENT_ROOT . $class . '.php'; [/code]

with the following:

 $location = JASPERCLIENT_ROOT . str_replace('\', '/', $class) . '.php'; [/code]

2) or you could use Composer and have it generate an autoloader for you, and use that autoloader (recommended)


Then you would want to modify your client constructor to use a URL as the first parameter

<?phprequire_once("autoload.dist.php");use JaspersoftClientClient;$client = new Client("http://localhost:8080/jasperserver-pro", "username", "password", "organization_name"); [/code]


Link to comment
Share on other sites

Dear god, when I saw this reply and I saw that I left the info up, I sprinted up a few floors to fix this immediately. Thank you very much for the heads up, I remembered to tell myself to change that when writing the question and just messed up.


Regarding the composer, if the jaspersoft server and database is not sitting locally, will it still work?

Link to comment
Share on other sites

Thanks Grant,


Modifying the autload.dist.php seems to have done the trick. It has moved past that line and I'm getting a new error:


Fatal error: Call to a member function reportService() on a non-object in /home/content/90/11012290/html/analytics/test.php on line 10

 I've looked up this error it seems like perhaps it's having trouble finding the reportService class? I placed this php file on the same level as the autoload.dist.php so I'm not sure if I need to relocate it to somewhere else.


Additionally, I've installed postman on Chrome to test out the API calls prior to this project. For me to see all my scheduled reports, the URL is analy*********.com/an*******s2/rest_v2/jobs


Should I replace that with /reports/MyReport in $report? I just noticed that this test page to display reports in HTML is actually an example you gave to another user! Neat!


Thanks for your help!

Link to comment
Share on other sites

The URI you provide to runReport should match the URI within the JasperReports Server. You can get this URI by right clicking on a report in the repository and selecting "Properties.."

The error you show seems like your $c may not have been instantiated properly. You can try using var_dump to ensure that it has created an object properly, and additionally you can try to var_dump the contents of $c->serverInfo() to ensure the connection is being properly made to your JRS instance


Additionally, you won't want to change any of the underlying directory structures as the autoloader attempts to load classes as they are needed based on their expected locations within your filesystem

Link to comment
Share on other sites

Hi Grant, Again, thank you very much for your help. I really do appreciate it. I still have that same error:


Fatal error: Call to a member function serverInfo() on a non-object in /home/content/90/11012290/html/analytics/test.php on line 10


This time, I decided to see if I can grab the server info and do a var_dump from that and it didn't work. This was my code $c-> serverInfo(); var_dump($c); ?> Tomorrow I will try to use the composer because I actually edited the autoloader file instead of using the composer.


If that doesn't work, maybe my credentials are wrong. I log into the system everyday but perhaps I can test some stuff with a GET login credential (http://:/jasperserver[-pro]/rest/login?j_username=[%7C] &j_password=)

Link to comment
Share on other sites

  • 2 months later...

I don't know if this is going to help you or not but I found it far easier to bypass the autoload and specifically load the classes I need. The idea behind the autoload is really nice (really, really nice) but I was having way too many issues - all of which went away once I started to explicitly load the classes.

Link to comment
Share on other sites

  • 1 year later...
  • 5 years 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...