Tech Blog

Batch Updating Alma Representations with REST

The Global Representation Changes Job offers the option to batch update various representations properties. It is a robust job that uses the Alma jobs infrastructure and allows updating several properties at once. However, in some cases a more customizable approach may be desired. In this post, a basic Python-based tool for updating representation properties via REST API is presented. The script expects an exact match, but can be modified to use more complex replace logic such as truncation or regular expressions.

See here for a list of representation properties that can be updated.

Note: Currently updates to entity_type and its related fields are not supported by the tool.

The script takes the following arguments:

  • API Key (with read/write permissions)
  • Textual file containing a list of MMS IDs, one per line
  • Logfile location (optional)
  • Property to update
  • Old value to match (or * for any)
  • New value to set
API Key: lxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0
Checking API Key... OK
Location of bibs list: bibs.txt
Logfile (leave empty for standard output): out.txt
Property to update: label
Old Value ('*' for 'any'): Oldlabel
New Value: Newlabel
Replace 'Oldlabel' with 'Newlabel' for property 'label'? (Y/N)Y


Number of fixed representations: 231
Number of skipped representations: 3
Number of errors: 0
See details in out.txt

The logfile provides a list of MMS IDs and Representation IDs and a summary:

------------------------- Start: 07/16/2020, 09:37:54-------------------------
Replacing 'Oldlabel' with 'Newlabel' for property 'label'
MMS ID: 99255841300561 representation ID: 12122519820000561 - match, fixed
MMS ID: 99255841300561 representation ID: 12155040000000561 - match, fixed
MMS ID: 99419741400561 representation ID: 12137819890000561 - no match, skipped
Number of fixed representations: 231
Number of skipped representations: 3
Number of errors: 0
------------------------- End: 07/16/2020, 09:47:59-------------------------

The script was tested using Python version 3.7.8.

One Reply to “Batch Updating Alma Representations with REST”

  1. Hi Opher

    That’s great. Have used that for thousands of records.
    Can you add an option to replace a text with nothing (Empty)?
    If already exists, will be glad getting details.


Leave a Reply