cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot add comment by Restful API

zuzoovn
Champ in-the-making
Champ in-the-making
Hi guys

I try to using this API


Add comment

Add a new comment to a node.

POST /alfresco/service/api/node/{store_type}/{store_id}/{id}/comments
In my case, i use this format:

/alfresco/service/api/node/workspace/SpacesStore/4eb045b7-8b0c-4799-9b8b-xxxxxxxxxx/comments


And try to post value by this

{
   "title" : "title",
   "content" : "content"
}

which has been described  here http://wiki.alfresco.com/wiki/3.0_REST_API#Comment_Service

But i alway receive this error

HTTP/1.1 500 Internal Server Error

How can i solve this problems

Regards
12 REPLIES 12

jpotts
World-Class Innovator
World-Class Innovator
When you use curl to do this, here's what it looks like:
curl -X POST -uadmin:admin http://localhost:8080/alfresco/s/api/node/workspace/SpacesStore/7bb9c846-fcc5-43b5-a893-39e46ebe94d4... -H "content-type:application/json" -d@/var/tmp/tmp.json

Where /var/tmp/tmp.json contains your JSON above, verbatim.

This is working fine against 4.0.d. I can test it against another version if you need me to, but you should check that you are properly setting the content-type to "application/json" as that is a common problem.

If it still doesn't work for you, please post the code that is making the POST.

Jeff

zuzoovn
Champ in-the-making
Champ in-the-making
When you use curl to do this, here's what it looks like:
curl -X POST -uadmin:admin http://localhost:8080/alfresco/s/api/node/workspace/SpacesStore/7bb9c846-fcc5-43b5-a893-39e46ebe94d4... -H "content-type:application/json" -d@/var/tmp/tmp.json

Where /var/tmp/tmp.json contains your JSON above, verbatim.

This is working fine against 4.0.d. I can test it against another version if you need me to, but you should check that you are properly setting the content-type to "application/json" as that is a common problem.

If it still doesn't work for you, please post the code that is making the POST.

Jeff


Hi, http://localhost:8080/alfresco/[size=150]s[/size]/api/node/workspace/SpacesStore/7bb9c846-fcc5-43b5-a893-39e46ebe94d4/comments

or

/alfresco/service/api/node/workspace/SpacesStore/4eb045b7-8b0c-4799-9b8b-xxxxxxxxxx/comments

Why do you have
s
in your url
alfresco/s/api/node/workspace/SpacesStore/

I dont see this in Wiki

BTW, this is my code for Android

DefaultHttpClient httpclient = new DefaultHttpClient();
         
       HttpPost httppost = new HttpPost(url);
      
       String json = "{"
                + "\"title\" : \"" + title + "\","
               + "\"content\" : \"" + content+ "\""
               + "}";
      
       StringEntity requestEntity = new StringEntity(json, "UTF-8");
        httppost.setEntity(requestEntity);
        httppost.setHeader("Content-type", "application/json'");
      
        Log.i("executing request" , String.valueOf(httppost.getRequestLine()));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
      
        System.out.println("—————————————-");
        System.out.println(response.getStatusLine());
       
        if (entity != null) {
               Log.i("response content length:", entity.getContentLength() + "");

               json = EntityUtils.toString(entity);
              
               Log.i("response content:" , json);
              
               response.getEntity().consumeContent();
            }
        
         // When HttpClient instance is no longer needed,
         // shut down the connection manager to ensure
         // immediate deallocation of all system resources
         httpclient.getConnectionManager().shutdown();

And here is error:


{
"status" :
{
"code" : 500,
"name" : "Internal Error",
"description" : "An error inside the HTTP server which prevented it from fulfilling the request."
},

jpotts
World-Class Innovator
World-Class Innovator
Sorry, didn't mean to confuse you by using "s". It is a shortcut. It is equivalent to using "service".

I notice a strange single-quote after your content-type string:
httppost.setHeader("Content-type", "application/json'");
Can you check that?

zuzoovn
Champ in-the-making
Champ in-the-making
Sorry, didn't mean to confuse you by using "s". It is a shortcut. It is equivalent to using "service".

I notice a strange single-quote after your content-type string:
httppost.setHeader("Content-type", "application/json'");
Can you check that?

OMG, this is my mistake.

Thanks for your comment

resolved

And, i have some more question:

1. How can i delete a specific comment:

DELETE /api/comment/node/{store_type}/{store_id}/{id}
   <= HTTP status
How i can pass the id of comment

2. And, what's the "Add to favorite" Restful API? . I dont know this API

Thanks you

jpotts
World-Class Innovator
World-Class Innovator
When you post the comment you'll get JSON back that looks something like this:
{
   "item": {
   "url": "api/comment/node/workspace\/SpacesStore\/5d3f51f1-b868-40e3-80c9-890c97061d7d",
   "nodeRef": "workspace://SpacesStore/5d3f51f1-b868-40e3-80c9-890c97061d7d",
   "name": "comment-1345137429134",
   "title": "title",
   "content": "content",
   "author":
   {
      "username": "admin",
      "firstName": "Administrator",
      "lastName": ""
   },
   "createdOn": "Aug 16 2012 12:17:09 GMT-0500 (CDT)",
   "modifiedOn": "Aug 16 2012 12:17:09 GMT-0500 (CDT)",
   "createdOnISO": "2012-08-16T12:17:09.136-05:00",
   "modifiedOnISO": "2012-08-16T12:17:09.136-05:00",
   "isUpdated": false,
   "permissions":
   {
      "edit": true,
      "delete": true
   }
}
}
That nodeRef is the nodeRef of the comment node. So you can make a DELETE call using that, like this:
curl -X DELETE -uadmin:admin http://localhost:8080/alfresco/s/api/node/workspace/SpacesStore/5d3f51f1-b868-40e3-80c9-890c97061d7d

The favorites is used to mark a document as a favorite. In the UI it shows as a filled in star and then shows up when you filter on favorites.
[img]http://i.imgur.com/yVBPF.png[/img]

To mark a document as a favorite, you POST to:
http://localhost:8080/alfresco/s/api/people/{user id}/preferences

The following JSON:
{"org":{"alfresco":{"share":{"documents":{"favourites":"{node ref of the favorite document"}}}}}

Where "node ref of the favorite document" looks like: workspace://SpacesStore/1a0b110f-1e09-4ca2-b367-fe25e4964a4e

Jeff

zuzoovn
Champ in-the-making
Champ in-the-making
When you post the comment you'll get JSON back that looks something like this:
{
   "item": {
   "url": "api/comment/node/workspace\/SpacesStore\/5d3f51f1-b868-40e3-80c9-890c97061d7d",
   "nodeRef": "workspace://SpacesStore/5d3f51f1-b868-40e3-80c9-890c97061d7d",
   "name": "comment-1345137429134",
   "title": "title",
   "content": "content",
   "author":
   {
      "username": "admin",
      "firstName": "Administrator",
      "lastName": ""
   },
   "createdOn": "Aug 16 2012 12:17:09 GMT-0500 (CDT)",
   "modifiedOn": "Aug 16 2012 12:17:09 GMT-0500 (CDT)",
   "createdOnISO": "2012-08-16T12:17:09.136-05:00",
   "modifiedOnISO": "2012-08-16T12:17:09.136-05:00",
   "isUpdated": false,
   "permissions":
   {
      "edit": true,
      "delete": true
   }
}
}
That nodeRef is the nodeRef of the comment node. So you can make a DELETE call using that, like this:
curl -X DELETE -uadmin:admin http://localhost:8080/alfresco/s/api/node/workspace/SpacesStore/5d3f51f1-b868-40e3-80c9-890c97061d7d


Hi

What's happen with the nodeRef have more than one of my comment?

Will all of them be deleted>

jpotts
World-Class Innovator
World-Class Innovator
No, because you are deleting a specific comment node, you are not deleting all of the comments on the document node.

Jeff

zuzoovn
Champ in-the-making
Champ in-the-making
Hi, i get rating by this api:
"/alfresco/service/api/node/workspace/SpacesStore/{id}/ratings"

But i can get only my RATING

How can i get all rating of file or folder?

zuzoovn
Champ in-the-making
Champ in-the-making
The favorites is used to mark a document as a favorite. In the UI it shows as a filled in star and then shows up when you filter on favorites.
[img]http://i.imgur.com/yVBPF.png[/img]

To mark a document as a favorite, you POST to:
http://localhost:8080/alfresco/s/api/people/{user id}/preferences

The following JSON:
{"org":{"alfresco":{"share":{"documents":{"favourites":"{node ref of the favorite document"}}}}}

Where "node ref of the favorite document" looks like: workspace://SpacesStore/1a0b110f-1e09-4ca2-b367-fe25e4964a4e

Jeff


Hi, i can mark document as a favorite, but the problems is:

When i add "file A" as favorite, it's OK

but when i add "file B" as favorite,so that "file A" is not favorite, i can see only "File B" as favorite

Help me please!

Thanks