Key
You will need an API key before you can pull or push data via the API. A key can be obtained from Digital Technologies with proper permissions from your supervisor. This key is also used in tools such as Spine'O'matic for call number printing, or Alma integration in MarcEdit. There are separate keys for the production and sandbox environments.
Connecting
Connecting to the API depends on the service you are using. If you are using MARCEdit (see here) or Spine'O'matic (see here).
If you wish to use python to pull or update Alma data via the API, here is a sample code:
Below is an example of a code that queries Alma's API and instructs it to update items. This specifically will append a specific note to a list of barcodes provided in the file.
import requests
import json
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = "https://api-na.hosted.exlibrisgroup.com/almaws/v1/items?item_barcode={barcode}&apikey={key}"
purl = "https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/{mms_id}/holdings/{holding_id}/items/{item_pid}?generate_description=false&apikey={key}"
file = open(r'[Enter your file path here]', rb)
Key = '[Enter your key here]'
for line in file:
barcode=line.decode('utf8').strip()
req = requests.get(url.format(barcode=barcode, key=Key), headers=headers,)
data = req.json()
itemnote = (data['item_data']['internal_note_1'])
mmsid = (data['bib_data']['mms_id'])
hid = (data['holding_data']['holding_id'])
ipid = (data['item_data']['pid'])
itemappend = " | [Enter Note Text Here]"
itemupdate = "".join((itemnote,itemappend))
data['item_data']['internal_note_1'] = itemupdate
response = requests.put(purl.format(mms_id=mmsid, holding_id=hid, item_pid=ipid), json=data, headers=headers)
Updating
You will specifically need to add the response line from the example above in order to apply any updates to the data. The json variable in the response line can be set to be equal to any variable you wish but be aware it will completely overlay everything, not just the specific section you accessed. To update just a specific section, change just that specific section in the code before using the response line. For example, you can see that I set the data['item_data']['internal_note_1'] to equal the update I made, this will update only that specific section of the record and update it. Then set the json=data and it should update the field you selected and leave the rest of the record as is.


