[Archivesspace_Users_Group] help with API route for archival object notes
Karen Miller
k-miller3 at northwestern.edu
Wed Jul 1 10:54:03 EDT 2020
Hi Chris,
Yes, I think you understood my problem exactly! I am using Python with the API and I’m not very familiar with either Python or JSON. I am pretty adept at SQL, so I am pretty sure I can identify and export the URIs of archival objects that have notes that contain HTML. It’s the issue of identifying that part of the JSON for Python to understand that I’m struggling with.
I think I’ll read up a bit more on dictionaries (I’ve been plowing through a book about beginning Python but gave up after reading about lists) and look into using the for loop with my notes. If I run into another brick wall, I’ll probably be back. Thanks!
Karen
From: archivesspace_users_group-bounces at lyralists.lyrasis.org <archivesspace_users_group-bounces at lyralists.lyrasis.org> On Behalf Of Chris Mayo
Sent: Wednesday, July 01, 2020 7:13 AM
To: Archivesspace Users Group <archivesspace_users_group at lyralists.lyrasis.org>
Subject: Re: [Archivesspace_Users_Group] help with API route for archival object notes
Hi Karen,
To be a little more specific, I'm getting the sense (since I've struggled with needing to update some notes but not others as well) that what you're asking is how to create the path to a specific note when you don't know in advance which note it's going to be.
If you want to only modify notes that have html tags in them, you'll need to give it the path to ['notes'] part of the structure, and then run a for-loop, since that part is a list. You can ask it to look at each note in the list of notes and only make changes if it comes across one of the bad tags you're looking for. In python this would look something like
for note in json['notes']
if 'bad tag' in note:
modify the note
I'm afraid that I am enough of a scripter to only use Python to interact with the API, if you're using Postman or anything like that I'm not entirely sure how you'd accomplish something like this, and maybe somebody else can advise.
The thing that was hardest for me about learning how to interact with JSON was coming to realize that as far as the scripting language is concerned, anything inside square brackets [ ] is a list, and anything inside curly braces { } is a dictionary, and they can be interacted with as those data types.
Hope that helps, and sorry if I misread what your problem was!
Chris
On Tue, Jun 30, 2020 at 7:35 PM James Bullen <james at hudmol.com<mailto:james at hudmol.com>> wrote:
Hi Karen,
The general rule is that anything you can GET from a uri can be modified and POSTed back to update it.
So, GET the JSON for the archival_object as you are doing. Then modify the JSON (in this case the notes bit of it) to look how you want. Then POST it back to the same uri.
Notes are nested subrecords (as are dates and others). These don’t have a life of their own, they are really just repeating parts of the top level record that they are contained within.
Hope that helps..
Cheers,
James
On Jul 1, 2020, at 8:22 AM, Karen Miller <k-miller3 at northwestern.edu<mailto:k-miller3 at northwestern.edu>> wrote:
Good morning, ArchivesSpace users.
I am a cataloger (*not* a developer) using the API to update ArchivesSpace. So far I’ve figured out how to add LCCNs to the authority_Id of Agent records and do a couple more updates that, in retrospect, were pretty simple.
The next task I’d like to tackle, however, just seems like maybe it can’t be done. We’ve got a lot of notes with html tags in them and I would like to update those to valid tags. I can get the JSON for the notes in any particular archival object, but I don’t know how to specify the route to the note to change it. The JSON looks like this:
'notes': [{'content': ['This is a note with a bad <i>tag</i>'],
'jsonmodel_type': 'note_singlepart',
'persistent_id': '75ba0ec57e374b8b154551a69b4c311f',
'publish': True,
'type': 'abstract'},
{'jsonmodel_type': 'note_multipart',
'persistent_id': '66afa07b3214260078123236bbe1ff27',
'publish': True,
'subnotes': [{'content': 'This is a dippy note.',
'jsonmodel_type': 'note_text',
'publish': True}],
'type': 'scopecontent'}],
I got this using the route ‘repositories/10/archival_objects/489763’, but I don’t know how to specify the note that I want in the JSON. For the agent authority_id I used the route ‘‘/agents/people/<somenumber> and specified the field like this:
['names'][0]['authority_id']
I’m hoping this is an easy question for somebody with more experience with the API and (especially) with JSON than I. I’m a little afraid the answer is that it can’t be done. Any advice will be appreciated!
Karen
Karen D. Miller
Monographic Cataloger/Metadata Specialist
Northwestern University Libraries
Northwestern University
1970 Campus Drive
Evanston, IL 60208
www.library.northwestern.edu<http://www.library.northwestern.edu/>
k-miller3 at northwestern.edu<mailto:k-miller3 at northwestern.edu>
874.467.3462
_______________________________________________
Archivesspace_Users_Group mailing list
Archivesspace_Users_Group at lyralists.lyrasis.org<mailto:Archivesspace_Users_Group at lyralists.lyrasis.org>
http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group<https://urldefense.com/v3/__http:/lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group__;!!Dq0X2DkFhyF93HkjWTBQKhk!GHVM_zgdGWk7RlGW_XLrX9EIzhezlhNaRMKKNGaqaMq66tyJvJOSvVfXuhP8WDsYexmrjkyf$>
_______________________________________________
Archivesspace_Users_Group mailing list
Archivesspace_Users_Group at lyralists.lyrasis.org<mailto:Archivesspace_Users_Group at lyralists.lyrasis.org>
http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group<https://urldefense.com/v3/__http:/lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group__;!!Dq0X2DkFhyF93HkjWTBQKhk!GHVM_zgdGWk7RlGW_XLrX9EIzhezlhNaRMKKNGaqaMq66tyJvJOSvVfXuhP8WDsYexmrjkyf$>
--
Chris Mayo
Digital Production Librarian
Boston College
chris.mayo at bc.edu<mailto:chris.mayo at bc.edu>
pronouns: they/them/theirs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lyralists.lyrasis.org/pipermail/archivesspace_users_group/attachments/20200701/9efa7338/attachment.html>
More information about the Archivesspace_Users_Group
mailing list