Search code examples
google-apps-scriptgoogle-docs

How to get suggestions on Google Docs with Google Apps Script


I found this StackOverflow answer that says "You can get the suggestions made in a document doing a get request," but when I follow the link I see Java and Python options. How can I actually get suggestions using exclusively Google Apps Script? I don't need to modify them at all, just get their existence.


Solution

  • Use Docs service of Apps Script and access the data you need to have based on its response.

    Script:

    function myFunction() {
      var documentId = <document ID>;
      var doc = Docs.Documents.get(documentId);
      doc.body.content.forEach(function (content){
        if (content.paragraph) {
          var elements = content.paragraph.elements;
          elements.forEach(function (element){
            if(element.textRun.suggestedDeletionIds)
              Logger.log("suggested to delete: " + element.textRun.content)
            if(element.textRun.suggestedInsertionIds)
              Logger.log("suggested to insert: " + element.textRun.content)
          });
        }
      });
    }
    
    

    Sample Data:

    sample

    Output:

    output

    Reference: