[Archivesspace_Users_Group] Update a Resource via the API

Corey Schmidt Corey.Schmidt at uga.edu
Wed Jul 22 12:47:06 EDT 2020


That did it. Thanks!
________________________________
From: archivesspace_users_group-bounces at lyralists.lyrasis.org <archivesspace_users_group-bounces at lyralists.lyrasis.org> on behalf of Kennedy, Nancy <KennedyN at si.edu>
Sent: Wednesday, July 22, 2020 12:25 PM
To: Archivesspace Users Group <archivesspace_users_group at lyralists.lyrasis.org>
Subject: Re: [Archivesspace_Users_Group] Update a Resource via the API

[EXTERNAL SENDER - PROCEED CAUTIOUSLY]

Hi Corey -
When you post your changes back, try this:

client.post('/repositories/5/resources/1814', json=resource)


Nancy Kennedy
Smithsonian Institution

________________________________
From: archivesspace_users_group-bounces at lyralists.lyrasis.org <archivesspace_users_group-bounces at lyralists.lyrasis.org> on behalf of Corey Schmidt <Corey.Schmidt at uga.edu>
Sent: Wednesday, July 22, 2020 11:54 AM
To: archivesspace_users_group at lyralists.lyrasis.org <archivesspace_users_group at lyralists.lyrasis.org>
Subject: [Archivesspace_Users_Group] Update a Resource via the API


External Email - Exercise Caution

Dear all,

Hello, this is Corey Schmidt, ArchivesSpace Project Manager at the University of Georgia. I hope you all are doing well and staying cool!

I'm trying to update records via the API using the Update a Resource endpoint (https://archivesspace.github.io/archivesspace/api/#update-a-resource<https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Farchivesspace.github.io%2Farchivesspace%2Fapi%2F%23update-a-resource&data=02%7C01%7CKennedyN%40si.edu%7C6c3a9025238e436ebeee08d82e579a60%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C637310301090865378&sdata=JAmmPBNTMiJzK8RdmtK0aIiRPoaqEaEAU1gHBbkQ4yA%3D&reserved=0>). I found Duke made a script (https://github.com/duke-libraries/archivesspace-duke-scripts/blob/master/python/asnake_update_all_resources_and_aos.py<https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fduke-libraries%2Farchivesspace-duke-scripts%2Fblob%2Fmaster%2Fpython%2Fasnake_update_all_resources_and_aos.py&data=02%7C01%7CKennedyN%40si.edu%7C6c3a9025238e436ebeee08d82e579a60%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C637310301090865378&sdata=ifr0tDYpc%2FjvBG2WGoiX8uedouLfZ5rGiyfUwLoVhUA%3D&reserved=0>) to do this very thing and I modeled my request on that example. I also found what I think is the code for the endpoint, found in backend/app/controllers/resource.rb file, line 114 (https://github.com/archivesspace/archivesspace/blob/0c4cb2dd263bbeacdbce70567ccbb86634cde769/backend/app/controllers/resource.rb#L114<https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Farchivesspace%2Farchivesspace%2Fblob%2F0c4cb2dd263bbeacdbce70567ccbb86634cde769%2Fbackend%2Fapp%2Fcontrollers%2Fresource.rb%23L114&data=02%7C01%7CKennedyN%40si.edu%7C6c3a9025238e436ebeee08d82e579a60%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C637310301090875376&sdata=WIMDFpICFKWlUmxIrsTRQnZZtnP3s2dV9JHR5RgVU1k%3D&reserved=0>).

However, no matter the combinations I try for the request, I'm getting a <Response [400]> error with the following message: "error":"Had some trouble parsing your request: unexpected token at <proceeds to quote entire json record>

The following is the code I'm running in python:


get_resource = client.get('/repositories/5/resources/1814')
print(get_resource.text)
resource = json.loads(get_resource.text)
resource["restrictions"] = True
print(json.dumps(resource))
update_resource = client.post('/repositories/5/resources/1814', json=json.dumps(resource))
# update_resource = client.post('/repositories/5/resources/1814', params={"id": 1814, "resource": json.dumps(resource), "repo_id": 5})
# the last line produces this error: <Response [400]> {"error":"Had some trouble parsing your request: A JSON text must at least contain two octets!"}
print(update_resource, update_resource.text)

I've attached the json file to this email.

Any help would be greatly appreciated. Thanks!

Sincerely,

Corey Schmidt
ArchivesSpace Project Manager
University of Georgia Special Collections Libraries
Email: Corey.Schmidt at uga.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lyralists.lyrasis.org/pipermail/archivesspace_users_group/attachments/20200722/c11a0f70/attachment.html>


More information about the Archivesspace_Users_Group mailing list