Search code examples
google-apps-scriptgoogle-cloud-platformgoogle-drive-api

Trigger event on uploading file to Google Drive folder


Is there a way to monitor a Google Drive folder to trigger an Apps Script (or otherwise in GCP) when a new file is uploaded to that folder?


Solution

  • Google drive api supports push notifications you could set up your server to listen for changes in the directory.

    POST https://www.googleapis.com/drive/v3/files/fileId/watch
    Authorization: Bearer auth_token_for_current_user
    Content-Type: application/json
    
    {
      "id": "01234567-89ab-cdef-0123456789ab", // Your channel ID.
      "type": "web_hook",
      "address": "https ://mydomain.com/notifications", // Your receiving URL.
      ...
      "token": "target=myApp-myFilesChannelDest", // (Optional) Your channel token.
      "expiration": 1426325213000 // (Optional) Your requested channel expiration time.
    }
    

    The question is weather or not the notification will pick up that a new file was uploaded or if its just going to notify you for something like a name change on the directory.

    check notification-events