Last active
June 1, 2016 17:19
-
-
Save djpillen/3a4759197287f18273e27c7267f901fa to your computer and use it in GitHub Desktop.
ASpace find_by_id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
# Proof of concept update for https://github.com/djpillen/bentley_scripts/blob/master/update_archival_object.py using the new find_by_id endpoint | |
aspace_url = 'http://localhost:8089' | |
username= 'admin' | |
password = 'admin' | |
auth = requests.post("{0}/users/{1}/login?password={2}".format(aspace_url, username, password)).json() | |
session = auth["session"] | |
headers = {'X-ArchivesSpace-Session':session} | |
# Read these from a spreadsheet or whatever as in the original script | |
ref_ids = ["abc", "123"] | |
# The "ref_id[]" param can take either a single ref_id or a list of ref_ids | |
params = {"ref_id[]":ref_ids} | |
lookup_unresolved = requests.get("{0}/repositories/2/find_by_id/archival_objects".format(aspace_url), params=params, headers=headers).json() | |
""" | |
This returns a dict with just the URIs to the found archival objects, which could be used to get the full JSON for each archival object: | |
{"archival_objects":[ | |
{"ref":"/repositories/2/archival_objects/1"}, | |
{"ref":"/repositories/2/archival_objects/2"} | |
]} | |
""" | |
params["resolve[]"] = "archival_objects" | |
lookup_resolved = requests.get("{0}/repositories/2/find_by_id/archival_objects".format(aspace_url), params=params, headers=headers).json() | |
""" | |
Adding the "resolve[]" parameter returns a dict with the URIs for the found archival objects AND the full JSON for each archival object, | |
which could then be parsed and updated as necessary: | |
{"archival_objects": [ | |
{"ref":"/repositories/2/archival_objects/1", "_resolved": {"the JSON for the first archival object"}}, | |
{"ref":"/repositories/2/archival_objects/2", "_resolved":{the JSON for the second archival object"}} | |
]} | |
""" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment