[Archivesspace_Users_Group] Adding an element with the API
Michelle Paquette
mpaquette at smith.edu
Fri Dec 18 14:15:40 EST 2020
Sure thing - I made a mistake in my effort to genericize it anyway and
missed a piece, so hopefully this helps. Good luck!
Michelle
On Fri, Dec 18, 2020 at 1:20 PM Karen Miller <k-miller3 at northwestern.edu>
wrote:
> 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>
> 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://urldefense.com/v3/__http:/requests.post__;!!Dq0X2DkFhyF93HkjWTBQKhk!FM_atqifl5z9WUFHxd0sKcmtc-C-nYZGSNcAH-NEN41PVE71q3zKB8X96v264rUBCqnUIrH0$>(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
>
> k-miller3 at northwestern.edu
>
> 874.467.3462
>
>
>
> _______________________________________________
> Archivesspace_Users_Group mailing list
> 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!FM_atqifl5z9WUFHxd0sKcmtc-C-nYZGSNcAH-NEN41PVE71q3zKB8X96v264rUBCpowfNuQ$>
>
>
>
>
> --
>
> Michelle Paquette
>
> (she/her)
>
> Metadata & Technical Services Archivist
>
> Special Collections
>
> Smith College
>
> 413-585-7029
>
> 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://urldefense.com/v3/__http:/bit.ly/SCLcovid-19__;!!Dq0X2DkFhyF93HkjWTBQKhk!FM_atqifl5z9WUFHxd0sKcmtc-C-nYZGSNcAH-NEN41PVE71q3zKB8X96v264rUBChRVz_a6$>
> for full details.
>
>
> Please send any questions you may have to libraryhelp at smith.edu and they
> will be answered as soon as possible. Special Collections reference
> service <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://urldefense.com/v3/__https:/www.smith.edu/student-life/health-wellness/coronavirus__;!!Dq0X2DkFhyF93HkjWTBQKhk!FM_atqifl5z9WUFHxd0sKcmtc-C-nYZGSNcAH-NEN41PVE71q3zKB8X96v264rUBCpNSNyOQ$>
> .
> _______________________________________________
> Archivesspace_Users_Group mailing list
> Archivesspace_Users_Group at lyralists.lyrasis.org
> http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group
>
--
Michelle Paquette
(she/her)
Metadata & Technical Services Archivist
Special Collections
Smith College
413-585-7029
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 for full details.
Please send any questions you may have to libraryhelp at smith.edu and they
will be answered as soon as possible. Special Collections reference service
<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://www.smith.edu/student-life/health-wellness/coronavirus>.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lyralists.lyrasis.org/pipermail/archivesspace_users_group/attachments/20201218/9b847b5a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: add_Compass_file_versions_plusthumbs.py
Type: text/x-python-script
Size: 3145 bytes
Desc: not available
URL: <http://lyralists.lyrasis.org/pipermail/archivesspace_users_group/attachments/20201218/9b847b5a/attachment.bin>
More information about the Archivesspace_Users_Group
mailing list