Can someone tell me how to do it please. Using KOHA REST API to get patron's checked-out book name.
I'm unable to fetch the book's name, I am able to fetch the other patron details but not the book name.
I tried following KOHA's API guide but its confusing, please help me out.
Expecting: TO get book's name which patron has checked out
First: accessing the Koha API. I know you can do a lot of this because you were able to get other patron details, but I felt it worthwhile to cover some basics.
We will need non-public API routes for this. That means you need to be logged in. For actual scripts you'll need to use either basic authentication or OAuth2 authentication. Both require permissions to be enabled within Koha and a certain level of common API knowledge. For testing, we'll only need GET operations for this so you can login to Koha via your browser normally and just run requests via the browser address bar.
To send a GET operation to the Koha API, first you need the address of your Koha user catalog site (ie:
https://mykohalibrary.example.com). Then we add/api/v1/to indicate we are using the API. So every request will start with:(Where "mymykohalibrary.example.com" is the address for your specific Koha installation). Then we append the information for the specific route.
Now we know that much, we can talk about what is needed to accomplish the goal of listing checkout information.
First up, we'll need to know the
patron_idto see what their checkouts are. If you only have a card number or username, you may need to first ask Koha to tell you the patron_id matches that input. So we'll use the patrons route, which looks like this:To briefly continue the previous part of the discussion, that means you could put something like the following into the address bar:
Remember: you need to be logged into Koha to see a valid result, but if you do it right you will get a JSON array back with one item, where the contents look something like this (with less whitespace):
If you have a username instead of a card number, you would make a similar request and get the same result:
We can see the cardnumber or userid in the result data will match what was provided, and now we have a
patron_idwe can use with the next step.Now we need to use the
/checkoutsroute.From the prior step we found a patron_id of
123, so we can use that with the new address to get this:Be careful with this route!
In my experience, if the targeted patron has no checkouts Koha may then return current checkouts for ALL patrons. Therefore you will need to validate each returned item still matches the desired patron_id.
We should now have a JSON array with items looking something like this:
Again: validate the patron_id field and only keep items where it really is correct. However, what you will NOT find here is the name of the book. All we have is an
item_id... so we'll need to do another request (for each item!):which using the
5423value found in the previous example will look like this:And now we see results that look like this:
No array this time, but (sigh) still no title, either. One more round to the biblios route:
Which using the value seen above would look like this:
And now it gets tricky again. The exact result you see depends on the
Acceptheader provided and the default marc format used by the library. But whatever you see, if you send a valid request the title will be in the response somewhere in a way you can parse out.It's also worth nothing there are public versions of the
itemsandbilbiosroutes, but since we had to authenticate to do the first steps we may as well stick to the authenticated options.