Google Apps Script: "Error 401: deleted_client The OAuth client was deleted" All of a sudden?

I currently use a Google App Scripts on Google Sheets for my budgeting spreadsheet. Essentially, the way I have it set up is:

  1. Buy item
  2. Input expense onto Google form (which feeds into a spreadsheet)
  3. Use Apps scripts to convert timestamp into yyyy-MM-dd

I've been using this process for 4 years but all of a sudden, today it stopped working by giving me this error below.

Error 401: deleted_client The OAuth client was deleted

Error 401: deleted_client The OAuth client was deleted

Here's my app script:
Here's my app script

Here's my trigger:
Here's my trigger


Solution 1:

At some point your Apps Script project's attached Google Cloud Platform (GCP) project (which manages the Oauth client) was likely deleted. You could confirm this by going to the Apps Script project editor, click the gear on the left for Project Settings, then click the Project Number link in the Google Cloud Platform (GCP) Project section. If it loads the GCP console (using the correct Google account) but gives you an error instead of bringing you to the project, then it probably doesn't exist anymore.

First, check if it's been deleted within the past 30 days and could be recovered:

  1. In the GCP console, go to the Manage resources page (project picker → three dots button → select your organization → Manage resources).
  2. Below the list of organizations, folders, and projects, click Resources pending deletion.
  3. If you see the project there, check the box then click Restore. In the dialog that appears, confirm that you want to restore the project.
  4. Go back to the Apps Script project editor and run one of your functions, and it should allow you to authorize the project again instead of giving you the 401 error.

If the project does not appear in the Resources pending deletion list because it'd been deleted over 30 days ago:

  1. Copy all of your Apps Script projects' files to your local machine. If there are many files, consider using the clasp CLI tool, which would allow you to clone the entire project locally with one clasp pull command.
  2. [IMPORTANT] Confirm that all of the files have been stored locally (and backed up, if desired), because the Apps Script project will be deleted permanently.
  3. Make note of any services which are enabled in the Services section of the Apps Script project editor sidebar.
  4. Delete the Apps Script project by going to the Apps Script project's Overview page, then click the trash can labeled Delete project forever.
  5. In your Google Sheets doc, go to ExtensionsApps Script again and it will create a new Apps Script project (with attached GCP project).
  6. Save the default Code.gs file
  7. Re-create the projects' files. If you'd used clasp pull in the first step, then you can use clasp push to push the files from your local machine back to the project. In this case, go to the Apps Script project's Project Settings page and copy the Script ID. Then update the scriptId in the local .clasp.json file, save it, then clasp push.
  8. If there were Services enabled in the previous project, enable them again in the Services section of the editor sidebar.
  9. Run one of your functions and it should allow you to authorize the project again instead of giving you the 401 error.