Hi Corey,
Splitting this into two sections – the first is a description of what’s
happening and should immediately fix your current issue, the second is some
advice going forward re: using ASnake.
You appear to have found a bug in the ASpace API! From what I can tell, all_ids
is not actually correctly supported in ‘search/repositories’ – you’ll need to
use paged access until this is fixed. I'm going to file a ticket
There’s also a minor issue with your query – the type parameter actually takes
an ARRAY of strings, not a single string – in terms of how this shows up in the
URL, the request should look like:
search/repositories?type[]="resource"&q=ms945&page=1
And then you could change page to 2 to get the next page of results, etc.
BUT, section two: advice on how to do this easily! There’s two main things:
1. Pass parameters in as an argument to the function, rather than putting them
in the URL
client.get('search/repositories', params={"q": "ms945", "page": 1, "type[]":
'resource', 'page': 1})
ASnake is based on requests, so you can find specific documentation of how
params works in the requests documentation.
Additionally, ASpace is set up to automatically handle array parameters, so you
can actually do this (difference is to the type parameter):
client.get('search/repositories', params={"q": "ms945", "page": 1, "type":
['resource'], 'page': 1})
2. ASnake's client also has a function specifically to handle paged routes
called get_paged - so if you can do this:
for resource_json in client.get_paged('search/repositories', params={"q":
"ms945", "type": ['resource']}):
# do something with resource JSON
Let me know if you need more help, here are some pointers to relevant docs:
https://github.com/archivesspace-labs/archivessnake#low-level-api
https://requests.readthedocs.io/en/master/user/quickstart/#passing-parameters-in-urls
--
Dave Mayo (he/him)
Senior Digital Library Software Engineer
Harvard University > HUIT > LTS
From: <[email protected]> on behalf of
Corey Schmidt <[email protected]>
Reply-To: Archivesspace Users Group
<[email protected]>
Date: Monday, March 9, 2020 at 10:39 AM
To: "[email protected]"
<[email protected]>
Subject: [Archivesspace_Users_Group] Search Across Repositories and Get EAD XML
- ArchivesSpace API
Dear ArchivesSpace Members,
Hello, my name is Corey Schmidt and I’m working as the ArchivesSpace Project
Manager at the University of Georgia. I hope you all are doing well and having
a good start to your week.
I have two questions about how to utilize the ArchivesSpace API. First, I want
to use the
https://urldefense.proofpoint.com/v2/url?u=https-3A__archivesspace.github.io_archivesspace_api_-23search-2Dacross-2Drepositories&d=DwMFAg&c=WO-RGvefibhHBZq3fL85hQ&r=_Mv1dY22K7jvT5MD7xjbvGVzRDOUMhx4WYcnPSIzYnE&m=B2y_0wn1HLyXldJyck05IgPrsrOCn8LyjRI8q5uSbtc&s=_eqqK2s6KdcWsYV9Ke0loG2mitQ-I_nV-F9VeT24-l0&e=
API endpoint searching with the resource identifier and take the results to
get the URI for that resource. How do I structure my call to the API using the
ASnake client (in python)? I have tried the following code with response 400
returned:
client.get('search/repositories?type="resource"&q=ms954&all_ids=true')
client.get('/search/repositories?q=ms954&type="resource"&all_ids=true')
Second, I want to download an EAD xml file directly from the API using this
endpoint:
https://urldefense.proofpoint.com/v2/url?u=https-3A__archivesspace.github.io_archivesspace_api_-23get-2Dan-2Dead-2Drepresentation-2Dof-2Da-2Dresource&d=DwMFAg&c=WO-RGvefibhHBZq3fL85hQ&r=_Mv1dY22K7jvT5MD7xjbvGVzRDOUMhx4WYcnPSIzYnE&m=B2y_0wn1HLyXldJyck05IgPrsrOCn8LyjRI8q5uSbtc&s=xwd2j6qv-zYs8pDbLpLM23dcSeDYcPUkZSAuio8FEVQ&e=
XML. How do I specify where the EAD xml file saves to? I’m not even sure if it
is saving anywhere on my computer. However, my requests are successful,
generating a 200 response. I tried turning the response into json (using
ASnake’s .json()) and writing it, but I keep getting a JSONDecodeError. This is
my request:
request_ead =
client.get('repositories/5/resource_descriptions/5734.xml?include_unpublished=false&include_daos=true&numbered_cs=true&print_pdf=false&ead3=false')
Any help would be greatly appreciated!
Sincerely,
Corey
Corey Schmidt
ArchivesSpace Project Manager | University of Georgia Libraries
Email: mailto:[email protected]
Phone: +1-706-542-8151
_______________________________________________
Archivesspace_Users_Group mailing list
[email protected]
http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group