[Archivesspace_Users_Group] Adding an element with the API
Michelle Paquette
mpaquette at smith.edu
Fri Dec 18 13:04:22 EST 2020
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(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
>
--
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/d61217a9/attachment.html>
More information about the Archivesspace_Users_Group
mailing list