The structure that unites resources and archival objects into the archival hierarchy.
Please note that are are some depreciated tree endpoints as of this presentation, I am using the newer ones
import requests
import json
baseURL = 'http://localhost:8089'
user = 'admin'
password = 'secure_password'
repository = '101'
auth = requests.post(baseURL + '/users/' + user + '/login?password=' + password).json()
session = auth['session']
headers = {'X-ArchivesSpace-Session': session, 'Content_Type': 'application/json'}
print('Your session key is: ' + session)
output = requests.get(baseURL + '/repositories/' + repository + '/resources/1/tree/root', headers=headers).json()
print(json.dumps(output, indent=2))
output = requests.get(baseURL + '/repositories/' + repository + '/resources/1/tree/node?node_uri=/repositories/' + repository + '/archival_objects/1', headers=headers).json()
print(json.dumps(output, indent=2))
output = requests.get(baseURL + '/repositories/' + repository + '/resources/1/tree/node?node_uri=/repositories/' + repository + '/archival_objects/2', headers=headers).json()
print(json.dumps(output, indent=2))
These demonstrations used the tree endpoints, such as [:GET] /repositories/:repo_id/resources/:id/tree/node
. Dealing with the tree endpoints is not intuitive. I consider them an intermediate-to-advanced skill in your ArchivesSpace toolbox.
By demonstrating the tree endpoints I want your takeaway to be two things, the first of which is more important:
Here are other ways to see and use tree information, including one of my favorite endpoints ever.
output = requests.get(baseURL + '/repositories/' + repository + '/archival_objects/6', headers=headers).json()
print(json.dumps(output, indent=2))
Get the list of URIs of this published resource and all published archival objects contained within. Ordered by tree order (i.e. if you fully expanded the record tree and read from top to bottom)
output = requests.get(baseURL + '/repositories/' + repository + '/resources/1/ordered_records', headers=headers).json()
print(json.dumps(output, indent=2))
# This demonstration script is just a way to explore example GETs, it doesn't contain any POSTs
# Final script all together.
# If you want to re-purpose this script, this is the block to use.
# Save it as name_of_file.py in order to run it as Python3 in your local environment.
# Disclaimer: This script is being provided as an example and may need to be modified for local use.
# Modifying and using this script is the responsibility of the individual using it.
# Do not test against Production!
# Authentication based on a script by ehanson8 (https://github.com/MITLibraries/archivesspace-api-python-scripts)
#Import the following libraries
import json
import requests
#Set your authentication info, baseurl, and repository info (if relevant)
baseURL = 'http://localhost:8089'
user = 'admin'
password = 'secure_password'
repository = '101'
#Authorize and store your session key in your header
auth = requests.post(baseURL + '/users/' + user + '/login?password=' + password).json()
session = auth['session']
headers = {'X-ArchivesSpace-Session': session, 'Content_Type': 'application/json'}
print('Your session key is: ' + session + ' for ' + baseURL)
# Explore the different endpoints here, you may need to change these to reflect your actual data
# The tree/root for resources/1:
output1 = requests.get(baseURL + '/repositories/' + repository + '/resources/1/tree/root', headers=headers).json()
print(json.dumps(output1, indent=2))
#tree/node for archival_object/1, which is in resources/1:
output2 = requests.get(baseURL + '/repositories/' + repository + '/resources/1/tree/node?node_uri=/repositories/' + repository + '/archival_objects/1', headers=headers).json()
print(json.dumps(output2, indent=2))
#tree/node for archival_object/2, which is in resources/1:
output3 = requests.get(baseURL + '/repositories/' + repository + '/resources/1/tree/node?node_uri=/repositories/' + repository + '/archival_objects/2', headers=headers).json()
print(json.dumps(output3, indent=2))
# Check out an ancestor array in archival_objects/6:
output4 = requests.get(baseURL + '/repositories/' + repository + '/archival_objects/6', headers=headers).json()
print(json.dumps(output4, indent=2))
# Check out ordered records for resources/1:
output5 = requests.get(baseURL + '/repositories/' + repository + '/resources/1/ordered_records', headers=headers).json()
print(json.dumps(output5, indent=2))