How to insert or add a comment to a google Document via the API

2,412 views
Skip to first unread message

Paul Armstrong

unread,
Mar 6, 2023, 2:04:34 AM3/6/23
to Google Apps Script Community
Hi
Can anyone advise on the API to use to add a comment to a google Document using the app script API? 

This may have been answered many times before but try searching for the terms "document' and "comment", and you'll see it's hard to find the answer if it is there :) 

Thanks in advance. 

Paul Armstrong

unread,
Mar 6, 2023, 3:38:20 AM3/6/23
to Google Apps Script Community
Hi
an update, I have found the method and its via the DriveAPI. This documentation: https://developers.google.com/drive/api/guides/manage-comments#define

The challenge now is how do I anchor a comment—fix a comment to some text in a document. Any examples welcome.

thank you 

Mark De Vos

unread,
Jun 28, 2023, 4:16:24 PM6/28/23
to Google Apps Script Community
Another approach might be to modify an existing comment using the comment.update method.  This means you don't have to worry about anchoring, etc. (https://developers.google.com/drive/api/reference/rest/v2/comments/update).

 var resource = {'content': 'I can change this comment!','commentId':'INSERT_ID'}
   Drive.Comments.update(resource, fileId, commentId);

Reply all
Reply to author
Forward
0 new messages