[Archivesspace_api_doc_adhoc] find_by_id Endpoint Help

Corey Schmidt Corey.Schmidt at uga.edu
Thu May 26 16:05:33 EDT 2022


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 Outlook for Android<https://aka.ms/AAb9ysg>
________________________________
From: archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org<mailto:archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org> <archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org<mailto:archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org>> on behalf of Mayo, Dave <dave_mayo at harvard.edu<mailto:dave_mayo at harvard.edu>>
Sent: Thursday, May 26, 2022 11:47:43 AM
To: ArchivesSpace API Ad Hoc Working Group <archivesspace_api_doc_adhoc at lyralists.lyrasis.org<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 Outlook for Android<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: archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org<mailto:archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org> <archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org<mailto:archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org>> on behalf of Corey Schmidt <Corey.Schmidt at uga.edu<mailto:Corey.Schmidt at uga.edu>>
Sent: Thursday, May 26, 2022 10:43:35 AM
To: ArchivesSpace API Ad Hoc Working Group <archivesspace_api_doc_adhoc at lyralists.lyrasis.org<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" "http://our_aspace_api_url/repositories/2/find_by_id/resources?identifier[]=$IDENTIFIER<http://our_aspace_api_url/repositories/2/find_by_id/resources?identifier%5b%5d=$IDENTIFIER>"

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: archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org<mailto:archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org> <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 <archivesspace_api_doc_adhoc at lyralists.lyrasis.org<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: <archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org<mailto:archivesspace_api_doc_adhoc-bounces at lyralists.lyrasis.org>> on behalf of Corey Schmidt <Corey.Schmidt at uga.edu<mailto:Corey.Schmidt at uga.edu>>
Reply-To: "archivesspace_api_doc_adhoc at lyralists.lyrasis.org<mailto:archivesspace_api_doc_adhoc at lyralists.lyrasis.org>" <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: "archivesspace_api_doc_adhoc at lyralists.lyrasis.org<mailto:archivesspace_api_doc_adhoc at lyralists.lyrasis.org>" <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 find_by_id resource endpoint<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



706-542-8151<tel:7065428151> | Corey.Schmidt at uga.edu<mailto:Corey.Schmidt at uga.edu>



[University of Georgia]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lyralists.lyrasis.org/pipermail/archivesspace_api_doc_adhoc/attachments/20220526/70859123/attachment-0001.html>


More information about the Archivesspace_api_doc_adhoc mailing list