SlideShare a Scribd company logo
Kyle Banerjee
https://bit.ly/alma_api
Getting Started with the
Alma API
● Perform mass modifications of user, item,
bib, holdings, or any other type of record
● Manage collections, portfolios, digital
assets, vendors, invoices, licenses
● Perform extractions and analyses that are
impossible in Analytics
● And more!
What can the Alma API do?
All an API does is send and receive
plain text* messages
APIs are MUCH simpler than they look
* You can also send and receive binary things like
images, but the process is the same as for text
...between using an API and a Web form
from 1995 is that something you wrote
rather than a browser interprets the text
the server sends
The only real difference...
● Focus on the main takeaways
● Ignore syntax. Pay attention to what is
being done, but not how -- you can
figure that out later
● Ask for help
If you’re new to APIs
● Syntax is hard because it’s super picky
and a little text does lot of work
● You can always look up syntax. Don’t try to
memorize everything
● If you don’t get it right the first (or tenth)
time, you can keep tweaking it until you get
it right
If you feel intimidated, remember...
● A way to interact with applications
● ReST (Representational State Transfer) API
is a fancy way of saying to interact with an
application the way a mid 1990’s Web
browser would
API (Application Programming Interface)
Anatomy of retrieving a Web page
Ordinary terminal connection
Request main page at root of site
Server sends back web page
The browser converts text to what you see
Real Alma API call
Set up encrypted connection
Request holdings record per API
specification
Holdings record returned
To use the Alma API, you typically need to
1. Read a file containing information allowing
you to build a command
2. Send that information to the API
3. Read and modify information you receive
from the API
Now what?
The command line
● Often by far the easiest way
● More flexible than a GUI
● Supported by all major platforms
● Process files of any size
● Combine the power of individual
programs -- they do all the heavy
lifting for you!
Handy tools for the Alma API
Linux or MacOS command line
curl -- Communicate with API service
xmlstarlet -- Extract data from XML or
edit XML
sed -- Clean data
cut -- Break data into fields
echo -- Print data
Learning the command line
● Learn one command at a time. Don’t worry
about what you don’t need.
● Don’t worry if you get things wrong -- one
advantage of the command line is you can try
things many times until you get it right
● Google solutions for specific problems --
there are many online examples
● Try, but give up fast. Ask linux geeks for help
Getting started with the command line
● MacOS (use Terminal)
○ Install Homebrew
xcode-select --install
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install coreutils
● Windows 10
○ Enable linux subsystem and go to bash terminal
Scripting is the command line!
● Simple text files that allow you to combine
utilities and programs written in any
language
● No programming experience necessary
● Great for automating processes
● For unfamiliar problems, ask for help
Command Line Tools:
curl, xmlstarlet, cut, and sed
curl
● A tool to transfer data from or to a server
● Works with many protocols, can deal with
authentication
● Especially useful for the Alma API
curl examples
curl -s -H "Authorization: apikey [your API key]" 
-H "Accept: application/xml" 
GET https://api-na.hosted.exlibrisgroup.com/[api call]
curl -s -H "Authorization: apikey [your API key]" 
-d "$DATA"  # data stored in variable
-H "Content-Type: application/xml" 
PUT https://api-na.hosted.exlibrisgroup.com/[api call]
curl -s -H "Authorization: apikey [your API key]" 
-d "@datafile"  # data stored in file
-H "Content-Type: application/xml" 
PUT https://api-na.hosted.exlibrisgroup.com/[api call]
curl examples
Reading records
curl -s -H "Authorization: apikey [your API key]" 
-H "Accept: application/xml" 
GET https://api-na.hosted.exlibrisgroup.com/[api call]
Updating records
curl -s -H "Authorization: apikey [your API key]" 
-H "Content-Type: application/xml" -d "$DATA" 
PUT https://api-na.hosted.exlibrisgroup.com/[api call]
Creating records
curl -s -H "Authorization: apikey [your API key]" 
-H "Content-Type: application/xml" -d "@datafile" 
POST https://api-na.hosted.exlibrisgroup.com/[api call]
Xmlstarlet
● A tool to parse, selectively display, update,
and create XML data
● Syntax can be challenging - little
parameters have a lot of power!
● Examples are the best way to learn - we’ll
look at some next.
Linux (and Windows Linux subsystem)
sudo apt-get install xmlstarlet
Mac
brew install xmlstarlet
Installing Xmlstarlet
-t creates a template
-m matches an XPATH expression
-v selects a value
-o outputs literal text
-c + ‘count()’ gives a count
Protip: ALWAYS strip out namespaces using sed
-- xmlstarlet is picky about them, so they’re a
pain. You can skip this with the Alma API
because it doesn’t send a namespace
xmlstarlet is easier than it looks
Extract a value and store in a variable
holdingid=$(echo $record |xmlstarlet sel -t -m
"item/holding_data/holding_id" -v . )
Update a node within an XML document
holdings=$(echo $holdings | xmlstarlet ed -u
'/holding/record/datafield[@tag="852"]/subfield[@code="c"]
' -v 'oldstorbks')
Xmlstarlet examples
sed
● User regular expressions to select,
parse, and transform lines
● Great for “fixing” data so that it can be
used with other programs
● Extremely powerful and works great
with very large (terabytes) files
● Strip everything except numbers from
barcode variable
barcode=$(sed 's/[^0-9]//g' <<< "$barcode")
● Strip all nonnumeric data from file1 with
results sent to file2
cat file1 | sed 's/[^0-9]//g' > file2
sed examples
Quick Regular Expression Guide
^ Match the start of the line
$ Match the end of the line
. Match any single character
* Match zero or more of the previous character
[A-D,G-J,0-5]* [A-D,G-J,0-5]* = match zero or more of ABCDGHIJ012345
[^A-C] Match any one character that is NOT A,B, or C
(dog)
Match the word "dog", including case, and remember that text
to be used later in the match or replacement
1
Insert the first remembered text as if it were typed here (2 for
second, 3 for 3rd, etc.)

Use to match special characters.  matches a backslash, *
matches an asterisk, $ matches dollar sign, etc.
cut -- Extract fields from delimited data
Extract second field in comma delimited line
variable
secondfield="$(cut -d',' -f2 <<<$line)"
Extract first through third fields in comma
delimited file and send output to file2
cat file1 | cut -d',' -f1-3 > file2
Read and process file
# Read file named “barcodes” one line at a time
cat barcodes | while read line
do
# Clean barcode
barcode=$(sed 's/[^0-9]//g' <<< "$line")
# print barcode
echo barcode
done
Putting it All Together:
A Practical Example
1. Create list of barcodes
2. Get mmsids and holdingsids from Alma
3. Retrieve holdings records based on
mmsids and holdingsids
4. Update location in holdings record
5. Replace holdings record
Example: Update locations based on barcode
cat barcodes| while read barcode # Read input file named “barcodes” one line at a time
do
barcode=$(sed 's/[^0-9]//g' <<< "$barcode") # Clean barcode
# Get record and extract record ids
recinfo=$(curl -s -X GET -L -H "Authorization: apikey $(cat apikey.txt)" "https://api-
na.hosted.exlibrisgroup.com/almaws/v1/items?item_barcode=${barcode}")
mmsid=$(echo $recinfo |xmlstarlet sel -t -m "item/bib_data/mms_id" -v . )
holdingid=$(echo $recinfo |xmlstarlet sel -t -m "item/holding_data/holding_id" -v . )
# Retrieve holdings record
url="https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/${mmsid}/holdings/${holdingid}"
holdings=$(curl -s -X GET -L -H "Authorization: apikey $(cat apikey.txt)" "${url}")
# Edit location in holdings record
holdings=$(echo $holdings | xmlstarlet ed -u
'/holding/record/datafield[@tag="852"]/subfield[@code="c"]' -v 'oldstorbks')
# Replace holdings record
newloc=$(curl -s -H "Authorization: apikey $(cat apikey.txt)" -H "Content-Type: application/xml" -
X PUT --data "${holdings}" "${url}")
done
A lot of work in just a few lines!
Retrieve the record via API
recinfo=$(curl -s -X GET -L -H "Authorization: apikey $(cat apikey.txt)" "https://api-
na.hosted.exlibrisgroup.com/almaws/v1/items?item_barcode=33231000051658"))
echo $recinfo |xmlstarlet fo
Extract fields we want with xmlstarlet
Then extract holdings and MMSID to construct another
query to retrieve the holdings record
Fix the XML
holdings=$(echo $holdings | xmlstarlet ed -u
'/holding/record/datafield[@tag="852"]/subfield[@code="c"]' -v 'oldstorbks')
● Use pipes “|” to make the output of one
command the input of another
● Use command substitution $(command) to
put use the output of one command within
another
● Use backslashes to break a single
command up across multiple lines to make
it more readable
Handy things to know with scripts
Running your scripts
● Script first must be made executable.
This must only be only once
chmod 700 myscript
● To run, just get in the same directory
and precede filename with a period and
forward slash
./myscript
Alma API Documentation
https://developers.exlibrisgroup.com/alma/apis/
This presentation
https://bit.ly/alma_api
A few starter scripts
https://github.com/banerjek/alma
Resources
Thank you!

More Related Content

What's hot (10)

PDF
Group6SDFinal
Hong Lu
 
PDF
Online Library Mangement System
Ammar Azeem
 
PPTX
Library Management System
Ankita Jangir
 
ODP
From Use case to User Story
Kunta Hutabarat
 
PDF
11.project online library management system
richaramgarh
 
PPSX
USING BIGDATA WITH ACADEMIC LIBRARY SERVICES: A VIEW
Nellore Harilakshmi
 
PPTX
IFLA ARL Webinar Series: Academic Library Services during Covid 19
IFLAAcademicandResea
 
PPTX
Library management system
Kamal Krish
 
PDF
Majd
BENSONOPITIA
 
DOC
Sequnce diagram for ONLINE EXAMINATION SYSTEM
COMSATS Institute of Information Technology
 
Group6SDFinal
Hong Lu
 
Online Library Mangement System
Ammar Azeem
 
Library Management System
Ankita Jangir
 
From Use case to User Story
Kunta Hutabarat
 
11.project online library management system
richaramgarh
 
USING BIGDATA WITH ACADEMIC LIBRARY SERVICES: A VIEW
Nellore Harilakshmi
 
IFLA ARL Webinar Series: Academic Library Services during Covid 19
IFLAAcademicandResea
 
Library management system
Kamal Krish
 
Sequnce diagram for ONLINE EXAMINATION SYSTEM
COMSATS Institute of Information Technology
 

Similar to Getting Started with the Alma API (20)

PDF
Server Logs: After Excel Fails
Oliver Mason
 
PDF
REST in pieces
sparkfabrik
 
PDF
[drupalday2017] - REST in pieces
DrupalDay
 
PPTX
programming language interface i.pptx
urvashipundir04
 
PPTX
CS174-151104itisapptofsomeauthoronninternet.pptx
Patrickbatemen1
 
PPTX
AWS Hadoop and PIG and overview
Dan Morrill
 
PDF
Amazon EMR Masterclass
Ian Massingham
 
PDF
Creating a modern web application using Symfony API Platform Atlanta
Jesus Manuel Olivas
 
PDF
Catalyst - refactor large apps with it and have fun!
mold
 
PDF
mastering libcurl part 1
Daniel Stenberg
 
PDF
GenAI-powered assistants compared in a real case - 2025-03-18
Alessandra Bilardi
 
PDF
Embulk, an open-source plugin-based parallel bulk data loader
Sadayuki Furuhashi
 
PPT
Wikilims Road4
guestcc22df
 
PPTX
Web data from R
schamber
 
ODP
NYPHP March 2009 Presentation
brian_dailey
 
ODP
Practical catalyst
dwm042
 
PDF
Killing the Angle Bracket
jnewmanux
 
PDF
Useful Python Libraries for Network Engineers - PyOhio 2018
Hank Preston
 
PDF
OpenERP Technical Memento V0.7.3
Borni DHIFI
 
PDF
Big Data - Lab A1 (SC 11 Tutorial)
Robert Grossman
 
Server Logs: After Excel Fails
Oliver Mason
 
REST in pieces
sparkfabrik
 
[drupalday2017] - REST in pieces
DrupalDay
 
programming language interface i.pptx
urvashipundir04
 
CS174-151104itisapptofsomeauthoronninternet.pptx
Patrickbatemen1
 
AWS Hadoop and PIG and overview
Dan Morrill
 
Amazon EMR Masterclass
Ian Massingham
 
Creating a modern web application using Symfony API Platform Atlanta
Jesus Manuel Olivas
 
Catalyst - refactor large apps with it and have fun!
mold
 
mastering libcurl part 1
Daniel Stenberg
 
GenAI-powered assistants compared in a real case - 2025-03-18
Alessandra Bilardi
 
Embulk, an open-source plugin-based parallel bulk data loader
Sadayuki Furuhashi
 
Wikilims Road4
guestcc22df
 
Web data from R
schamber
 
NYPHP March 2009 Presentation
brian_dailey
 
Practical catalyst
dwm042
 
Killing the Angle Bracket
jnewmanux
 
Useful Python Libraries for Network Engineers - PyOhio 2018
Hank Preston
 
OpenERP Technical Memento V0.7.3
Borni DHIFI
 
Big Data - Lab A1 (SC 11 Tutorial)
Robert Grossman
 
Ad

More from Kyle Banerjee (9)

PPTX
Demystifying RDF
Kyle Banerjee
 
PPTX
Keep it Safe, Stupid, or an Intro to Digital Preservation
Kyle Banerjee
 
PPTX
Web Scraping Basics
Kyle Banerjee
 
PPTX
Future Directions in Metadata
Kyle Banerjee
 
PPTX
Переход от отдельных библиотечных систем к объединенной системе Альма
Kyle Banerjee
 
PPTX
Normalizing Data for Migrations
Kyle Banerjee
 
PPTX
Dropping ACID: Wrapping Your Mind Around NoSQL Databases
Kyle Banerjee
 
PPT
Batch metadata assignment to archival photograph collections using facial rec...
Kyle Banerjee
 
PPT
Intro to XML in libraries
Kyle Banerjee
 
Demystifying RDF
Kyle Banerjee
 
Keep it Safe, Stupid, or an Intro to Digital Preservation
Kyle Banerjee
 
Web Scraping Basics
Kyle Banerjee
 
Future Directions in Metadata
Kyle Banerjee
 
Переход от отдельных библиотечных систем к объединенной системе Альма
Kyle Banerjee
 
Normalizing Data for Migrations
Kyle Banerjee
 
Dropping ACID: Wrapping Your Mind Around NoSQL Databases
Kyle Banerjee
 
Batch metadata assignment to archival photograph collections using facial rec...
Kyle Banerjee
 
Intro to XML in libraries
Kyle Banerjee
 
Ad

Recently uploaded (20)

PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Biography of Daniel Podor.pdf
Daniel Podor
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 

Getting Started with the Alma API

  • 2. ● Perform mass modifications of user, item, bib, holdings, or any other type of record ● Manage collections, portfolios, digital assets, vendors, invoices, licenses ● Perform extractions and analyses that are impossible in Analytics ● And more! What can the Alma API do?
  • 3. All an API does is send and receive plain text* messages APIs are MUCH simpler than they look * You can also send and receive binary things like images, but the process is the same as for text
  • 4. ...between using an API and a Web form from 1995 is that something you wrote rather than a browser interprets the text the server sends The only real difference...
  • 5. ● Focus on the main takeaways ● Ignore syntax. Pay attention to what is being done, but not how -- you can figure that out later ● Ask for help If you’re new to APIs
  • 6. ● Syntax is hard because it’s super picky and a little text does lot of work ● You can always look up syntax. Don’t try to memorize everything ● If you don’t get it right the first (or tenth) time, you can keep tweaking it until you get it right If you feel intimidated, remember...
  • 7. ● A way to interact with applications ● ReST (Representational State Transfer) API is a fancy way of saying to interact with an application the way a mid 1990’s Web browser would API (Application Programming Interface)
  • 8. Anatomy of retrieving a Web page Ordinary terminal connection Request main page at root of site Server sends back web page
  • 9. The browser converts text to what you see
  • 10. Real Alma API call Set up encrypted connection Request holdings record per API specification Holdings record returned
  • 11. To use the Alma API, you typically need to 1. Read a file containing information allowing you to build a command 2. Send that information to the API 3. Read and modify information you receive from the API Now what?
  • 12. The command line ● Often by far the easiest way ● More flexible than a GUI ● Supported by all major platforms ● Process files of any size ● Combine the power of individual programs -- they do all the heavy lifting for you!
  • 13. Handy tools for the Alma API Linux or MacOS command line curl -- Communicate with API service xmlstarlet -- Extract data from XML or edit XML sed -- Clean data cut -- Break data into fields echo -- Print data
  • 14. Learning the command line ● Learn one command at a time. Don’t worry about what you don’t need. ● Don’t worry if you get things wrong -- one advantage of the command line is you can try things many times until you get it right ● Google solutions for specific problems -- there are many online examples ● Try, but give up fast. Ask linux geeks for help
  • 15. Getting started with the command line ● MacOS (use Terminal) ○ Install Homebrew xcode-select --install ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew install coreutils ● Windows 10 ○ Enable linux subsystem and go to bash terminal
  • 16. Scripting is the command line! ● Simple text files that allow you to combine utilities and programs written in any language ● No programming experience necessary ● Great for automating processes ● For unfamiliar problems, ask for help
  • 17. Command Line Tools: curl, xmlstarlet, cut, and sed
  • 18. curl ● A tool to transfer data from or to a server ● Works with many protocols, can deal with authentication ● Especially useful for the Alma API
  • 19. curl examples curl -s -H "Authorization: apikey [your API key]" -H "Accept: application/xml" GET https://api-na.hosted.exlibrisgroup.com/[api call] curl -s -H "Authorization: apikey [your API key]" -d "$DATA" # data stored in variable -H "Content-Type: application/xml" PUT https://api-na.hosted.exlibrisgroup.com/[api call] curl -s -H "Authorization: apikey [your API key]" -d "@datafile" # data stored in file -H "Content-Type: application/xml" PUT https://api-na.hosted.exlibrisgroup.com/[api call]
  • 20. curl examples Reading records curl -s -H "Authorization: apikey [your API key]" -H "Accept: application/xml" GET https://api-na.hosted.exlibrisgroup.com/[api call] Updating records curl -s -H "Authorization: apikey [your API key]" -H "Content-Type: application/xml" -d "$DATA" PUT https://api-na.hosted.exlibrisgroup.com/[api call] Creating records curl -s -H "Authorization: apikey [your API key]" -H "Content-Type: application/xml" -d "@datafile" POST https://api-na.hosted.exlibrisgroup.com/[api call]
  • 21. Xmlstarlet ● A tool to parse, selectively display, update, and create XML data ● Syntax can be challenging - little parameters have a lot of power! ● Examples are the best way to learn - we’ll look at some next.
  • 22. Linux (and Windows Linux subsystem) sudo apt-get install xmlstarlet Mac brew install xmlstarlet Installing Xmlstarlet
  • 23. -t creates a template -m matches an XPATH expression -v selects a value -o outputs literal text -c + ‘count()’ gives a count Protip: ALWAYS strip out namespaces using sed -- xmlstarlet is picky about them, so they’re a pain. You can skip this with the Alma API because it doesn’t send a namespace xmlstarlet is easier than it looks
  • 24. Extract a value and store in a variable holdingid=$(echo $record |xmlstarlet sel -t -m "item/holding_data/holding_id" -v . ) Update a node within an XML document holdings=$(echo $holdings | xmlstarlet ed -u '/holding/record/datafield[@tag="852"]/subfield[@code="c"] ' -v 'oldstorbks') Xmlstarlet examples
  • 25. sed ● User regular expressions to select, parse, and transform lines ● Great for “fixing” data so that it can be used with other programs ● Extremely powerful and works great with very large (terabytes) files
  • 26. ● Strip everything except numbers from barcode variable barcode=$(sed 's/[^0-9]//g' <<< "$barcode") ● Strip all nonnumeric data from file1 with results sent to file2 cat file1 | sed 's/[^0-9]//g' > file2 sed examples
  • 27. Quick Regular Expression Guide ^ Match the start of the line $ Match the end of the line . Match any single character * Match zero or more of the previous character [A-D,G-J,0-5]* [A-D,G-J,0-5]* = match zero or more of ABCDGHIJ012345 [^A-C] Match any one character that is NOT A,B, or C (dog) Match the word "dog", including case, and remember that text to be used later in the match or replacement 1 Insert the first remembered text as if it were typed here (2 for second, 3 for 3rd, etc.) Use to match special characters. matches a backslash, * matches an asterisk, $ matches dollar sign, etc.
  • 28. cut -- Extract fields from delimited data Extract second field in comma delimited line variable secondfield="$(cut -d',' -f2 <<<$line)" Extract first through third fields in comma delimited file and send output to file2 cat file1 | cut -d',' -f1-3 > file2
  • 29. Read and process file # Read file named “barcodes” one line at a time cat barcodes | while read line do # Clean barcode barcode=$(sed 's/[^0-9]//g' <<< "$line") # print barcode echo barcode done
  • 30. Putting it All Together: A Practical Example
  • 31. 1. Create list of barcodes 2. Get mmsids and holdingsids from Alma 3. Retrieve holdings records based on mmsids and holdingsids 4. Update location in holdings record 5. Replace holdings record Example: Update locations based on barcode
  • 32. cat barcodes| while read barcode # Read input file named “barcodes” one line at a time do barcode=$(sed 's/[^0-9]//g' <<< "$barcode") # Clean barcode # Get record and extract record ids recinfo=$(curl -s -X GET -L -H "Authorization: apikey $(cat apikey.txt)" "https://api- na.hosted.exlibrisgroup.com/almaws/v1/items?item_barcode=${barcode}") mmsid=$(echo $recinfo |xmlstarlet sel -t -m "item/bib_data/mms_id" -v . ) holdingid=$(echo $recinfo |xmlstarlet sel -t -m "item/holding_data/holding_id" -v . ) # Retrieve holdings record url="https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/${mmsid}/holdings/${holdingid}" holdings=$(curl -s -X GET -L -H "Authorization: apikey $(cat apikey.txt)" "${url}") # Edit location in holdings record holdings=$(echo $holdings | xmlstarlet ed -u '/holding/record/datafield[@tag="852"]/subfield[@code="c"]' -v 'oldstorbks') # Replace holdings record newloc=$(curl -s -H "Authorization: apikey $(cat apikey.txt)" -H "Content-Type: application/xml" - X PUT --data "${holdings}" "${url}") done A lot of work in just a few lines!
  • 33. Retrieve the record via API recinfo=$(curl -s -X GET -L -H "Authorization: apikey $(cat apikey.txt)" "https://api- na.hosted.exlibrisgroup.com/almaws/v1/items?item_barcode=33231000051658")) echo $recinfo |xmlstarlet fo
  • 34. Extract fields we want with xmlstarlet Then extract holdings and MMSID to construct another query to retrieve the holdings record
  • 35. Fix the XML holdings=$(echo $holdings | xmlstarlet ed -u '/holding/record/datafield[@tag="852"]/subfield[@code="c"]' -v 'oldstorbks')
  • 36. ● Use pipes “|” to make the output of one command the input of another ● Use command substitution $(command) to put use the output of one command within another ● Use backslashes to break a single command up across multiple lines to make it more readable Handy things to know with scripts
  • 37. Running your scripts ● Script first must be made executable. This must only be only once chmod 700 myscript ● To run, just get in the same directory and precede filename with a period and forward slash ./myscript
  • 38. Alma API Documentation https://developers.exlibrisgroup.com/alma/apis/ This presentation https://bit.ly/alma_api A few starter scripts https://github.com/banerjek/alma Resources