[Archivesspace_Users_Group] curl help
Steven Majewski
sdm7g at virginia.edu
Wed Jan 21 13:04:17 EST 2015
Chris Fitzpatrick has a bunch of examples of Ruby code using RestClient and the AS backend API
at: https://gist.github.com/cfitz
but if you want to do a bulk export of a repo, there is a script in the current release: archivesspace/scripts/ead_export.sh
Usage: export.rb <username> <password> <repository_id>
which will make a zip file of all of the resources exported from a repository.
The ruby code is here ( as another example of using the API ):
https://github.com/archivesspace/archivesspace/blob/master/launcher/ead_export/lib/ead_export.rb
Before finding cfitz more thorough delete_repo https://gist.github.com/cfitz/4fefcfa659ef18bfbe6c
I was using this shell script to delete all resources from a repository ( so we could retest imports
after code patches ). I’m including it here as another example of scripting the API with curl from
the shell.
REPO=http://localhost:8089
#
REPO_ID=$1
#
user=admin
pass=admin
session=$(curl -s -F password="$pass" "$REPO/users/$user/login" |
sed 's|.*"session":"\([a-z0-9]*\)".*|\1|g')
echo "Repo: $REPO"
echo "Session $session" 1>&2
curl -H "X-ArchivesSpace-Session: $session" "$REPO/repositories/$REPO_ID" | jq .
DELETE='-X DELETE'
for ID in $( curl -H "X-ArchivesSpace-Session: $session" "$REPO/repositories/$REPO_ID/resources?all_ids=true" | tail -1 | tr '[],' ' ' )
do
curl -H "X-ArchivesSpace-Session: $session" $DELETE $REPO/repositories/$REPO_ID/resources/$ID | jq .
done
I highly recommend jq http://stedolan.github.io/jq/ for pretty printing and exploring json output from
the API. ‘jq . ‘ (in the example above just does a json pretty print, but you can also select particular fields:
R=http://localhost:8089/repositories
./curl_as_osx admin admin $R | jq '.[].repo_code’ # list repository codes
"uva-sc"
"RG_3"
"Legacy"
"lsc-test"
"sdm7g-test"
"uva-hsl"
"tsd-test"
"mhm8m-test"
"uvalaw-test"
"img7u-test"
"elg3e-test"
# get repo-id # from repo-code
./curl_as_osx admin admin $R | jq '.[0:-1]| map(select( .repo_code == "img7u-test" ))|.[0].uri'
"/repositories/12"
And, although I haven’t tried it, you could pull json from AS with a GET, edit a field on the fly with jq, and post the modified
json back to ArchivesSpace. However, the jq syntax can be difficult. Chris’s bulk_update
https://gist.github.com/cfitz/9eb97ad3f6dd772f875f
may be a better way. It does a merge on the ruby hash of the parsed JSON, which may be a bit easier to follow than jq syntax.
— Steve Majewski
On Jan 21, 2015, at 8:57 AM, Ben Goldman <bmg17 at psu.edu> wrote:
> Noah, thanks for the feedback. It's good to know I am on the right track. I was able to get that to work. And in fact, we were able to build on that and perform a mass export of the finding aids, though for some reason only 1914 of 1940 resources were exported.
>
> Now I am wondering how I might adjust the script to export the XML file with a file name that uses the value of the resource's identifier field rather than the ASpace system identifier for the record.
>
> I agree that it would be great to see the documentation on the API/cURL expand in the way you outline. I feel there is so much more I could do with the API, that I do not fully understand the capabilities here. I just know being able to mass export finding aids with one script is pretty damn cool.
>
> Thanks,
> Ben
>
>
> From: "Noah Huffman" <noah.huffman at duke.edu>
> To: "Archivesspace Users Group" <archivesspace_users_group at lyralists.lyrasis.org>
> Sent: Tuesday, January 20, 2015 9:32:56 AM
> Subject: Re: [Archivesspace_Users_Group] curl help
>
> Hi Ben,
>
> I’m a curl novice too, but your last example should work to output a single EAD file to the current directory. The only thing I see is that in your example you have a single quote to begin the URL and a double quote to end it. Maybe change the double quote at the very end to a single quote, or make both double quotes?
>
> Something like:
>
> curl --output “EADfilename.xml” -H "X-ArchivesSpace-Session: $TOKEN" ‘http://aspace1prod.dlt.psu.edu:9089/repositories/3/resource_descriptions/9235.xml?numbered_cs=true’
>
> This works for me in Windows Powershell.
>
> More generally, I think it would be helpful for noobs like us if the ASpace documentation included a short primer (with examples) on how to use curl to interact with the API. This could supplement the existing API documentation at:http://archivesspace.github.io/archivesspace/doc/file.API.html
>
> The ASpace developer screencasts are a good reference if you haven’t seen them, particularly this one http://youtu.be/iKd4ZME1uIE?list=PLJFitFaE9AY_DDlhl3Kq_vFeX27F1yt6I
>
> -Noah
>
> ================
> Noah Huffman
> Archivist for Metadata and Encoding
> David M. Rubenstein Rare Book & Manuscript Library
> Duke University
> noah.huffman at duke.edu
> 919-660-5982
> http://library.duke.edu/rubenstein/
>
>
>
>
> From: archivesspace_users_group-bounces at lyralists.lyrasis.org [mailto:archivesspace_users_group-bounces at lyralists.lyrasis.org] On Behalf Of Ben Goldman
> Sent: Monday, January 19, 2015 3:56 PM
> To: Archivesspace Users Group
> Subject: [Archivesspace_Users_Group] curl help
>
> Hey All,
>
> Wondering if anyone can help a cURL novice work through the process of exporting a finding aid from the API. I've reviewed some of the past emails on this subject from Noah and Kevin but I am still hung up somewhere. A quick recap:
>
> Login:
>
> curl -F password='***' http://aspace1prod.dlt.psu.edu:9089/users/bmg17/login
>
> Save token:
>
> token=*****
>
> Just to verify I know what I am doing, try retrieving a resource record:
>
> curl -H "X-ArchivesSpace-Session: $token" 'http://aspace1prod.dlt.psu.edu:9089/repositories/3/resources/1352'
>
> Success: {"lock_version":0,"title":"Frederick R. Matson papers","publish":true, etc. etc. etc.
>
> I'm not going to do a mass publish yet, but went ahead and retrieved all the ids anyway:
>
>
> curl -H "X-ArchivesSpace-Session: $token" 'http://aspace1prod.dlt.psu.edu:9089/repositories/3/resources?all_ids=true'
>
> A long list. Including a very short resource record with the id of 9235. Now I am wondering exactly how I put this together to export just this one. This is the command mentioned in previous messages:
>
> curl --output “resource_#1.xml” -H "X-ArchivesSpace-Session: $TOKEN" 'http://aspace1prod.dlt.psu.edu:9089/repositories/3/resource_descriptions/$ids.xml?numbered_cs=true"
>
> I assume if I'm just exporting one, I can replace '$ids" with the actual number (9235), and that the value following --output can be whatever I want the finding aid file name to be. Is all this correct? And where would this actually output the file to?
>
> Thanks, in advance, for any help.
>
> -Ben
>
>
>
> Ben Goldman
> Digital Records Archivist
> Penn State University Libraries
> University Park, PA
> 814-863-8333
> http://www.libraries.psu.edu/psul/speccolls.html
>
>
> _______________________________________________
> Archivesspace_Users_Group mailing list
> Archivesspace_Users_Group at lyralists.lyrasis.org
> http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group
>
> _______________________________________________
> Archivesspace_Users_Group mailing list
> Archivesspace_Users_Group at lyralists.lyrasis.org
> http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lyralists.lyrasis.org/pipermail/archivesspace_users_group/attachments/20150121/40eb190a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4943 bytes
Desc: not available
URL: <http://lyralists.lyrasis.org/pipermail/archivesspace_users_group/attachments/20150121/40eb190a/attachment.bin>
More information about the Archivesspace_Users_Group
mailing list