Skip to content

Instantly share code, notes, and snippets.

@djpillen
Last active March 18, 2016 19:52
Show Gist options
  • Select an option

  • Save djpillen/4617455ba6a82151959c to your computer and use it in GitHub Desktop.

Select an option

Save djpillen/4617455ba6a82151959c to your computer and use it in GitHub Desktop.
Publish ASpace agents that are linked to a published record
import requests
import json
#Change these
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}
agent_types = ["people", "corporate_entities", "families"]
for agent_type in agent_types:
agent_ids = requests.get("{0}/agents/{1}?all_ids=true".format(aspace_url, agent_type),headers=headers).json()
total = len(agent_ids)
count = 1
for agent_id in agent_ids:
print "Publishing {0} that are linked to published records - {1}/{2}".format(agent_type, count, total)
agent = requests.get("{0}/agents/{1}/{2}".format(aspace_url, agent_type, agent_id),headers=headers).json()
if agent['is_linked_to_published_record'] and not agent['publish']:
agent['publish'] = True
response = requests.post("{0}/agents/{1}/{2}".format(aspace_url, agent_type, agent_id),headers=headers, data=json.dumps(agent)).json()
print response
count += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment