cancel
Showing results for 
Search instead for 
Did you mean: 

update document name with REST API

yosrioh
Confirmed Champ
Confirmed Champ

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 ACCEPTED ANSWER

alxgomz
Star Contributor
Star Contributor
10 REPLIES 10

alxgomz
Star Contributor
Star Contributor

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.

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
Star Contributor
Star Contributor

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"
  }
}

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());