archivesspace-labs / ArchivesSnake

A client library for working with the ArchivesSpace API
https://archivesspace-labs.github.io/ArchivesSnake/
Other
78 stars 13 forks source link

Unable to create new digital object with a note #41

Closed bonniegee closed 3 years ago

bonniegee commented 3 years ago

I'm unable to create a new digital object using the ArchivesSnake client, if the digital object has a note.

This code:

data = {"jsonmodel_type": "digital_object",
            "is_slug_auto": True,
            "file_versions": [{"jsonmodel_type": "file_version",
                               "is_representative": False,
                               "file_uri": str(file_uri),
                               "xlink_actuate_attribute": "onRequest",
                               "xlink_show_attribute": "new",
                               "file_format_name": "pdf",
                               "file_format_version": "Generic PDF", "publish": True}],
           "restrictions": False,
           "notes": [{"jsonmodel_type": "note_digital_object",
                      "content": [str(aip_uuid)],
                      "type": "originalsloc", "publish": False}],
                      "title": str(title),
                      "digital_object_id": str(dip_uuid)}
aspace.client.post(dao_url, json=data)

I get the following error:

'Can\'t unambiguously match {"content"=>["a23c9c77-19be-4e77-bc3a-aad7ef45b07a"], "type"=>"originalsloc", "publish"=>false} against schema types: ["JSONModel(:note_bibliography) object", "JSONModel(:note_digital_object) object"]. Resolve this by adding a \'jsonmodel_type\' property to {"content"=>["a23c9c77-19be-4e77-bc3a-aad7ef45b07a"], "type"=>"originalsloc", "publish"=>false}

As noted above, I am providing the jsonmodel_type property.

If I use the python requests library to post the same, it's successful:

headers = {'X-ArchivesSpace-Session': aspace_token}
data = {"jsonmodel_type": "digital_object",
            "is_slug_auto": True,
            "file_versions": [{"jsonmodel_type": "file_version",
                               "is_representative": False,
                               "file_uri": str(file_uri),
                               "xlink_actuate_attribute": "onRequest",
                               "xlink_show_attribute": "new",
                               "file_format_name": "pdf",
                               "file_format_version": "Generic PDF", "publish": True}],
           "restrictions": False,
           "notes": [{"jsonmodel_type": "note_digital_object",
                      "content": [str(aip_uuid)],
                      "type": "originalsloc", "publish": False}],
                      "title": str(title),
                      "digital_object_id": str(dip_uuid)}
requests.post(dao_url, json=data, headers=headers)

I think "jsonmodel_type": "note_digital_object" is getting stripped somewhere in ArchivesSnake, but I'm not 100% sure what's happening.

pobocks commented 3 years ago

That's bizarre - I'll try to replicate this. But as far as I know, and I should know pretty far, ASnake doesn't alter json values prior to handing them off to requests. The only transformation done is altering params which get passed in as lists to have '[]' on the end of them.

https://github.com/archivesspace-labs/ArchivesSnake/blob/master/asnake/client/web_client.py#L19

bonniegee commented 3 years ago

Thanks @pobocks! I (and @helrond ) did some further testing and the issue was indeed on my end--I fed ArchivesSnake the full URL instead of the URI, which is what caused the issue.