Exposing Koha SQL Reports to External Services

By

Reports in Koha can be exposed to the public and utilized in a manner similar to how REST API endpoints are utilized.

Using JSON Reports Service, Saved reports in koha can be made public and utilized in external services by setting Report is public to true.

The following SQL report is used to query the number of circulation transactions in a given date range per branch.

SELECT type AS transaction_type, COUNT(datetime) AS transaction_count 
FROM statistics 
WHERE type IN ('issue', 'return', 'renew')
AND branch=<<Campus|branches>>
AND DATE(datetime) BETWEEN <<From|date>> AND <<To|date>>
GROUP BY transaction_type 
ORDER BY transaction_count DESC

Assume the report has been made public and it has the report ID 389. The report receives 3 parameters when executed as shown in the image

To run the same report using the JSON Report Service in koha, the reportId and the 3 parameters must be provided as query parameters in the URL with id as the first parameter followed by all the other parameters using sql_params as the keyword in the order they appear in the SQL code. See the examples below.

https://opac.example.ac.ke/cgi-bin/koha/svc/report?id=389&sql_params=LIB12&sql_params=2025-01-01&sql_params=2025-03-01

About The Author

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

×

Hello!

Select one of our contacts below to chat on WhatsApp

× How can I help you?