Rest Api: Creating node with "overwrite" option doesn't update properties...

cancel
Showing results for 
Search instead for 
Did you mean: 
Maxx
Member II

Rest Api: Creating node with "overwrite" option doesn't update properties...

Hi,

I'm doing some tests with Rest Api in Python.
Following the rest Api Explorer (https://api-explorer.alfresco.com/api-explorer/#!/nodes/createNode) and this link: https://docs.alfresco.com/6.2/concepts/dev-api-by-language-alf-rest-upload-file.html

I found the way to create node, uploading file with correct properties (working also with custom type and custom properties) using multipart/form-data in python with the "requests" library.

Here's a small example:

import os
import requests
from requests.auth import HTTPBasicAuth

USER = "username"
PASSWD = "password"


def upload_file():
    thisfolder = os.path.dirname(os.path.abspath(__file__))
    docfile = os.path.join(thisfolder, 'picture.jpg')
    node_id = "4efc2abb-e12c-4995-b2e4-f2ff5ee022ae"  # SAS uuid
    opUrl = 'nodes/%s/children' % node_id
    with open(docfile, 'rb') as file:
        files = {'filedata': file}
        createURL = 'http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/%s' % opUrl
        data = {
            "name": "picture.jpg",
            "nodeType": "cm:content",
            "overwrite": "true",
            "cm:title": "My Picture",
            "cm:description": "This is my picture",
        }
        response = requests.post(createURL, data=data, files=files, auth=HTTPBasicAuth(USER, PASSWD) )
        print(response)
        print(response.json)
        print(response.text)
        print(response.headers)


if __name__ == "__main__":
    upload_file()

My question concerns the "overwrite" option, it's incrementing the version when doing upload with the same "name", so i can change my file and version number is updated.

But "properties" (cm:title, cm:description,...) are never updated... so the overwrite option seems not concerning the "properties" but only the data... Very annoying when using custom properties or if i just want to update title or description. Is this a bug ? Am i missing an option ?
Thanks for help!

4 Replies
janv
Alfresco Employee

Re: Rest Api: Creating node with "overwrite" option doesn't update properties...

Hi,

Thanks for the suggestion. Yes, unfortunately, that does seem to be the case at the moment. See for example:

https://github.com/Alfresco/alfresco-remote-api/blob/master/src/main/java/org/alfresco/rest/api/impl... (and surrounding code).

If I'm undertanding you correctly you would like to use multi-part/form data to not only create a new file node (with content & properties) but also update the same file in a similar way. I think your suggestion would be to use POST with "overwrite" flag.

Alternatively, it could be done with PUT  in the same way if we implemented and extended https://issues.alfresco.com/jira/browse/REPO-146  idea to enable update of content & properties as a single request. The difference would be using "PUT" (with known node id) instead of "POST with overwrite" (with known node name).

I suggest you raise a new enhancement request in JIRA or update REPO-146 with more info if that might help. You could also provide a contribution with tests (and updates to the REST API Explorer).

In the meantime, can you make two calls ?

Thanks,

Jan

Maxx
Member II

Re: Rest Api: Creating node with "overwrite" option doesn't update properties...

Hi Jan,

Thanks for your answer.


@janv wrote:

If I'm undertanding you correctly you would like to use multi-part/form data to not only create a new file node (with content & properties) but also update the same file in a similar way. I think your suggestion would be to use POST with "overwrite" flag.

Alternatively, it could be done with PUT  in the same way if we implemented and extended https://issues.alfresco.com/jira/browse/REPO-146  idea to enable update of content & properties as a single request. The difference would be using "PUT" (with known node id) instead of "POST with overwrite" (with known node name).

Indeed, i could use "PUT", but "PUT" needs an existing node... In my case, using the POST with the "overwrite" flag allows me not to check if node already exists... so i could create or update existing node with the same api call. It seems logical to me that overwrite option allows to update properties...
In the case of using PUT, i've first to do a POST without "overwrite", catching errors and in case of 409 error, searching for the node_id then doing a PUT to update content and properties...

I'm just a user, i do not feel comfortable with Java so do not feel able to provide contribution... just providing an idea for an eventual enhancement.


udaikumar26
Customer

Re: Rest Api: Creating node with "overwrite" option doesn't update properties...

Hi,

Can anyone help me with this issue.

I am not able to use the "overwrite" flag in my post request. when i have that flag i am getting the following error,

Could not read content from HTTP request body: Unrecognized field \"overwrite\" (class org.alfresco.rest.api.model.Node)

 

I am using alfresco 6.2.2

EddieMay
Alfresco Employee

Re: Rest Api: Creating node with "overwrite" option doesn't update properties...

Hi @udaikumar26 

If you're updating an existing node I think you should be using PUT instead of POST? See https://api-explorer.alfresco.com/api-explorer/#/nodes/updateNode 

HTH,

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!