update document name with REST API

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
yosrioh
Active Member

update document name with REST API

Jump to solution

i am trying to update the name of a document in alfresco using the webscript :

POST    /alfresco/service/api/node/content/workspace/SpacesStore/

i am getting a 405 responce from the server .

is this the right webscript to update a node properties ?

this is the code i am using to send the request

           HttpPost httppost = new HttpPost(urlString);
           JSONObject json = new JSONObject();
           json.put("ContentType", "application/json");
           json.put("name", "yosri");
           
           HttpEntity e = new StringEntity(json.toString());
           httppost.setEntity(e);
           HttpResponse response = httpclient.execute(httppost);

1 Solution

Accepted Solutions
alxgomz
Established Member

Re: update document name with REST API

Jump to solution

SpacesStore

10 Replies
alxgomz
Established Member

Re: update document name with REST API

Jump to solution

Hi yosrioh_

You cannot update properties this way. You can use instead

POST /alfresco/s/api/metadata/node/{store_type}/{store_id}/{id}

If you're using a recent Alfresco version (5.2.something) you can then use the newer v1 API:

Alfresco Content Services REST API Explorer 

Or you can write a tiny webscript using java or javascript API to match exactly your needs.

yosrioh
Active Member

Re: update document name with REST API

Jump to solution

hello

thx for your answer i tried POST /alfresco/s/api/metadata/node/{store_type}/{store_id}/{id} and i got a 200 responce from server but the document title isn't changing

is there a problem with the Json object im sending ?

           JSONObject json = new JSONObject();

           json.put("ContentType", "application/json");
           json.put("fileName", "yosri");
           
           HttpEntity e = new StringEntity(json.toString());
           httppost.setEntity(e);
           HttpResponse response = httpclient.execute(httppost);
alxgomz
Established Member

Re: update document name with REST API

Jump to solution

Yes you need a json object as expected by the webscript. It must contains a "properties" element and appropriate properties set in it.

Something like:

{
  "properties": {
      "cm:description": "Some desc"
  }
}

yosrioh
Active Member

Re: update document name with REST API

Jump to solution

hello

thx for your answer i tried to put a json format like you suggested but i got a 404 not a valid node

i am using this exemple i found

what im i doing wrong ?

     Abdera abdera = new Abdera();
     AbderaClient client = new AbderaClient(abdera);

     String uri = "http://192.168.100.231:8080/alfresco/service/api/metadata/node/workspace/SpaceStore/"+nodeRef+"?alf_ticket="+ticket;
        uri = uri.replaceAll("\"", "");
     String jsonMessage ="{\"properties\":{\"cm:title\":\"Texas\",\"cm:description\":\"Descripcion de Texas\"}}";
      InputStream is =new ByteArrayInputStream(jsonMessage.getBytes(StandardCharsets.UTF_8));

     RequestOptions options = new RequestOptions();
     options.setHeader("Content-Type", "application/json");

    ClientResponse c= client.post(uri, is, options);
    System.out.println( c.getStatus());
alxgomz
Established Member

Re: update document name with REST API

Jump to solution

The error message says it all...

You're trying to work on a node that doesn't exist. Check that "nodeRef" returns a *valid* node reference.

you can also use your tomcat access log to see the full URL accessed by your code, and check the nodeRef actually exists in the node browser.

yosrioh
Active Member

Re: update document name with REST API

Jump to solution

i checked the tomcat log like you suggested and i found the url sent to server

192.168.10.87 - - [17/Aug/2017:12:47:18 +0100] "POST /alfresco/service/api/login HTTP/1.1" 200 90
192.168.10.87 - - [17/Aug/2017:12:47:18 +0100] "POST /alfresco/service/api/metadata/node/workspace/SpaceStore/nodeRef=workspace://SpacesStore/a2ad1215-da21-40e0-baf2-39532170d846?alf_ticket=TICKET_360e0e0f5beaaa036009c534d578ce46a70f0bfe HTTP/1.1" 404 437

i cheked also the node and it exists

is there something wrong with the url ?

alxgomz
Established Member

Re: update document name with REST API

Jump to solution

yes there is. You're using "nodeRef=fullyQualifiedNodeRef" as the last component of the the URL.

Use only the UUID part of the nodeRef.

So URL should be:

/alfresco/service/api/metadata/node/workspace/SpacesStore/a2ad1215-da21-40e0-baf2-39532170d846?alf_ticket=TICKET_360e0e0f5beaaa036009c534d578ce46a70f0bfe

yosrioh
Active Member

Re: update document name with REST API

Jump to solution

i have changed the url but i get the same responce

192.168.10.87 - - [17/Aug/2017:13:15:14 +0100] "POST /alfresco/service/api/metadata/node/workspace/SpaceStore/a2ad1215-da21-40e0-baf2-39532170d846?alf_ticket=TICKET_360e0e0f5beaaa036009c534d578ce46a70f0bfe HTTP/1.1" 404 402

and this is the url of the node

http://192.168.100.231:8080/share/page/document-details?nodeRef=workspace://SpacesStore/a2ad1215-da2... 

alxgomz
Established Member

Re: update document name with REST API

Jump to solution

SpacesStore