API Presentation at ELUNA 2019, Atlanta, GA

By Chad Kluck on

You don't need to be a developer to understand the potential of Ex Libris APIs. Of the four major API integration projects undertaken by University of St. Thomas Libraries over the past year, three didn’t even require the library to supply a single line of code. Students and faculty now access their requests, loans, and fines through the university’s portal, we’ve experimented with discovery, request, and renewals using a chat interface, and we will now start to ingest invoices into our campus finance system, all by pitching the power of Ex Libris APIs to potential development partners. For beginners to intermediate, we’ll explore Ex Libris’s API Center, generate your first few API requests (bring your laptop or mobile device!), and introduce Postman (a free API tool). Best practices and security are also covered. Though Alma and Primo APIs are used as implementation examples, the main focus is getting comfortable using and leveraging APIs in general.

This is a presentation I gave at the Ex Libris Users North America (ELUNA) Conference in Atlanta, Georgia, Friday, May 3, 2019.

St. Thomas Libraries GitHub

Chad Kluck GitHub

Ex Libris Developer's Network

Postman

Serverless options

Code to run your own instance of the ELUNA example API:

Helpful GitHub projects

Ex Libris API Example (Load Courses)

PHP Project Framework: A project template to quickly develop your own APIs and microsites

JavaScript Template: A template to quickly develop JavaScript code that calls APIs

Example: 8 Ball

Additional Presentations

This ELUNA presentation was based on/extends the presentation I gave at UMWUG (Upper Midwest User Group) Fall:

More on the Library Help LTI: “Drag, Drop, Done, Implementing Library Help LTI in Canvas” presentation given at LibTech 2019:

API URLS

User, Loans, Fines, Fees

User

/almaws/v1/users/{{user_id}}?user_id_type=all_unique&view=full&expand=loans,fees,requests&apikey={{apikey}}&format=json

Loans

/almaws/v1/users/{{user_id}}/loans?user_id_type=all_unique&limit=10&offset=0&order_by=due_date&direction=ASC&apikey={{apikey}}&format=json

Holds/Requests

/almaws/v1/users/{{user_id}}/requests?request_type=HOLD&user_id_type=all_unique&limit=10&offset=0&status=active&apikey={{apikey}}&format=json

Fines

/almaws/v1/users/{{user_id}}/fees?user_id_type=all_unique&status=ACTIVE&apikey={{apikey}}&format=json

Search and Request

Perform a search on Primo

/primo/v1/pnxs?q={{query}}&lang=eng&offset=1&limit=10&view=full&vid={{view}}&scope={{scope}}&apikey={{apikey}}

When a user selects an item we get the BIB

/almaws/v1/bibs/?view=full&expand=p_avail,e_avail,d_avail&nz_mms_id={{nz_mms_id}}&format={{format}}&apikey={{apikey}}

/almaws/v1/bibs/{{mms_id}}/holdings?format={{format}}&apikey={{apikey}}

Get PID

/almaws/v1/bibs/{{mms_id}}/holdings/{{holding_id}}/items/?format={{format}}&apikey={{apikey}}

Make Request

/almaws/v1/bibs/{{mms_id}}/holdings/{{holding_id}}/items/{{item_pid}}/requests?user_id={{user_id}}&format={{format}}&apikey={{apikey}}

Import Invoices to Finance System

Get Fund Codes

/almaws/v1/acq/funds?apikey={{apikey}}&view=full&limit=100&offset=0

Get Active Invoices

/almaws/v1/acq/invoices/?apikey={{apikey}}&base_status=ACTIVE&limit=100&view=full&offset=0

Get Each Vendor (based on invoices)

/almaws/v1/acq/vendors/{{vendorCode}}?apikey={{apikey}}

PHP Code Snippets

Return an array as JSON

// ------------------------------------------------------
// PHP - Return an array as JSON

$data = array();
$data[] = "Hello World"; // put data in the array

$cache = 60; //in seconds
$origin = "https://www.yoursitedomain.com"; // CORS allowed origin

$ts = gmdate("D, d M Y H:i:s", time() + $cache) . " GMT";

header("Expires: ".$ts);
header("Pragma: cache");
header("Cache-Control: max-age=".$cache);
header("Access-Control-Allow-Origin: ".$origin); // CORS
header("Content-type: application/json");
echo json_encode($array);

Request JSON data as an array

// --------------------------------
// PHP - Request json data and turn into array
function getDataFromJSON($url) {
 $results = array();
 try {
 $contents = @file_get_contents($url); // @ means suppress warnings
 $results = json_decode($contents, true);
 } catch (Exception $e) {
 echo "Caught exception: ". $e->getMessage();
 }
 return $results;
}

$apikey = ""; // enter an API key here - needs access to Courses
$url = "https://api-na.hosted.exlibrisgroup.com/almaws/v1/courses?limit=10&offset=0&order_by=code%2Csection&direction=ASC&format=json&apikey=".$apikey; // change this to whatever you want, be sure the key has access
$data = getDataFromJSON($url);

Tags