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).
This blog post includes 2 samples of scripts that retrieve a file with a list of items to process, and perform updates on that items. These scripts are just an example -  it is possible to update any field that is supported by the Update Item API.
 
 
Example 1: Update item barcodes in case of duplication
  1.  Identify items with duplicated barcodes. This can be done using analytics. See How To document.
  2.  Decide which item of the report above should be updated with a new barcode. <MMS ID>;<Holdings ID>;<Item ID>  of the item should be added to the input file for the script.
  3.  Define an automatic Barcode Generation method in Alma.
  4.  The script retrieves item data, removes barcode from the XML and sends it back with empty barcode. Alma will then assign a new barcode according to the Barcode Generation Configuration:
#!/bin/csh
set prefix = 'https://api-eu.hosted.exlibrisgroup.com/'
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
  echo "-- RESPONSE end --"
## activate for clean-up ##
##  rm *tmp
end

 

Example 2: Bulk removal of Due Back Date

The script performs the following logic:

  1.  Retrieve the item via GET
  2. Send back the full XML with empty Due Back Date and empty temporary location using PUT
set prefix = 'https://api-eu.hosted.exlibrisgroup.com/'
set api_key_header = 'Authorization: apikey l7xxxxxxx...'


foreach barc (`cat item_barcodes.txt`)
  echo __ processing item $barc __
  set item = `echo "$barc" | sed 's/.*;//'`
  set get_item_url = $prefix'almaws/v1/items?item_barcode='$barc

  echo __ Calling GET "$get_item_url" ...
  curl --dump-header /tmp/item.$barc.tmp "$get_item_url" -H "$api_key_header"
  set item_url = "$prefix`cat /tmp/item.$barc.tmp | grep Location | sed 's/.*almaws/almaws/' | sed 's/\r//g'`"

  echo __ Calling GET "$item_url" ...
  curl "$item_url" -H "$api_key_header" > $item.tmp
  cat $item.tmp | sed 's/<due_back_date>.*<\/due_back_date>/<due_back_date\/>/' | sed 's/<temp_location>.*<\/temp_location>/<temp_location\/>/' > $item.barc.tmp
  #cat $item.barc.tmp ; echo

  echo __ Calling PUT "$item_url" ...
  echo "-- RESPONSE start --"
  curl -X PUT "$item_url" -H "$api_key_header" -H "Content-Type: application/xml; charset=utf-8" -D - -d@$item.barc.tmp
  echo
  echo "-- RESPONSE end --"


## activate for clean-up ##
##  rm *tmp
end