Troubleshooting 4 common errors when calling Google Cloud Run from App Script

By May 18, 2022 No Comments
Troubleshooting Google Cloud Run from AppScript

Author: Nauvoo Perez 

Cloud Run, a serverless compute platform managed by Google, has become a popular way to run containerised apps. Recently, I worked on a project where I had to send information collected through Google Forms to the service. While Guillaume Blaquire’s blog post Call Cloud Run from App Script: The easy way was a life saver, I still spent an entire day debugging errors. 

Below are four errors I encountered while sending POST requests to Cloud Run via App Script. In this post, I detail where the errors came up, and list out step-by-step how I fixed them. Hopefully this helps cut down your debugging time.

Error #1

Error message: “You cannot switch to a Cloud Platform project outside the script owner’s Cloud Organization.”

When you might encounter this error: When changing your Apps Script project in Settings.

Solution: Ensure that the account you use to create your form/spreadsheet is linked to the organisation node that contains your GCP project and Cloud Run service. In other words, your account needs to be a user under the relevant domain.

In my situation, this meant that my account had to have the same domain as the organisation node that contained my project. But this might not be the case in your situation. I would recommend talking to your Google Workspace administrator or tech lead. If all else fails, you’ll very likely have to redeploy your project.

In my case it wasn’t sufficient that I switched accounts when re-creating my form/spreadsheet as Google kept switching me back to my main account when moving across different sections in Apps Script. I fixed the issue by logging into the correct account using an incognito window.

Error #2

Error message: “IAM Service Account Credentials API has not been used in project.”

When you might encounter this error: When changing your Apps Script project in Settings

Solution: Specify OAuth scopes in your appsscript.json file and follow Guillaume’s post steps in order.

Error #3

Error message: “In order to change your project, you will need to configure the OAuth consent screen.”

When you might encounter this error: When changing your Apps Script project in Settings

Solution: Inside the GCP console, ensure that you are in the correct project. 

  1. Go to APIs and Services -> OAuth Consent screen 

  2. Choose Internal then create 

  3. Fill out required information (app name, user support email, developer contact information email) then press Save and Continue.

  4. No need to change anything under Scopes, so press Save and Continue again.

Error #4

Error message: “Exception: You do not have permission to call SpreadsheetApp.getActiveSpreadsheet. Required permissions: ( ||”

When you might encounter this error:  When running or testing your Apps Script function

Solution: Add either  or in your OAuth scope inside the appsscript.json file. It should be noted that this error only came up for me when I manually edited the OAuth scopes inside the appsscript.json file. If you are getting this error but haven’t edited your appsscript.json file, your solution might lie elsewhere.  

These are just the errors that I personally encountered and I am sure there are others that I thankfully didn’t run into… this time. Should you come across any that aren’t mentioned here, feel free to reach out to me on LinkedIn. I would love to hear how you end up resolving the error.