5. Working with Agents

list_agent implementation

In our definition section add

    def list_agent(api_url, auth_token, agent_type, agent_id):
       '''List all the agent ids of a given type'''
       url = api_url+agent_type_path(agent_type)+'/'+str(agent_id)
       req = urllib.request.Request(
          url = url,
          data = None,
          headers = {'X-ArchivesSpace-Session': auth_token},
          method = 'GET')
       try:
            response = urllib.request.urlopen(req)
       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)

In our test if block add

        print('Test list_agent()')
        agent_id = int(input('Enter agent_id (numeric): '))
        agent = list_agent(api_url, auth_token, 'agent_person', agent_id)
        print('agent', agent_id, ' details', json.dumps(agent, indent=4))

Full listing agent.py