Tech Blog

Update Item Information API – Enumeration Field

This blog post contributes another example of using the Update Item Information API (see also https://developers.exlibrisgroup.com/blog/bulk-updating-items-by-api-on-a-file-of-item-pids/). This example uses PowerShell.

Problem: We would like to update the Enumeration A fields in item records. However, the  Change Physical Items job does not allow for this functionality. (Note: this is no longer the case as of the June 2020 release. However, this procedure can easily be applied to other fields.) 

Solution: Use a PowerShell script with the Update Item Information API (PUT /almaws/v1/bibs/{mms_id}/holdings/{holding_id}/items/{item_pid}).

(see full documentation at https://developers.exlibrisgroup.com/alma/apis/docs/bibs/UFVUIC9hbG1hd3MvdjEvYmlicy97bW1zX2lkfS9ob2xkaW5ncy97aG9sZGluZ19pZH0vaXRlbXMve2l0ZW1fcGlkfQ==/)

Workflow:

Starting with a list of barcodes, use the Item Barcode API (GET /almaws/v1/items?item_barcode={barcode}) to collect data points {mms_id}, {holding_id}, and {item_pid}.

Code:

#Define Starting Variables

$ItemData = “c:usersuserdesktopbarcodes.txt”​

$url_base = ‘https://api-na.hosted.exlibrisgroup.com/almaws/v1/items?item_barcode=’​

$url_params = ‘&apikey=’​

$apiKey = ‘superSecretKey’​

#Load List of Barcodes into Memory

$BarcodeList = Get-Content $ItemData -ErrorAction SilentlyContinue

#Define Script to Use Each Barcode

foreach ($BarcodeId in $BarcodeList) {​

#Run Item_Barcode API to Fetch Item XML​

$loadUrl = $url_base + $BarcodeId + $url_params + $apiKey​

[xml]$xml = (New-Object System.Net.WebClient).DownloadString(“$loadUrl”)

#Identify the Enumeration_A Field and Add Text “1” to It

$node = $xml.SelectSingleNode(“//enumeration_a”)​

$node.InnerText = “1”​

#Identify Components of Update Item InfoAPI​

$mmsID = $xml.item.bib_data.mms_id​

$holdingID = $xml.item.holding_data.holding_id​

$pidID = $xml.item.item_data.pid​

#Construct Update Item Information API

$putURL = ‘https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/’ + $mmsID + ‘/holdings/’ + $holdingID + ‘/items/’ + $pidID + ‘?apikey=’ + $apiKey​

#PUT XML Back into Alma with Updated Node via Update Item Information API

$Response = Invoke-WebRequest -Uri $putUrl -Method PUT -Body $xml -ContentType “application/xml”​

#Write out barcode (for pseudo-error reporting)

Write-Host $BarcodeId

#Close the ForEach

}

Note: there is a potential problem when using the Update Item Information API, if the item records are frozen/locked. Please see blog post for more information: https://developers.exlibrisgroup.com/forums/topic/items-api-error-unable-to-set-temp_location-with-invalid-missing-temp_library/

Leave a Reply