0

I'm trying to deploy a Google Apps script via the Google REST API, and I'm using the API Explorer to perform that.

This is the method I am testing: https://developers.google.com/apps-script/api/reference/rest/v1/projects.deployments/create

Executing the method via the API Explorer returns a 404 error. I have verified that the scriptId in question does exist, and have tried several other scriptIds, to no avail. I have also made sure the permission scopes are properly set.

This is what the API Explorer gives me.

Worth mentioning that the same scriptId works when calling another method such as projects.get.

Is there anything I am missing, or is this an issue on Google's end? In case of the latter, what are the steps to contact Google Apps Script's team and inform them of this issue?

Ohm
  • 3
  • 3
  • Did you enable the Apps Script API's project-level access? https://developers.google.com/apps-script/api/how-tos/enable#granting_third-party_applications_access_to_your_script_projects – tehhowch Apr 01 '19 at 12:43
  • Just double checked, yes it is enabled. (A toggle in the Apps Script console's Settings screen). In fact I am able to create new scripts via the API, but can't deploy them. – Ohm Apr 01 '19 at 12:51
  • Probably this issue is because the APIs Explorer is not in the same Google Cloud Project as your script. This is a requirement of the Execution API: https://developers.google.com/apps-script/api/how-tos/execute#limitations but may or may not also be true for deployments. – tehhowch Apr 01 '19 at 12:57
  • Funnily enough, I only resorted to the API Explorer when my code was failing. I initially implemented this as a browser app using the gapi client, with all the APIs and permission scopes enabled in the Google API Console, but after facing this same error I tried the API explorer for full certainty and it also didn't work. My JS app is actually able to make several API calls successfully to the `scripts`, `drive` and other APIs, but the project deployment itself is not working for some reason, hence why I'm suspecting it's a Google bug. – Ohm Apr 01 '19 at 13:05

2 Answers2

0

Check your authorization scopes. You need to have the following scope enabled:

https://www.googleapis.com/auth/script.deployments

If its not in the list of available scopes in API Explorer then you'll need to add it manually (there is an area at the bottom of the authorization dialog where you can add scopes).

Google's API Explorer uses API keys to authorize requests. In some cases an API key is not sufficient and an OAuth2 (bearer) access token is required. As an alternative you can create an Apps Script project and add the appropriate scopes via the manifest file(appsscript.json). Then you can use UrlFetchApp.fetch() to test the API directly.

TheAddonDepot
  • 8,408
  • 2
  • 20
  • 30
  • This scope is already enabled, please check the attached screenshot: https://i.stack.imgur.com/4lcOG.png - I have also already logged in and enabled the permission for this scope for the API Explorer before executing the API call and taking the screenshot. – Ohm Apr 01 '19 at 11:56
  • Small clarification, I logged in to API Explorer via OAuth2, *not* using an API key. – Ohm Apr 01 '19 at 12:09
0

Your versionNumber is incorrect. The Requested entity here refers to the version of your script. You need to go to File>Manage Versions>Save New version to create a new version(or create one with the api1) and use that version number in the request body.

TheMaster
  • 45,448
  • 6
  • 62
  • 85
  • Thanks a lot, after deploying manually first, it works indeed. Do you know if this the missing step before deploying? (I'll try it soon regardless) https://developers.google.com/apps-script/api/reference/rest/v1/projects.versions/create – Ohm Apr 01 '19 at 18:01
  • @Ohm see the link in my answer. You can create a new version with the api. – TheMaster Apr 01 '19 at 18:03
  • Yes perfect, thank you again! I unfortunately cannot upvote your answer yet. – Ohm Apr 01 '19 at 18:05