[Archivesspace_Users_Group] Adding an element with the API

Custer, Mark mark.custer at yale.edu
Fri Dec 18 14:45:10 EST 2020


Karen,

In addition to Michelle's great advice, if you're adding notes, you'll want to follow the same model of creating the whole note and posting it.

Here's an ugly mocked-up example:

                   new_sc_note_content = "Whatever note you're adding"

                    note = {"jsonmodel_type": "note_multipart", "type": "scopecontent", "publish": True,
                                    "subnotes": [{"jsonmodel_type": "note_text",
                                     "content": new_sc_note_content,
                                     "publish": True}]}

                    record_json["notes"].append(note)

But notes are trickiest, since there are a few different ways that ArchivesSpace models those depending on the note type, and if there are lists, etc.

When working with the API and ArchivesSpace this way, I'd suggest going through the following steps (rather than trying to read the codebase and the internal data schemas):

  1.  Create the data that you want to add to ASpace directly in the staff interface (e.g. create a digital object with those two file URIs, and the two notes, etc.)
  2.  Also create another record that just has the required data fields (e.g. just a digital object with a title or whatever is required, and not the extra stuff you want to add)
  3.  Use the API to get both of those objects and check out what the JSON looks like.
  4.  Then, write your script to model the data the same way (and, the reason to grab an object with a minimal amount of data is just to see if you need to create a new data field like for "notes", of if that key will already be present even when empty, etc.).
  5.  Check out the results after you post your new data to a variety of existing records and make sure that your script won't overwrite any existing data that you don't want to erase (e.g. if you're adding a thumbnail URI, you'll want to make sure that you "append" it, as in Michelle's example.)

And, of course, always best if you have a test environment to do this.  If not, you could try things out on one of the other TEST instances out there 🙂

Mark



________________________________
From: archivesspace_users_group-bounces at lyralists.lyrasis.org <archivesspace_users_group-bounces at lyralists.lyrasis.org> on behalf of Karen Miller <k-miller3 at northwestern.edu>
Sent: Friday, December 18, 2020 1:20 PM
To: Archivesspace Users Group <archivesspace_users_group at lyralists.lyrasis.org>
Subject: Re: [Archivesspace_Users_Group] Adding an element with the API


Thank you, Michelle!



Yes, if you don’t mind sending the script, I’d really appreciate it. This looks like what I need, but I think having the script might be useful.



Karen



From: archivesspace_users_group-bounces at lyralists.lyrasis.org <archivesspace_users_group-bounces at lyralists.lyrasis.org> On Behalf Of Michelle Paquette
Sent: Friday, December 18, 2020 12:04 PM
To: Archivesspace Users Group <archivesspace_users_group at lyralists.lyrasis.org>
Subject: Re: [Archivesspace_Users_Group] Adding an element with the API



Hi Karen,



I think you're getting the error because it's looking to set those values on a file version that already exists, and the file version doesn't exist yet.



I have a script that does something similar and what I've done is create a definition for a new file version, and then done an "append" on the record in question (record being the digital object).



def add_thumbnail(thumbnail_uri):

    note_dict =  {'file_uri': thumbnail_uri,

    'publish': True, #change to False if you do not want the file version to be published.

    'xlink_actuate_attribute': 'onLoad',

    'xlink_show_attribute': 'embed',

    'use_statement': 'image-thumbnail',

    'jsonmodel_type': 'file_version'

    }





Later I have record['file_versions'].append(add_thumbnail)



thumbnail_uri is coming from a spreadsheet. If seeing the full script is helpful for you please let me know and I'd be happy to share it with you.



Best,

Michelle



On Fri, Dec 18, 2020 at 12:48 PM Karen Miller <k-miller3 at northwestern.edu<mailto:k-miller3 at northwestern.edu>> wrote:

I hope there are still some folks around to think about an API problem I’m having!



We’re updating URLs in our digital objects. I can easily update the URL that exists in digital objects, using Python syntax like this:



digital_object_json['file_versions'][0]['file_uri'] = permalink



post_record = requests.post<https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.com%2Fv3%2F__http%3A%2Frequests.post__%3B!!Dq0X2DkFhyF93HkjWTBQKhk!FM_atqifl5z9WUFHxd0sKcmtc-C-nYZGSNcAH-NEN41PVE71q3zKB8X96v264rUBCqnUIrH0%24&data=04%7C01%7Cmark.custer%40yale.edu%7C36863ac5286d4811913908d8a3818cab%7Cdd8cbebb21394df8b4114e3e87abeb5c%7C0%7C0%7C637439124135695886%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=WNREmt6ejEX6yL8fWcKfO3uy2k%2BVAIycuo2Kcy3DO5U%3D&reserved=0>(f"{api_url}/{digital_object_uri}", headers=headers, json=digital_object_json).json()



where “permalink” is a value I’ve read in from a spreadsheet. This works just fine for me. But I wanted to get fancy and add a second URL as a thumbnail (I can do this through the staff interface and it works the way I anticipate) as well as a couple of notes. I thought that the syntax would be straightforward:



digital_object_json['file_versions'][1]['file_uri'] = thumbnail

digital_object_json['notes'][0]['content'] = note1

digital_object_json['notes'][0]['jsonmodel_type'] = 'note_digital_object'

digital_object_json['notes'][0]['publish'] = False

digital_object_json['notes'][0]['type'] = 'note'

digital_object_json['notes'][1]['content'] = note2

digital_object_json['notes'][1]['jsonmodel_type'] = 'note_digital_object'

digital_object_json['notes'][1]['publish'] = False

digital_object_json['notes'][1]['type'] = 'note'

where “thumbnail”, “note1”, and “note2” are values from the spreadsheet. However, I’m getting this error for each of these statements:



IndexError: list index out of range



because those aren’t already in the JSON that I’ve retrieved. How do I add to the JSON? I’m not experienced enough with JSON or with Python and am looking for some basic help. Any advice will be appreciated!



Best regard and happy holidays,

Karen





Karen D. Miller

Monographic Cataloger/Metadata Specialist

Northwestern University Libraries

Northwestern University

1970 Campus Drive

Evanston, IL 60208

www.library.northwestern.edu<https://nam12.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.library.northwestern.edu%2F&data=04%7C01%7Cmark.custer%40yale.edu%7C36863ac5286d4811913908d8a3818cab%7Cdd8cbebb21394df8b4114e3e87abeb5c%7C0%7C0%7C637439124135695886%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=RIPaUDLm4MzCHuo22Dl%2BjbZC8%2FYBHQRKIh1zCtDRmEI%3D&reserved=0>

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://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.com%2Fv3%2F__http%3A%2Flyralists.lyrasis.org%2Fmailman%2Flistinfo%2Farchivesspace_users_group__%3B!!Dq0X2DkFhyF93HkjWTBQKhk!FM_atqifl5z9WUFHxd0sKcmtc-C-nYZGSNcAH-NEN41PVE71q3zKB8X96v264rUBCpowfNuQ%24&data=04%7C01%7Cmark.custer%40yale.edu%7C36863ac5286d4811913908d8a3818cab%7Cdd8cbebb21394df8b4114e3e87abeb5c%7C0%7C0%7C637439124135705839%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=hx1oH%2BpYXKdeeztflGyWWPnawwbIBnCtX2CExfOByEE%3D&reserved=0>




--

Michelle Paquette

(she/her)

Metadata & Technical Services Archivist

Special Collections

Smith College

413-585-7029

mpaquette at smith.edu<mailto:mpaquette at smith.edu>



Please note: In light of COVID-19, the Libraries are offering contactless pickup, and all other services will continue to be offered remotely. Visit bit.ly/SCLcovid-19<https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.com%2Fv3%2F__http%3A%2Fbit.ly%2FSCLcovid-19__%3B!!Dq0X2DkFhyF93HkjWTBQKhk!FM_atqifl5z9WUFHxd0sKcmtc-C-nYZGSNcAH-NEN41PVE71q3zKB8X96v264rUBChRVz_a6%24&data=04%7C01%7Cmark.custer%40yale.edu%7C36863ac5286d4811913908d8a3818cab%7Cdd8cbebb21394df8b4114e3e87abeb5c%7C0%7C0%7C637439124135705839%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=RfigzGk07udEYeH4pzgwpAcWjiJv167DNmPZ%2Bkkv8%2Bw%3D&reserved=0> for full details.

Please send any questions you may have to libraryhelp at smith.edu<mailto:libraryhelp at smith.edu> and they will be answered as soon as possible. Special Collections reference service<mailto:specialcollections at smith.edu> is active, but limited. For information about Smith College’s response to Covid-19, please visit the college’s official website<https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.com%2Fv3%2F__https%3A%2Fwww.smith.edu%2Fstudent-life%2Fhealth-wellness%2Fcoronavirus__%3B!!Dq0X2DkFhyF93HkjWTBQKhk!FM_atqifl5z9WUFHxd0sKcmtc-C-nYZGSNcAH-NEN41PVE71q3zKB8X96v264rUBCpNSNyOQ%24&data=04%7C01%7Cmark.custer%40yale.edu%7C36863ac5286d4811913908d8a3818cab%7Cdd8cbebb21394df8b4114e3e87abeb5c%7C0%7C0%7C637439124135715797%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=195QZvejKeXdZBahvGT16sI03iyP7qZkkbJNfRmmm7c%3D&reserved=0>.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lyralists.lyrasis.org/pipermail/archivesspace_users_group/attachments/20201218/6a868fde/attachment.html>


More information about the Archivesspace_Users_Group mailing list