[Archivesspace_api_doc_adhoc] find_by_id Endpoint Help

Mayo, Dave dave_mayo at harvard.edu
Thu May 26 16:31:54 EDT 2022


It’d be each id as its own key:value pair in the parameters – like, if you’re passing one identifier, you’d serialize the json array but wouldn’t put an extra array around it?

Really, I think you’d want to do the following:

curl -H "X-ArchivesSpace-Session: $SESSION" -G http://our_aspace_api_url/repositories/2/find_by_id/resources  --data-urlencode "identifier[]=${IDENTIFIER}"

where -G switches the request to GET, and makes following –data* options stick things in the query string rather than formdata.  Since you’re not putting the [] in the url anymore you can dispense with -g

For multiple ids, you’d repeat the –data-urlencode with the same key and the other values.

So for example:

$ curl -H "X-ArchivesSpace-Session: $SESSION" -G http://our_aspace_api_url/repositories/2/find_by_id/resources --data-urlencode 'identifier[]=["test","1234","abcd","5678"]' --data-urlencode 'identifier[]=["my","other","identifier","value"]'

should search for those two records.

--
Dave Mayo (he/him)
Senior Digital Library Software Engineer
Harvard University > HUIT > LTS

From: <archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org> on behalf of Corey Schmidt <Corey.Schmidt at uga.edu>
Reply-To: "archivesspace_api_doc_adhoc at lyralists.lyrasis.org" <archivesspace_api_doc_adhoc at lyralists.lyrasis.org>
Date: Thursday, May 26, 2022 at 4:05 PM
To: "archivesspace_api_doc_adhoc at lyralists.lyrasis.org" <archivesspace_api_doc_adhoc at lyralists.lyrasis.org>
Subject: Re: [Archivesspace_api_doc_adhoc] find_by_id Endpoint Help

Dave,

I think I get what you’re pointing out, but having trouble composing something. Would it be something like for each ID component as its own SHELL variable? Like:

$ export ID1=["test"]

$ export ID2=["1234"]

$ export ID3=["abcd"]

$ export ID4=["5678"]

I tried doing it like the above, but I don’t think I know enough about how to encode each json array. 

$ curl -H "X-ArchivesSpace-Session: $SESSION" -g http://our_aspace_api_url/repositories/2/find_by_id/resources?identifier[]={[$ID1,$ID2,$ID3,$ID4]}

From: archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org <archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org> On Behalf Of Mayo, Dave
Sent: Thursday, May 26, 2022 11:49 AM
To: ArchivesSpace API Ad Hoc Working Group <archivesspace_api_doc_adhoc at lyralists.lyrasis.org>
Subject: Re: [Archivesspace_api_doc_adhoc] find_by_id Endpoint Help

[EXTERNAL SENDER - PROCEED CAUTIOUSLY]
Since we're using curl you probably don't want/need to manually construct the URL and urlencode, there's I believe an option for passing params? I'd have to look at the man page or Google examples.  

Get https://urldefense.proofpoint.com/v2/url?u=https-3A__aka.ms_AAb9ysg&d=DwMFAg&c=WO-RGvefibhHBZq3fL85hQ&r=_Mv1dY22K7jvT5MD7xjbvGVzRDOUMhx4WYcnPSIzYnE&m=WH5tOOw5lVrKhS8lmA2jPmMQ5hrGa5QlYeA71SIrfKmLMmzMOusTbjxMUh73VUe3&s=o5pHGNC3cCFzaowpX6ytMCOIWzjzIIHnmKBmDuQ5-K4&e=

From: mailto:archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org <mailto:archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org> on behalf of Mayo, Dave <mailto:dave_mayo at harvard.edu>
Sent: Thursday, May 26, 2022 11:47:43 AM
To: ArchivesSpace API Ad Hoc Working Group <mailto:archivesspace_api_doc_adhoc at lyralists.lyrasis.org>
Subject: Re: [Archivesspace_api_doc_adhoc] find_by_id Endpoint Help 
 
One thing is that you probably want to do "${IDENTIFIER}" to avoid escaping issues. But the big thing is that requests actually does some negotiation around "array params" that you have to manually handle in shell - so instead of passing in identifier as one array of json arrays, you'd actually want to pass each identifier directly as one array.

Basically, you would pass each serialized (and URL encoded) json array of components to a separate "identifier[]=" param and repeat as necessary. 

Get https://urldefense.proofpoint.com/v2/url?u=https-3A__aka.ms_AAb9ysg&d=DwMF-g&c=WO-RGvefibhHBZq3fL85hQ&r=_Mv1dY22K7jvT5MD7xjbvGVzRDOUMhx4WYcnPSIzYnE&m=JIWO7CnuIiNwxYkmDENr4-SsSBh4Og97Lukp8TXQl62aMjIYADti2QlkkILGdFGh&s=4Zcs12VNqP-zCxmrNV9uJywdheuJIowa5yHp3_c2efU&e=

From: mailto:archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org <mailto:archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org> on behalf of Corey Schmidt <mailto:Corey.Schmidt at uga.edu>
Sent: Thursday, May 26, 2022 10:43:35 AM
To: ArchivesSpace API Ad Hoc Working Group <mailto:archivesspace_api_doc_adhoc at lyralists.lyrasis.org>
Subject: Re: [Archivesspace_api_doc_adhoc] find_by_id Endpoint Help 
 
Hey Dave,

That’s alright, I spoke with Tommy Keswick at Caltech and we got something working, but it’s a cumbersome workaround using urllib.parse.quote and lots of extra lines of code.

That explains a lot why this was so frustrating! I’ve tried your examples and they work perfectly, thank you so so much!

I wonder if I couldn’t pick your brain for helping me write the SHELL examples for this? So far, I’ve got something like so:

$ export IDENTIFIER=['["test","1234","abcd","5678"]']
$ curl -H -g "X-ArchivesSpace-Session: $SESSION" "https://urldefense.proofpoint.com/v2/url?u=http-3A__our-5Faspace-5Fapi-5Furl_repositories_2_find-5Fby-5Fid_resources-3Fidentifier-255b-255d-3D-24IDENTIFIER&d=DwMFAg&c=WO-RGvefibhHBZq3fL85hQ&r=_Mv1dY22K7jvT5MD7xjbvGVzRDOUMhx4WYcnPSIzYnE&m=WH5tOOw5lVrKhS8lmA2jPmMQ5hrGa5QlYeA71SIrfKmLMmzMOusTbjxMUh73VUe3&s=1lhEnst_t4dNFrpIMglmWfNT_3jK6TyNfLOTsu3qs3o&e="

The above gets a response from ASpace, but doesn’t return any results like in the python example. 

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    17  100    17    0     0    482      0 --:--:-- --:--:-- --:--:--   500{"resources":[]}

Can you spot anything wrong with how I’m making the call? I changed the fourth ID from !@#$ to 5678 since it was difficult for SHELL to accept those characters

Corey
 
From: mailto:archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org <mailto:archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org> On Behalf Of Mayo, Dave
Sent: Wednesday, May 25, 2022 8:48 PM
To: ArchivesSpace API Ad Hoc Working Group <mailto:archivesspace_api_doc_adhoc at lyralists.lyrasis.org>
Subject: Re: [Archivesspace_api_doc_adhoc] find_by_id Endpoint Help
 
[EXTERNAL SENDER - PROCEED CAUTIOUSLY]
Hi Corey! 
 
Sorry for taking so long to get back to you!
 
The reason you’ve had no success is that, frankly, this aspect of the app’s functionality is bad? Bad, it is poorly implemented in a way that makes it basically impossible to suss out without reading the code.
 
What this function actually expects is: an array of strings with serialized JSON, each of which contains a JSON array of a four part id, null trailing components of which can be omitted.
 
Here’s a working example for two records from Harvard:

x.client.get('repositories/3/find_by_id/resources', params={'identifier[]': ['["ecb00051",null,null,null]', '["bf-test"]']}).json()

This returns:

{'resources': [{'ref': '/repositories/3/resources/7303'},
  {'ref': '/repositories/3/resources/9611'}]}

So, a working version of your query would be:

find_res_id = client.get(‘repositories/2/find_by_id/resources’, params={‘identifier’: [‘[“test”, “1234”, “abcd”, “!@#$”]’]})

Or less hatefully? Maybe?

import json
find_res_id = client.get(‘repositories/2/find_by_id/resources’, params={‘identifier’: [json.dumps([‘test’, ‘1234’, ‘abcd’, ‘!@#$’])]})

In any event, it’s a weird way to do business and I don’t care for it.
--
Dave Mayo (he/him)
Senior Digital Library Software Engineer
Harvard University > HUIT > LTS
 
From: <mailto:archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org> on behalf of Corey Schmidt <mailto:Corey.Schmidt at uga.edu>
Reply-To: "mailto:archivesspace_api_doc_adhoc at lyralists.lyrasis.org" <mailto:archivesspace_api_doc_adhoc at lyralists.lyrasis.org>
Date: Wednesday, March 23, 2022 at 4:23 PM
To: "mailto:archivesspace_api_doc_adhoc at lyralists.lyrasis.org" <mailto:archivesspace_api_doc_adhoc at lyralists.lyrasis.org>
Subject: [Archivesspace_api_doc_adhoc] find_by_id Endpoint Help
 
Dear all,

Hello, this is Corey Schmidt from the University of Georgia. I hope everyone is well and enjoying the slow warmup to Spring.

I've been hitting some roadblocks trying to write documentation for API endpoints and I wanted to askfor your help. For the https://urldefense.proofpoint.com/v2/url?u=https-3A__archivesspace.github.io_archivesspace_api_-3Fshell-23find-2Dresources-2Dby-2Dtheir-2Didentifiers&d=DwMFAw&c=WO-RGvefibhHBZq3fL85hQ&r=_Mv1dY22K7jvT5MD7xjbvGVzRDOUMhx4WYcnPSIzYnE&m=C2RTpp6a036fpnD59EANxOYTWgp62F2fxW6SOcn7HPqjzSghIQN4KWW5_v9UYUJR&s=jI_tQ6Z_E7reBBJrWf2gLSIXIMZoFQN7jLH3NgzihxQ&e=, I'm trying to find a resource with a four-part ID, but when I call the endpoint, it keeps giving me an error I can't pin down. Here's what I'm calling: 
from asnake.client import ASnakeClient
import asnake.logging as loggin
client = ASnakeClient(baseurl=as_api, username=as_un, password=as_pw)
client.authorize()

find_res_id = client.get('repositories/2/find_by_id/resources', params={'identifier[]': ['test', '1234', 'abcd', '!@#$']})
print(find_res_id.json(), find_res_id)
 
Here's the error message:
{'error': "Had some trouble parsing your request: unexpected token at 'test'"} <Response [400]>

It may be an issue with the requests package, but I'm not sure. I tested both ASnake and requests, and they gave the same error.

Any help/advice would be appreciated, thanks!

Corey
 
Corey Schmidt 
Special Collections Libraries | ArchivesSpace Project Manager
 
tel:7065428151 | mailto:Corey.Schmidt at uga.edu
 




More information about the Archivesspace_api_doc_adhoc mailing list