Apps Script API . scripts

Instance Methods

run(scriptId, body, x__xgafv=None)

Runs a function in an Apps Script project. The script project must be

Method Details

run(scriptId, body, x__xgafv=None)
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](#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.

Args:
  scriptId: string, 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**. (required)
  body: object, The request body. (required)
    The object takes the form of:

{ # A request to run the function in a script. The script is identified by the
      # specified `script_id`. Executing a function on a script returns results
      # based on the implementation of the script.
    "function": "A 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": True or False, # 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": [ # The parameters to be passed to the function being executed. The object type
        # for each parameter should match the expected type in Apps Script.
        # Parameters cannot be Apps Script-specific object types (such as a
        # `Document` or a `Calendar`); they can only be primitive types such as
        # `string`, `number`, `array`, `object`, or `boolean`. Optional.
      "",
    ],
    "sessionState": "A 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](https://developer.android.com/guide/components/intents-filters.html)
        # that launches the add-on. When an Android add-on is run with a session
        # state, it gains the privileges of a
        # [bound](https://developers.google.com/apps-script/guides/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.
  }

  x__xgafv: string, V1 error format.
    Allowed values
      1 - v1 error format
      2 - v2 error format

Returns:
  An object of the form:

    { # A representation of an execution of an Apps Script function started with run. The execution response does not arrive until the function finishes executing. The maximum execution runtime is listed in the [Apps Script quotas guide](/apps-script/guides/services/quotas#current_limitations). 

After execution has started, it can have one of four outcomes:

"done": True or False, # 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. "response": { # If the script function returns successfully, this field contains an ExecutionResponse object with the function's return value. "a_key": "", # Properties of the object. Contains field @type with type URL. }, "error": { # 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. # If a `run` call succeeds but the script function (or Apps Script itself) throws an exception, this field contains a Status object. The `Status` object's `details` field contains an array with a single ExecutionError object that provides information about the nature of the error. "message": "A 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. "code": 42, # The status code. For this API, this value either: "details": [ # An array that contains a single ExecutionError object that provides information about the nature of the error. { "a_key": "", # Properties of the object. Contains field @type with type URL. }, ], }, }