Google Sheets API creates comment on the spreadsheet instead of specified cells

13 views
Skip to first unread message

Harit Himanshu

unread,
Aug 15, 2019, 11:18:56 AM8/15/19
to Google Drive API and SDK
So, I am looking at Google Drive API v3 at https://developers.google.com/drive/api/v3/manage-comments#anchor for creating comments on the sheet.

As I follow along, I am trying the API with their own explorer at https://developers.google.com/drive/api/v3/reference/comments/create.  

My payload for creating the comment is following

{
  "content": "This is a comment - 02",
  "anchor": "{'r': '46', 'a': [{'matrix': {'r': 1, 'c': 1}}]}"
}


The `anchor` field is created based on their documentation https://developers.google.com/drive/api/v3/manage-comments#anchor 

Each anchor requires:
r — A string ID that indicates for which revision of the file this anchor was created. Use the revision id retrieved with revisions.get.  
a — The region or regions associated with the anchor. This must be a JSON array, and the type of object in that array is a region.

Based on this, I used Revisions.list at https://developers.google.com/drive/api/v3/reference/revisions/list API to fetch all the versions and took the `id` for the object where the `modifiedTime` is the latest. 

That's how in my payload 'r': '46' appears.  
For anchor a, I created the `matrix` because their documentation matches closely with what I am trying to achieve

matrix  
A location in a matrix-like structure. Use to define row and columns in spreadsheet documents, or any other documents which have a row or column structure.

So, I want to create a comment in a cell with row=1, column=1. That's how I arrived at the remaining part of the payload 'a': [{'matrix': {'r': 1, 'c': 1}}]}.

Now, when I execute this API using the API explorer at https://developers.google.com/drive/api/v3/reference/comments/create, the call succeeds

Screen Shot 2019-08-15 at 8.06.36 AM.png



However, the comment is made on the entire spreadsheet, instead of the cell

Screen Shot 2019-08-15 at 8.07.59 AM.png



While the cell has no comment

Screen Shot 2019-08-15 at 8.08.11 AM.png



So, somehow the comments are posted, but the `anchor` location is not honoured.  

What am I missing in my approach which is causing this unexpected behavior? and how can I fix it?

Thanks a lot in advance for the help
Reply all
Reply to author
Forward
0 new messages