Using the Koha REST API

From Koha Wiki

Jump to: navigation, search
Home > Documentation

Koha has an old, RESTish API, referred to as SVC. A new REST API is being added from scratch, and this page aims to inform non-Koha developers about how to develop against this new API.

Contents

Documentation

The REST API is self documenting, so you can view documentation describing the actual version you will be working with at the following URL:

https://example.com/api/v1/.html

Here is a live example, from a demo installation:

https://demo.bibkat.no/api/v1/.html

Authentication

OAuth

Can be enabled with the RESTOAuth2ClientCredentials syspref.

Basic auth

Can be enabled with the RESTBasicAuth syspref. Uses the username and password of a patron/borrower registered in Koha.

Simple example in Perl

This will fetch a list of libraries from the Koha instance:

 use Modern::Perl;
 use LWP::UserAgent;
 use HTTP::Request::Common;
 
 my $domain   = 'example.com';
 my $username = 'foo';
 my $password = 'bar';
 
 my $ua = LWP::UserAgent->new();
 my $request = GET "https://$domain/api/v1/libraries";
 
 $request->authorization_basic( $username, $password );
 
 my $response = $ua->request($request);
 say $response->as_string();

Versions

Added in Bug 22132, and part of Koha from the following versions:

  • 19.05.00
  • 18.11.03

Plugins

The REST API can be extended through Koha plugins. See the Kitchen sink example plugin from ByWater for an example.

Examples

See also

Personal tools