[Koha] Parsing public reports

Alvaro Cornejo cornejo.alvaro at gmail.com
Wed Jul 8 18:09:02 NZST 2020


Hi

I´m trying to parse the results of a report setup as public but are unable
to get the data.
This is the script I'm working on

#!/usr/bin/perl
 use strict;
 use warnings;

 use LWP::UserAgent;
 use HTTP::Request;

 my $ua = new LWP::UserAgent;
 $ua->agent("Perl API Client/1.0");

 my $url = "https://myurl/report?id=53";

 my $request = HTTP::Request->new("GET" => $url);
 my $response = $ua->request($request);
 print "Response::: " . $response . "\n";

 use JSON;
 my $json_obj = JSON->new->utf8->decode($response->content);

 print "JSON OBJ:  " . $json_obj . "\n";
 print $json_obj->{rowCount} . " rows:n";

 foreach my $row(@{$json_obj->{rows}}){
         print $row->{Key} . ":" . $row->{Value} . "n";
 }


My debug print gives me:

Response::: HTTP::Response=HASH(0x564ec7e6cfa8)
JSON OBJ:  ARRAY(0x564ec76dd7f8)
Not a HASH reference at reporte53-2.pl line 23.

Each time I run the script I get different 0X values.

If I call the report through a web browser I get

[["aa",339],["ab",99094],["am",47957],["as",1641],["gm",1],["jm",1]]

And if I add &annotated=1 to my report link I get:

 [{"Registros":339,"Type":"aa"},{"Type":"ab","Registros":99094},{"Registros":47957,"Type":"am"},{"Type":"as","Registros":1641},{"Registros":1,"Type":"gm"},{"Registros":1,"Type":"jm"}]

What am I missing for parsing the report?

Regards,

Alvaro


|----------------------------------------------------------------------------------------|
 Stay safe / Cuídate/  Reste sécurisé
*7* Switch off as you go / Apaga lo que no usas /  Débranchez au fur et à
mesure.
 *q *Recycle always / Recicla siempre / Recyclez toujours
 P Print only if absolutely necessary / Imprime solo si es necesario /
Imprimez seulement si nécessaire


More information about the Koha mailing list