We need three pieces of information
Notice the similarity to update_agent.
def update_accession(api_url, auth_token, repo_id, accession_id, accession_model):
'''update an accession record and return a results message'''
data = json.JSONEncoder().encode(accession_model).encode('utf-8')
url = api_url+'/repositories/'+str(repo_id)+'/accessions/'+str(accession_id)
req = urllib.request.Request(
url = url,
data = None,
headers = {'X-ArchivesSpace-Session': auth_token},
method = 'POST')
try:
response = urllib.request.urlopen(req, data)
except urllib.error.URLError as e:
print(e.reason)
return None
except urllib.error.HTTPError as e:
print(e.code)
print(e.read())
return None
src = response.read().decode('utf-8')
return json.JSONDecoder().decode(src)
And our test in the if block
# Test update_accession
print('Test update_accession()')
accession_id = int(input('Enter accession id to uppdate: '))
accession_model = list_accession(api_url, auth_token, repo_id, accession_id)
accession_model['title'] = input('Enter new title: ')
result = update_accession(api_url, auth_token, repo_id, accession_id, accession_model)
print('update result', json.dumps(result, indent=4))
Full listing accession.py