To list all the comments for a file (or folder) we can use the following GET call: http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/{id}/comments
The Node Identifier for the folder or file node to get the comments for is specified with the {id} parameter.
As an example we will get all the comments for the file we just added a comment to:
$ curl -X GET -H 'Accept: application/json' -H 'Authorization: Basic VElDS0VUXzA4ZWI3ZTJlMmMxNzk2NGNhNTFmMGYzMzE4NmNjMmZjOWQ1NmQ1OTM=' 'http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/7279b5c5-da55-4e98-8b12-72d33b90c810/comments' | jq % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1151 0 1151 0 0 7829 0 --:--:-- --:--:-- --:--:-- 7829 { "list": { "pagination": { "count": 2, "hasMoreItems": false, "totalItems": 2, "skipCount": 0, "maxItems": 100 }, "entries": [ { "entry": { "createdAt": "2019-12-03T09:32:54.803+0000", "createdBy": { "enabled": true, "firstName": "Administrator", "email": "admin@alfresco.com", "emailNotificationsEnabled": true, "company": {}, "id": "admin" }, "edited": false, "modifiedAt": "2019-12-03T09:32:54.803+0000", "canEdit": true, "modifiedBy": { "enabled": true, "firstName": "Administrator", "email": "admin@alfresco.com", "emailNotificationsEnabled": true, "company": {}, "id": "admin" }, "canDelete": true, "id": "cace6ed3-1e57-4690-86eb-d9bce01257cf", "content": "This is a comment" } }, { "entry": { "createdAt": "2019-12-02T13:31:54.693+0000", "createdBy": { "enabled": true, "firstName": "Administrator", "email": "admin@alfresco.com", "emailNotificationsEnabled": true, "company": {}, "id": "admin" }, "edited": false, "modifiedAt": "2019-12-02T13:31:54.693+0000", "canEdit": true, "modifiedBy": { "enabled": true, "firstName": "Administrator", "email": "admin@alfresco.com", "emailNotificationsEnabled": true, "company": {}, "id": "admin" }, "canDelete": true, "id": "7eb1a859-6c00-49c0-9eec-36c8f45db88d", "content": "This is a comment on a file" } } ] } }
The response is constructed in the usual way for lists, with a pagination section at the start and then entries.
Each comment has a canEdit and canDelete property, this can be used to determine whether the current user has the permission to edit or delete that comment, respectively.
We can see that the file has two comments. There is a lot of information returned for each comment. We can make it a bit more succinct and save bandwidth by using the fields parameter, let’s return only the date the comment was made and the content of it:
$ curl -X GET -H 'Accept: application/json' -H 'Authorization: Basic VElDS0VUXzA4ZWI3ZTJlMmMxNzk2NGNhNTFmMGYzMzE4NmNjMmZjOWQ1NmQ1OTM=' 'http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/7279b5c5-da55-4e98-8b12-72d33b90c810/comments?fields=createdAt,content' | jq % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 299 0 299 0 0 5245 0 --:--:-- --:--:-- --:--:-- 5155 { "list": { "pagination": { "count": 2, "hasMoreItems": false, "totalItems": 2, "skipCount": 0, "maxItems": 100 }, "entries": [ { "entry": { "createdAt": "2019-12-03T09:32:54.803+0000", "content": "This is a comment" } }, { "entry": { "createdAt": "2019-12-02T13:31:54.693+0000", "content": "This is a comment on a file" } } ] } }