DriveApp Error: "We're sorry, a server error occurred. Please wait a bit and try again."

Viewed 1626

Whenever I run the following function

    function getDatabases(){
      var files = DriveApp.getFilesByType(MimeType.GOOGLE_SHEETS);
      var amount = 0;
      while (files.hasNext()){
        if((files.next().getName()).indexOf("Database") > -1){
          amount++;
        }
      }
      return amount;
    }

I get this error:

Error Message

This suddenly started about a month and a half ago. The same code was working earlier so I thought I reached a quota limit but that was not the case.

4 Answers

got my solution In the script -> Resources -> Advanced google services -> turn on Drive API Click in below message " Google Cloud Platform API Dashboard" to open de cloud project for the script. With the project selected, search in the search bar "Drive API" -> ENABLE, do the same for "Google Drive API". Done, no more "we're are sorry server error" for DriveApp functions in the script. Also: I enabled other APIs and advanced services Drive Activity API, just in case...

I ran into this issue too...

Like Nicolás Paulino mentioned, check your "Advanced Google Services" are turned on with the Apps Script Editor UI..

As stated...from the apps script editor..

  • select the "Resources" menu item
  • then "Advanced Google Services"
  • then find all/all related services and toggle them on.

Then head to ... https://console.cloud.google.com/apis/library?project={yourProjectId}

Click on the menu (top-left)

  • hover on "Apis & Services"
  • click "Library"
  • search for any/all related APIs you're using

I've just had your same issue and it took me forever to fix it. What worked for me was to create a copy of the spreadsheet with the bound script. After authorising everything again in the copy, it worked. Hope it helps!

If you have connected your Apps script to Google Cloud Project then you have to enable the Drive API in your console.

Drive API: https://console.cloud.google.com/apis/api/drive.googleapis.com/

Else you can go to Apps script -> Services -> Add Drive API

Source: https://developers.google.com/apps-script/guides/services/advanced

Also beware that there is a quota limit for the number of times you have called the DriveAPI. If you are not connected to any GCP project then just create a new copy of spreadsheet and try again.

Related