<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Dave,<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
You're the best!! This works perfectly and makes sense. I have so much more to learn about curl, so I'm keeping the --data-urlencode and -G tricks up my sleeve for next time.<br>
<br>
I'll make sure to include these examples in the API documentation and update the existing python examples.<br>
<br>
Btw, I'm also looking for help writing an example of finding a resource via ARK ID. If anyone here on the working group uses ARKs and has some time to collaborate to help make a python/SHELL example for documentation, I would greatly appreciate it!<br>
<br>
Thanks again Dave!<br>
<br>
Corey<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org <archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org> on behalf of Mayo, Dave
 <dave_mayo@harvard.edu><br>
<b>Sent:</b> Thursday, May 26, 2022 4:31 PM<br>
<b>To:</b> ArchivesSpace API Ad Hoc Working Group <archivesspace_api_doc_adhoc@lyralists.lyrasis.org><br>
<b>Subject:</b> Re: [Archivesspace_api_doc_adhoc] find_by_id Endpoint Help</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">[EXTERNAL SENDER - PROCEED CAUTIOUSLY]<br>
<br>
<br>
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?<br>
<br>
Really, I think you’d want to do the following:<br>
<br>
curl -H "X-ArchivesSpace-Session: $SESSION" -G <a href="http://our_aspace_api_url/repositories/2/find_by_id/resources">
http://our_aspace_api_url/repositories/2/find_by_id/resources</a>  --data-urlencode "identifier[]=${IDENTIFIER}"<br>
<br>
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<br>
<br>
For multiple ids, you’d repeat the –data-urlencode with the same key and the other values.<br>
<br>
So for example:<br>
<br>
$ curl -H "X-ArchivesSpace-Session: $SESSION" -G <a href="http://our_aspace_api_url/repositories/2/find_by_id/resources">
http://our_aspace_api_url/repositories/2/find_by_id/resources</a> --data-urlencode 'identifier[]=["test","1234","abcd","5678"]' --data-urlencode 'identifier[]=["my","other","identifier","value"]'<br>
<br>
should search for those two records.<br>
<br>
--<br>
Dave Mayo (he/him)<br>
Senior Digital Library Software Engineer<br>
Harvard University > HUIT > LTS<br>
<br>
From: <archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org> on behalf of Corey Schmidt <Corey.Schmidt@uga.edu><br>
Reply-To: "archivesspace_api_doc_adhoc@lyralists.lyrasis.org" <archivesspace_api_doc_adhoc@lyralists.lyrasis.org><br>
Date: Thursday, May 26, 2022 at 4:05 PM<br>
To: "archivesspace_api_doc_adhoc@lyralists.lyrasis.org" <archivesspace_api_doc_adhoc@lyralists.lyrasis.org><br>
Subject: Re: [Archivesspace_api_doc_adhoc] find_by_id Endpoint Help<br>
<br>
Dave,<br>
<br>
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:<br>
<br>
$ export ID1=["test"]<br>
<br>
$ export ID2=["1234"]<br>
<br>
$ export ID3=["abcd"]<br>
<br>
$ export ID4=["5678"]<br>
<br>
I tried doing it like the above, but I don’t think I know enough about how to encode each json array.<br>
<br>
$ curl -H "X-ArchivesSpace-Session: $SESSION" -g <a href="http://our_aspace_api_url/repositories/2/find_by_id/resources?identifier[]={[$ID1,$ID2,$ID3,$ID4]}">
http://our_aspace_api_url/repositories/2/find_by_id/resources?identifier[]={[$ID1,$ID2,$ID3,$ID4]}</a><br>
<br>
From: archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org <archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org> On Behalf Of Mayo, Dave<br>
Sent: Thursday, May 26, 2022 11:49 AM<br>
To: ArchivesSpace API Ad Hoc Working Group <archivesspace_api_doc_adhoc@lyralists.lyrasis.org><br>
Subject: Re: [Archivesspace_api_doc_adhoc] find_by_id Endpoint Help<br>
<br>
[EXTERNAL SENDER - PROCEED CAUTIOUSLY]<br>
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.<br>
<br>
Get <a href="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=">
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=</a><br>
<br>
From: <a href="mailto:archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org">
mailto:archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org</a> <<a href="mailto:archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org">mailto:archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org</a>> on behalf of Mayo, Dave <<a href="mailto:dave_mayo@harvard.edu">mailto:dave_mayo@harvard.edu</a>><br>
Sent: Thursday, May 26, 2022 11:47:43 AM<br>
To: ArchivesSpace API Ad Hoc Working Group <<a href="mailto:archivesspace_api_doc_adhoc@lyralists.lyrasis.org">mailto:archivesspace_api_doc_adhoc@lyralists.lyrasis.org</a>><br>
Subject: Re: [Archivesspace_api_doc_adhoc] find_by_id Endpoint Help<br>
<br>
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.<br>
<br>
Basically, you would pass each serialized (and URL encoded) json array of components to a separate "identifier[]=" param and repeat as necessary.<br>
<br>
Get <a href="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=">
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=</a><br>
<br>
From: <a href="mailto:archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org">
mailto:archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org</a> <<a href="mailto:archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org">mailto:archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org</a>> on behalf of Corey Schmidt <<a href="mailto:Corey.Schmidt@uga.edu">mailto:Corey.Schmidt@uga.edu</a>><br>
Sent: Thursday, May 26, 2022 10:43:35 AM<br>
To: ArchivesSpace API Ad Hoc Working Group <<a href="mailto:archivesspace_api_doc_adhoc@lyralists.lyrasis.org">mailto:archivesspace_api_doc_adhoc@lyralists.lyrasis.org</a>><br>
Subject: Re: [Archivesspace_api_doc_adhoc] find_by_id Endpoint Help<br>
<br>
Hey Dave,<br>
<br>
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.<br>
<br>
That explains a lot why this was so frustrating! I’ve tried your examples and they work perfectly, thank you so so much!<br>
<br>
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:<br>
<br>
$ export IDENTIFIER=['["test","1234","abcd","5678"]']<br>
$ curl -H -g "X-ArchivesSpace-Session: $SESSION" "<a href="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=">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=</a>"<br>
<br>
The above gets a response from ASpace, but doesn’t return any results like in the python example.<br>
<br>
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current<br>
                                 Dload  Upload   Total   Spent    Left  Speed<br>
100    17  100    17    0     0    482      0 --:--:-- --:--:-- --:--:--   500{"resources":[]}<br>
<br>
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<br>
<br>
Corey<br>
<br>
From: <a href="mailto:archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org">
mailto:archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org</a> <<a href="mailto:archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org">mailto:archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org</a>> On Behalf Of Mayo, Dave<br>
Sent: Wednesday, May 25, 2022 8:48 PM<br>
To: ArchivesSpace API Ad Hoc Working Group <<a href="mailto:archivesspace_api_doc_adhoc@lyralists.lyrasis.org">mailto:archivesspace_api_doc_adhoc@lyralists.lyrasis.org</a>><br>
Subject: Re: [Archivesspace_api_doc_adhoc] find_by_id Endpoint Help<br>
<br>
[EXTERNAL SENDER - PROCEED CAUTIOUSLY]<br>
Hi Corey!<br>
<br>
Sorry for taking so long to get back to you!<br>
<br>
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.<br>
<br>
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.<br>
<br>
Here’s a working example for two records from Harvard:<br>
<br>
x.client.get('repositories/3/find_by_id/resources', params={'identifier[]': ['["ecb00051",null,null,null]', '["bf-test"]']}).json()<br>
<br>
This returns:<br>
<br>
{'resources': [{'ref': '/repositories/3/resources/7303'},<br>
  {'ref': '/repositories/3/resources/9611'}]}<br>
<br>
So, a working version of your query would be:<br>
<br>
find_res_id = client.get(‘repositories/2/find_by_id/resources’, params={‘identifier’: [‘[“test”, “1234”, “abcd”, “!@#$”]’]})<br>
<br>
Or less hatefully? Maybe?<br>
<br>
import json<br>
find_res_id = client.get(‘repositories/2/find_by_id/resources’, params={‘identifier’: [json.dumps([‘test’, ‘1234’, ‘abcd’, ‘!@#$’])]})<br>
<br>
In any event, it’s a weird way to do business and I don’t care for it.<br>
--<br>
Dave Mayo (he/him)<br>
Senior Digital Library Software Engineer<br>
Harvard University > HUIT > LTS<br>
<br>
From: <<a href="mailto:archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org">mailto:archivesspace_api_doc_adhoc-bounces@lyralists.lyrasis.org</a>> on behalf of Corey Schmidt <<a href="mailto:Corey.Schmidt@uga.edu">mailto:Corey.Schmidt@uga.edu</a>><br>
Reply-To: "<a href="mailto:archivesspace_api_doc_adhoc@lyralists.lyrasis.org">mailto:archivesspace_api_doc_adhoc@lyralists.lyrasis.org</a>" <<a href="mailto:archivesspace_api_doc_adhoc@lyralists.lyrasis.org">mailto:archivesspace_api_doc_adhoc@lyralists.lyrasis.org</a>><br>
Date: Wednesday, March 23, 2022 at 4:23 PM<br>
To: "<a href="mailto:archivesspace_api_doc_adhoc@lyralists.lyrasis.org">mailto:archivesspace_api_doc_adhoc@lyralists.lyrasis.org</a>" <<a href="mailto:archivesspace_api_doc_adhoc@lyralists.lyrasis.org">mailto:archivesspace_api_doc_adhoc@lyralists.lyrasis.org</a>><br>
Subject: [Archivesspace_api_doc_adhoc] find_by_id Endpoint Help<br>
<br>
Dear all,<br>
<br>
Hello, this is Corey Schmidt from the University of Georgia. I hope everyone is well and enjoying the slow warmup to Spring.<br>
<br>
I've been hitting some roadblocks trying to write documentation for API endpoints and I wanted to askfor your help. For the
<a href="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=">
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=</a>,
 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:<br>
from asnake.client import ASnakeClient<br>
import asnake.logging as loggin<br>
client = ASnakeClient(baseurl=as_api, username=as_un, password=as_pw)<br>
client.authorize()<br>
<br>
find_res_id = client.get('repositories/2/find_by_id/resources', params={'identifier[]': ['test', '1234', 'abcd', '!@#$']})<br>
print(find_res_id.json(), find_res_id)<br>
<br>
Here's the error message:<br>
{'error': "Had some trouble parsing your request: unexpected token at 'test'"} <Response [400]><br>
<br>
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.<br>
<br>
Any help/advice would be appreciated, thanks!<br>
<br>
Corey<br>
<br>
Corey Schmidt<br>
Special Collections Libraries | ArchivesSpace Project Manager<br>
<br>
tel:7065428151 | <a href="mailto:Corey.Schmidt@uga.edu">mailto:Corey.Schmidt@uga.edu</a><br>
<br>
<br>
<br>
_______________________________________________<br>
Archivesspace_api_doc_adhoc mailing list<br>
Archivesspace_api_doc_adhoc@lyralists.lyrasis.org<br>
<a href="http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_api_doc_adhoc">http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_api_doc_adhoc</a><br>
</div>
</span></font></div>
</body>
</html>