Playing with the Alma APIs
Hoot hoot – the Alma train is coming, so we should jump on and get familiar with the APIs it bring. Our ticket is an API key to Developers Network, and to get it you should send an email to Bibsys (or just ask me if you’re at UBO).
Open up a terminal and store the key in a variable. At the same time, let’s also create a variable to hold the MMS id of a bibliographic record we’re interested in (the MMS id is the identifier that identifies a bibliographic record in Alma):
ALMA_API_KEY="my secret key goes here"
MMS_ID="991400201794702204"
Now, for the first oddity: if you don’t know the MMS id, there’s no search API easily to be found. Alma does support SRU though, so the thinking is probably that you should use SRU for search. I might get back to SRU in a later post.
Let’s see if we can get the holdings belonging to this record. To make the result more readable, we’ll also pipe it through prettyjson:
curl -X GET \ --header "Authorization: apikey ${ALMA_API_KEY}" \ --header "Accept: application/json" \ "https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/${MMS_ID}/holdings" | prettyjson
to get:
holding: - library: value: 1030310 desc: UiO Realfagsbiblioteket location: value: k00475 desc: UREAL Samling 42 link: https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/991400201794702204/holdings/22148809160002204 holding_id: 22148809160002204 call_number: FA 4606 bib_data: title: The science of cheese author: Tunick, Michael H.. issn: null isbn: 9780199922307 publisher: Oxford University Press link: https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/991400201794702204 mms_id: 991400201794702200 place_of_publication: Oxford network_number: - (NO-TrBIB)140020179 - 140020179-47bibsys_network - (EXLNZ-47BIBSYS_NETWORK)991400201794702201 total_record_count: 1
Great! We can get information about the items too:
HOLDING_ID="22148809160002204" curl -X GET \ --header "Authorization: apikey ${ALMA_API_KEY}" \ --header "Accept: application/json" \ "https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/${MMS_ID}/holdings/${HOLDING_ID}/items" | prettyjson
gives us:
item: - link: https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/991400201794702204/holdings/22148809160002204/items/23148809150002204 bib_data: title: The science of cheese author: Tunick, Michael H.. issn: null isbn: 9780199922307 link: https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/991400201794702204 mms_id: 991400201794702200 place_of_publication: Oxford publisher_const: Oxford University Press network_number: - (NO-TrBIB)140020179 - 140020179-47bibsys_network - (EXLNZ-47BIBSYS_NETWORK)991400201794702201 holding_data: link: https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/991400201794702204/holdings/22148809160002204 holding_id: 22148809160002204 call_number_type: value: 8 desc: Other scheme call_number: FA 4606 accession_number: copy_id: in_temp_location: false temp_library: value: null desc: null temp_location: value: null desc: null temp_call_number_type: value: desc: null temp_call_number: temp_policy: value: desc: null item_data: pid: 23148809150002204 barcode: 053225na0 policy: value: desc: null provenance: value: desc: null description: library: value: 1030310 desc: UiO Realfagsbiblioteket location: value: k00475 desc: UREAL Samling 42 pages: pieces: requested: false edition: null imprint: null language: null creation_date: 2015-11-05Z modification_date: 2015-11-23Z base_status: value: 1 desc: Item in place physical_material_type: value: BOOK desc: Book po_line: is_magnetic: false arrival_date: 2014-05-14Z year_of_issue: enumeration_a: chronology_i: receiving_operator: import process_type: value: desc: null alternative_call_number: alternative_call_number_type: value: desc: null storage_location_id: public_note: fulfillment_note: internal_note_1: Status: kat - kat internal_note_2: TIME FOR CIRC STATUS: 2015-11-02 | CIRC STATUS: 0 internal_note_3: statistics_note_1: statistics_note_2: statistics_note_3: total_record_count: 1
Note that the response doesn’t just include item data, but also a selection of holdings and bibliographic data. At least it’s well separated, so we can just ignore what we don’t need.
Having the item identifier (named ‘pid’) we could try checking out the item 23148809150002204
:
ITEM_ID=23148809150002204
USER_ID=<YOUR USER ID>
curl -X POST \
--header "Authorization: apikey ${ALMA_API_KEY}" \
"https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/${MMS_ID}/holdings/${HOLDING_ID}/items/${ITEM_ID}/loans?user_id=${USER_ID}"
Well, it didn’t work, I just got a BAD_REQUEST
error. Not really sure why.