Ready to Learn?Ex Libris products all provide open APIs

Tech Blog


Bulk updating items by API on a file of item pids

GSOAlma Support on December 4th, 2017

The Retrieve Item and Update Item APIs are useful in order to bulk change fields in item records that are not covered by the Change physical items batch job in Alma (see OLH for more information on the job).
The following script can be used in order to perform a "bulk" clean-up of duplicate barcodes based on a list of item pids in a single file.

Before running the script, you need to do the following:

1. Identify the items for barcode updating

You can create a report in Analytics to retrieve the duplicate barcodes (see How To document), then you need to decide which of the items should get a new barcode and add the <MMS ID>;<Holdings ID>;<Item ID>  of the item to the input file for the script.

2. Define an automatic Barcode Generation method in Alma.

The script retrieves the item data, removes the barcode from the XML and sends it back with empty barcode. Alma will then assign a new barcode according to the Barcode Generation Configuration.


set prefix = ''
set api_key_header = 'Authorization: apikey XXXXX'

foreach line (`cat item_list.txt`)
  echo __ processing item $line __
  set url = `echo "$line" | sed 's/;/\/holdings\//' | sed 's/;/\/items\//'`
  set item = `echo "$line" | sed 's/.*;//'`
  set get_item_url = $prefix'almaws/v1/bibs/'$url
  echo __ Calling GET "$get_item_url" ...
  curl -v "$get_item_url" -H "$api_key_header" > $item.tmp
  cat $item.tmp | sed 's/<barcode>.*<\/barcode>/<barcode\/>/' > $item.no_barcode.tmp
  echo __ Calling PUT "$get_item_url" ...
  echo "-- RESPONSE start --"
  curl -X PUT "$get_item_url" -H "$api_key_header" -H "Content-Type: application/xml" --data-binary "`cat $item.no_barcode.tmp`"
  echo "-- RESPONSE end --"
## activate for clean-up ##
##  rm *tmp