Method: scripts.run Stay organized with collections Save and categorize content based on your preferences.
Page Summary
The
scripts.runmethod in the Apps Script API allows you to execute a function within a deployed Apps Script project.This method requires authorization using an OAuth 2.0 token with appropriate scopes.
The HTTP request uses a POST method with the script ID as a path parameter.
The request body specifies the function name to execute and optional parameters.
The response body indicates the execution status, including success with a result or failure with an error.
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 theAuthorization 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 script projectOverview page and scroll down to "Project OAuth Scopes."
The error403, 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.
HTTP request
POST https://script.googleapis.com/v1/scripts/{deploymentId}:run
The URL usesgRPC Transcoding syntax.
Path parameters
| Parameters | |
|---|---|
deploymentId |
The deployment ID for the API Executable deployment.Find the deployment ID underDeploy > Manage deployments in the script editor. |
Request body
The request body contains data with the following structure:
| JSON representation |
|---|
{"function":string,"parameters":[value],"sessionState":string,"devMode":boolean} |
| Fields | |
|---|---|
function |
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 |
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 |
sessionState |
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 theIntent that launches the add-on. When an Android add-on is run with a session state, it gains the privileges of abound 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 |
devMode |
If |
Response body
If successful, the response body contains data with the following structure:
A representation of an execution of an Apps Script function started withrun. The execution response does not arrive until the function finishes executing. The maximum execution runtime is listed in theApps Script quotas guide.
After execution has started, it can have one of four outcomes:
- If the script function returns successfully, the
responsefield contains anExecutionResponseobject with the function's return value in the object'sresultfield. - If the script function (or Apps Script itself) throws an exception, the
errorfield contains aStatusobject. TheStatusobject'sdetailsfield contains an array with a singleExecutionErrorobject that provides information about the nature of the error. - If the execution has not yet completed, the
donefield isfalseand the neither theresponsenorerrorfields are present. - If the
runcall itself fails (for example, because of a malformed request or an authorization error), the method returns an HTTP response code in the 4XX range with a different format for the response body. Client libraries automatically convert a 4XX response into an exception class.
| JSON representation |
|---|
{"done":boolean,// Union field |
| Fields | |
|---|---|
done |
This field indicates whether the script execution has completed. A completed execution has a populated |
Union fieldresult. The operation result, which can be either anerror or a validresponse. Ifdone ==false, neithererror norresponse is set. Ifdone ==true, exactly one oferror orresponse may be set. Some services might not provide the result.result can be only one of the following: | |
error |
If a |
response |
If the script function returns successfully, this field contains an An object containing fields of an arbitrary type. An additional field |
Authorization Scopes
Requires one of the following OAuth scopes:
https://apps-apis.google.com/a/feedshttps://apps-apis.google.com/a/feeds/alias/https://apps-apis.google.com/a/feeds/groups/https://mail.google.com/https://sites.google.com/feedshttps://www.google.com/calendar/feedshttps://www.google.com/m8/feedshttps://www.googleapis.com/auth/admin.directory.grouphttps://www.googleapis.com/auth/admin.directory.userhttps://www.googleapis.com/auth/documentshttps://www.googleapis.com/auth/documents.currentonlyhttps://www.googleapis.com/auth/drivehttps://www.googleapis.com/auth/dynamiccreativeshttps://www.googleapis.com/auth/formshttps://www.googleapis.com/auth/forms.currentonlyhttps://www.googleapis.com/auth/groupshttps://www.googleapis.com/auth/script.cpanelhttps://www.googleapis.com/auth/script.external_requesthttps://www.googleapis.com/auth/script.scriptapphttps://www.googleapis.com/auth/script.send_mailhttps://www.googleapis.com/auth/script.storagehttps://www.googleapis.com/auth/script.webapp.deployhttps://www.googleapis.com/auth/spreadsheetshttps://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/sqlservicehttps://www.googleapis.com/auth/userinfo.email
For more information, see theOAuth 2.0 Overview.
Status
If arun call succeeds but the script function (or Apps Script itself) throws an exception, the response body'serror field contains thisStatus object.
| JSON representation |
|---|
{"code":integer,"message":string,"details":[{"@type":string,field1:...,...}]} |
| Fields | |
|---|---|
code |
The status code. For this API, this value either:
|
message |
A developer-facing error message, which is in English. Any user-facing error message is localized and sent in the |
details[] |
An array that contains a single An object containing fields of an arbitrary type. An additional field |
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-11-04 UTC.