'Is it possible to initiate Google Drive File Approval via API?

Google Drive Approvals are now out of beta and allow for a user to request one or more other parties to approve/reject a document, then lock it as non-editable. Is there a way to do this via the Google Drive/Google Docs/Google Slides API, or do you have to use the Web GUI?



Solution 1:[1]

I have found a workaround to know if a document is approved or not (unfortunately not to start an approval flow):

  • Open the document you want to start approval;
  • Click File > Approval > Start new Approval flow, select option "Lock file before sending approval request"
  • Call API /drive/v3/files/:fileId?fields=contentRestrictions, the response will look like this:
{
   "contentRestrictions":[
      {
         "readOnly":true,
         "restrictingUser":{
            "kind":"drive#user",
            "displayName":"........",
            "me":true,
            "permissionId":"........",
            "emailAddress":".........."
         },
         "restrictionTime":"2022-04-27T11:03:42.430Z",
         "type":"globalContentRestriction"
      }
   ]
}
  • Back to the document, make the approval, and file will be locked.
  • Call again API /drive/v3/files/:fileId?fields=contentRestrictions, and now the response response will look like this:
{
   "contentRestrictions":[
      {
         "readOnly":true,
         "reason":"Locked for File Approval",
         "restrictingUser":{
            "kind":"drive#user",
            "displayName":"......",
            "me":true,
            "permissionId":".......",
            "emailAddress":"........"
         },
         "restrictionTime":"2022-04-27T10:54:24.594Z",
         "type":"globalContentRestriction"
      }
   ]
}

The difference is in the "reason" field, "Locked for File Approval" means that the file was approved.

P.S.: I don't how trustable this workaround is, I tested several and it seems consistent.

P.S.: I don't know if there is a better way to do it, just could find this one at the moment

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Fabrizio Marmitt