Run

Runs a function in an Apps Script project

5 variables
8 variables

Runs a function in an Apps Script project. The script project must be deployed for use with the Apps Script API and the calling application must share the same Cloud Platform project.

This method requires authorization with an OAuth 2.0 token that includes at least one of the scopes listed in the Authorization section; script projects that do not require authorization cannot be executed through this API. To find the correct scopes to include in the authentication token, open the project in the script editor, then select File > Project properties and click the Scopes tab.

The error 403, PERMISSION_DENIED: The caller does not have permission indicates that the Cloud Platform project used to authorize the request is not the same as the one used by the script

Authorization

To use this building block you will have to grant access to at least one of the following scopes:

  • Read, compose, send, and permanently delete all your email from Gmail
  • See, edit, share, and permanently delete all the calendars you can access using Google Calendar
  • See, edit, download, and permanently delete your contacts
  • View and manage the provisioning of groups on your domain
  • View and manage the provisioning of users on your domain
  • View and manage your Google Docs documents
  • See, edit, create, and delete all of your Google Drive files
  • View and manage your forms in Google Drive
  • View and manage forms that this application has been installed in
  • View and manage your Google Groups
  • See, edit, create, and delete your spreadsheets in Google Drive
  • View your email address

Input

This building block consumes 5 input parameters

  = Parameter name
  = Format

scriptId STRING Required

The script ID of the script to be executed. To find the script ID, open the project in the script editor and select File > Project properties

sessionState STRING

Deprecated. For use with Android add-ons only. An ID that represents the user's current session in the Android app for Google Docs or Sheets, included as extra data in the Intent that launches the add-on. When an Android add-on is run with a session state, it gains the privileges of a bound script—that is, it can access information like the user's current cursor position (in Docs) or selected cell (in Sheets). To retrieve the state, call Intent.getStringExtra("com.google.android.apps.docs.addons.SessionState"). Optional

function STRING

The name of the function to execute in the given script. The name does not include parentheses or parameters. It can reference a function in an included library such as Library.libFunction1

devMode BOOLEAN

If true and the user is an owner of the script, the script runs at the most recently saved version rather than the version deployed for use with the Apps Script API. Optional; default is false

parameters[] ANY

Output

This building block provides 8 output parameters

  = Parameter name
  = Format

response OBJECT

If the script function returns successfully, this field contains an ExecutionResponse object with the function's return value

response.customKey.value ANY

If the script function returns successfully, this field contains an ExecutionResponse object with the function's return value

error OBJECT

If a run call succeeds but the script function (or Apps Script itself) throws an exception, the response body's error field contains this Status object

error.code INTEGER

The status code. For this API, this value either:

  • 10, indicating a SCRIPT_TIMEOUT error,
  • 3, indicating an INVALID_ARGUMENT error, or
  • 1, indicating a CANCELLED execution.

error.message STRING

A developer-facing error message, which is in English. Any user-facing error message is localized and sent in the details field, or localized by the client

error.details[] OBJECT

error.details[].customKey.value ANY

done BOOLEAN

This field indicates whether the script execution has completed. A completed execution has a populated response field containing the ExecutionResponse from function that was executed