0

I have a Google Cloud Function that I would like to call from my Google App Script on a Google Form submission. The process will be: 1)user submits google form, 2)there will be a trigger (onformsubmit) that will run the app script function 3) app script function will trigger cloud function.

So far:

  1. The script trigger works, in the logs it's listening correctly.

  2. The cloud function works, I tested it in the Cloud function testing interface and when I run it from there, it does what I need it to do which is to update a google sheet as well as upload data to BigQuery.

The problem comes from calling that function from App Script that I have associated with my google form submission trigger. There seems to be no communication there, as cloud function logs don't show anything happening at trigger submission.

This is my app script code:

function onSubmit() {

  var url = "myurl"   
  const token = ScriptApp.getIdentityToken() 

  var options = {   
      'method' : 'get',   
      'headers': {"Authorization":"Bearer "+ token}    
        };   
  
  var data = UrlFetchApp.getRequest(url,options);
  
  return data
  
    }

And my Cloud function is a HTTP one in Python and starts with:

def numbers(request):

Some troubleshooting:

  • When I test it, the execution log shows no errors
  • If I try to change UrlFetchApp to .fetch or change getIdentityToken to getOAuthToken I get a 401 error for both
  • I added the following to my oauthScopes:
     "openid",
     "https://www.googleapis.com/auth/cloud-platform",
     "https://www.googleapis.com/auth/script.container.ui",
     "https://www.googleapis.com/auth/script.external_request",
     "https://www.googleapis.com/auth/documents"```
    
  • I'm running both from the same Google Cloud account
  • I added myself to permissions in Cloud Function settings too

Any ideas of why the two aren't communicating would be appreciated!

1

1 Answer 1

1

I was able to resolve this in case anyone has a similar issue. Since my email address was associated with an organizational account, my Apps Script and GCP didn't allow the correct permissions.

In the settings of Apps Script, I couldn't change the GCP account with that function because the GCP was outside of my organization. Once I set up the Cloud Function on my organizations GCP, I was able to change the account manually in the settings and my function worked properly on the trigger.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.