0

I created a Google Cloud Project, enabled the Apps Script API, created an Apps Script Project with the following function:

function remoteEXE() {
    return "Ok Google."
}

Next I bound the Apps Script Project to the GCP created earlier. Using the OAuth2.0 Playground, I chose the following scope in Step 1.

"https://www.googleapis.com/auth/script.external_request"

In Step 2 I got the authorization code and obtained the access & refresh tokens.

In Step 3, I provided the url substituting in the Apps Script scriptID and marked the request as a POST. Then, I prepared the request body with:

{
"function": "remoteEXE",
"parameters": []
}

Then I hit "send the request". It responded with a 404 error saying that the requested entity was not found.

I then realized I forgot to create a deployment. I created an API executable deployment. I still hit a 404 error. Then I added "devMode": true to the request body. I was met with a 403 Forbidden error; "The caller does not have permission". Afterwords I tried replacing the scriptID with the deploymentID in the url of the request. That lead to a 404 error. After removing the devMode property from the request body I got the 403 error again.

Afterwords I tried adding the same oauth scope to the manifest file in the GAS project. It did not affect the outcome.

The scope I used was pulled from the docs.

Based on a similar question here I also tried to redo step 2. It also did not affect the outcome.

Any clue as what I am doing wrong?

Update: 2023/03/01

I tried to deploy it as a web app as Prabhakaran Jayaraman Masani specified but it did not make a difference. I think deploying as "API Executable" is correct because it provides a URL trailed with ':run'. I also tried the 'IAM' permissions Prabhakaran Jayaraman Masani mentioned. I did find the cloud functions role and added it. I could not find a Apps Script API Execute role. I also have the owner role.

There aren't any errors in the error reporting area or in the Executions tab.

1 Answers1

1

It seems that you have followed the correct steps to authorize and execute the Apps Script function through the OAuth2 Playground. However, there might be a few issues that could be causing the 404 and 403 errors.

Firstly, please ensure that the Apps Script project is bound to the same GCP project where you enabled the Apps Script API. You can check this by going to the "Google Cloud Platform" menu in your Apps Script project and selecting "Project Settings". Under "Google Cloud Platform (GCP) Project", make sure the correct GCP project is selected.

Secondly, make sure that you have deployed the Apps Script project as a web app. To do this, go to the "Publish" menu in your Apps Script project and select "Deploy as web app". Make sure that you have selected the correct version of the script, and that "Execute the app as" is set to your Google account.

Once you have deployed the script as a web app, you will get a URL that you can use to make requests to your script. Make sure that you are using the correct URL in your request, and that you have specified the correct function name in the request body.

Lastly, check the IAM permissions for your GCP project. Make sure that your Google account has the necessary permissions to execute the Apps Script API. You can check this by going to the IAM & Admin menu in your GCP project and selecting "IAM". Make sure that your Google account has the "Cloud Functions Developer" and "Apps Script API Execute" roles.

If you have checked all of these things and are still getting errors, it might be helpful to check the error logs in your GCP project to see if there are any more specific error messages.

  • I tried to deploy it as a web app as you specified but it did not make a difference. I think deploying as "API Executable" is correct because it provides a URL trailed with ':run'. I also tried the 'IAM' permissions you mentioned. I did find the cloud functions role and added it. I could not find a Apps Script API Execute role. I also have the owner role. There aren't any errors in the error reporting area. – Lucas Sandre Mar 01 '23 at 19:53