Jon Wayne Parrott | 36e41bc | 2016-02-19 16:02:29 -0800 | [diff] [blame] | 1 | <html><body> |
| 2 | <style> |
| 3 | |
| 4 | body, h1, h2, h3, div, span, p, pre, a { |
| 5 | margin: 0; |
| 6 | padding: 0; |
| 7 | border: 0; |
| 8 | font-weight: inherit; |
| 9 | font-style: inherit; |
| 10 | font-size: 100%; |
| 11 | font-family: inherit; |
| 12 | vertical-align: baseline; |
| 13 | } |
| 14 | |
| 15 | body { |
| 16 | font-size: 13px; |
| 17 | padding: 1em; |
| 18 | } |
| 19 | |
| 20 | h1 { |
| 21 | font-size: 26px; |
| 22 | margin-bottom: 1em; |
| 23 | } |
| 24 | |
| 25 | h2 { |
| 26 | font-size: 24px; |
| 27 | margin-bottom: 1em; |
| 28 | } |
| 29 | |
| 30 | h3 { |
| 31 | font-size: 20px; |
| 32 | margin-bottom: 1em; |
| 33 | margin-top: 1em; |
| 34 | } |
| 35 | |
| 36 | pre, code { |
| 37 | line-height: 1.5; |
| 38 | font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace; |
| 39 | } |
| 40 | |
| 41 | pre { |
| 42 | margin-top: 0.5em; |
| 43 | } |
| 44 | |
| 45 | h1, h2, h3, p { |
| 46 | font-family: Arial, sans serif; |
| 47 | } |
| 48 | |
| 49 | h1, h2, h3 { |
| 50 | border-bottom: solid #CCC 1px; |
| 51 | } |
| 52 | |
| 53 | .toc_element { |
| 54 | margin-top: 0.5em; |
| 55 | } |
| 56 | |
| 57 | .firstline { |
| 58 | margin-left: 2 em; |
| 59 | } |
| 60 | |
| 61 | .method { |
| 62 | margin-top: 1em; |
| 63 | border: solid 1px #CCC; |
| 64 | padding: 1em; |
| 65 | background: #EEE; |
| 66 | } |
| 67 | |
| 68 | .details { |
| 69 | font-weight: bold; |
| 70 | font-size: 14px; |
| 71 | } |
| 72 | |
| 73 | </style> |
| 74 | |
Bu Sun Kim | 715bd7f | 2019-06-14 16:50:42 -0700 | [diff] [blame] | 75 | <h1><a href="script_v1.html">Apps Script API</a> . <a href="script_v1.scripts.html">scripts</a></h1> |
Jon Wayne Parrott | 36e41bc | 2016-02-19 16:02:29 -0800 | [diff] [blame] | 76 | <h2>Instance Methods</h2> |
| 77 | <p class="toc_element"> |
Thomas Coffee | 2f24537 | 2017-03-27 10:39:26 -0700 | [diff] [blame] | 78 | <code><a href="#run">run(scriptId, body, x__xgafv=None)</a></code></p> |
Bu Sun Kim | 715bd7f | 2019-06-14 16:50:42 -0700 | [diff] [blame] | 79 | <p class="firstline">Runs a function in an Apps Script project. The script project must be</p> |
Jon Wayne Parrott | 36e41bc | 2016-02-19 16:02:29 -0800 | [diff] [blame] | 80 | <h3>Method Details</h3> |
| 81 | <div class="method"> |
Thomas Coffee | 2f24537 | 2017-03-27 10:39:26 -0700 | [diff] [blame] | 82 | <code class="details" id="run">run(scriptId, body, x__xgafv=None)</code> |
Bu Sun Kim | 715bd7f | 2019-06-14 16:50:42 -0700 | [diff] [blame] | 83 | <pre>Runs a function in an Apps Script project. The script project must be |
| 84 | deployed for use with the Apps Script API and the calling application must |
| 85 | share the same Cloud Platform project. |
Sai Cheemalapati | c30d2b5 | 2017-03-13 12:12:03 -0400 | [diff] [blame] | 86 | |
| 87 | This method requires authorization with an OAuth 2.0 token that includes at |
| 88 | least one of the scopes listed in the [Authorization](#authorization) |
| 89 | section; script projects that do not require authorization cannot be |
| 90 | executed through this API. To find the correct scopes to include in the |
| 91 | authentication token, open the project in the script editor, then select |
| 92 | **File > Project properties** and click the **Scopes** tab. |
Jon Wayne Parrott | 36e41bc | 2016-02-19 16:02:29 -0800 | [diff] [blame] | 93 | |
Bu Sun Kim | 715bd7f | 2019-06-14 16:50:42 -0700 | [diff] [blame] | 94 | The error `403, PERMISSION_DENIED: The caller does not have permission` |
| 95 | indicates that the Cloud Platform project used to authorize the request is |
| 96 | not the same as the one used by the script. |
| 97 | |
Jon Wayne Parrott | 36e41bc | 2016-02-19 16:02:29 -0800 | [diff] [blame] | 98 | Args: |
Bu Sun Kim | 715bd7f | 2019-06-14 16:50:42 -0700 | [diff] [blame] | 99 | scriptId: string, The script ID of the script to be executed. To find the script ID, open |
Sai Cheemalapati | c30d2b5 | 2017-03-13 12:12:03 -0400 | [diff] [blame] | 100 | the project in the script editor and select **File > Project properties**. (required) |
Jon Wayne Parrott | 36e41bc | 2016-02-19 16:02:29 -0800 | [diff] [blame] | 101 | body: object, The request body. (required) |
| 102 | The object takes the form of: |
| 103 | |
Sai Cheemalapati | c30d2b5 | 2017-03-13 12:12:03 -0400 | [diff] [blame] | 104 | { # A request to run the function in a script. The script is identified by the |
| 105 | # specified `script_id`. Executing a function on a script returns results |
| 106 | # based on the implementation of the script. |
| 107 | "function": "A String", # The name of the function to execute in the given script. The name does not |
Bu Sun Kim | 715bd7f | 2019-06-14 16:50:42 -0700 | [diff] [blame] | 108 | # include parentheses or parameters. It can reference a function in an |
| 109 | # included library such as `Library.libFunction1`. |
Sai Cheemalapati | 4ba8c23 | 2017-06-06 18:46:08 -0400 | [diff] [blame] | 110 | "devMode": True or False, # If `true` and the user is an owner of the script, the script runs at the |
| 111 | # most recently saved version rather than the version deployed for use with |
Bu Sun Kim | 715bd7f | 2019-06-14 16:50:42 -0700 | [diff] [blame] | 112 | # the Apps Script API. Optional; default is `false`. |
Sai Cheemalapati | 4ba8c23 | 2017-06-06 18:46:08 -0400 | [diff] [blame] | 113 | "parameters": [ # The parameters to be passed to the function being executed. The object type |
| 114 | # for each parameter should match the expected type in Apps Script. |
| 115 | # Parameters cannot be Apps Script-specific object types (such as a |
| 116 | # `Document` or a `Calendar`); they can only be primitive types such as |
| 117 | # `string`, `number`, `array`, `object`, or `boolean`. Optional. |
| 118 | "", |
| 119 | ], |
Bu Sun Kim | 715bd7f | 2019-06-14 16:50:42 -0700 | [diff] [blame] | 120 | "sessionState": "A String", # <b>Deprecated</b>. For use with Android add-ons only. An ID that represents |
| 121 | # the user's current session in the Android app for Google Docs or Sheets, |
| 122 | # included as extra data in the |
| 123 | # [Intent](https://developer.android.com/guide/components/intents-filters.html) |
Sai Cheemalapati | c30d2b5 | 2017-03-13 12:12:03 -0400 | [diff] [blame] | 124 | # that launches the add-on. When an Android add-on is run with a session |
| 125 | # state, it gains the privileges of a |
Bu Sun Kim | 715bd7f | 2019-06-14 16:50:42 -0700 | [diff] [blame] | 126 | # [bound](https://developers.google.com/apps-script/guides/bound) |
| 127 | # script—that is, it can access information like the user's current |
| 128 | # cursor position (in Docs) or selected cell (in Sheets). To retrieve the |
| 129 | # state, call |
Sai Cheemalapati | c30d2b5 | 2017-03-13 12:12:03 -0400 | [diff] [blame] | 130 | # `Intent.getStringExtra("com.google.android.apps.docs.addons.SessionState")`. |
| 131 | # Optional. |
Jon Wayne Parrott | 36e41bc | 2016-02-19 16:02:29 -0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | x__xgafv: string, V1 error format. |
Sai Cheemalapati | c30d2b5 | 2017-03-13 12:12:03 -0400 | [diff] [blame] | 135 | Allowed values |
| 136 | 1 - v1 error format |
| 137 | 2 - v2 error format |
Jon Wayne Parrott | 36e41bc | 2016-02-19 16:02:29 -0800 | [diff] [blame] | 138 | |
| 139 | Returns: |
| 140 | An object of the form: |
| 141 | |
Bu Sun Kim | 715bd7f | 2019-06-14 16:50:42 -0700 | [diff] [blame] | 142 | { # 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). <p>After execution has started, it can have one of four outcomes:</p> <ul> <li> If the script function returns successfully, the |
| 143 | # response field contains an |
| 144 | # ExecutionResponse object |
| 145 | # with the function's return value in the object's `result` field.</li> |
| 146 | # <li> If the script function (or Apps Script itself) throws an exception, the |
| 147 | # error field contains a |
| 148 | # Status object. The `Status` object's `details` |
| 149 | # field contains an array with a single |
| 150 | # ExecutionError object that |
| 151 | # provides information about the nature of the error.</li> |
| 152 | # <li> If the execution has not yet completed, |
| 153 | # the done field is `false` and |
| 154 | # the neither the `response` nor `error` fields are present.</li> |
| 155 | # <li> If the `run` call itself fails (for example, because of a |
| 156 | # malformed request or an authorization error), the method returns an HTTP |
| 157 | # response code in the 4XX range with a different format for the response |
| 158 | # body. Client libraries automatically convert a 4XX response into an |
| 159 | # exception class.</li> |
| 160 | # </ul> |
| 161 | "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. |
| 162 | "response": { # If the script function returns successfully, this field contains an ExecutionResponse object with the function's return value. |
Jon Wayne Parrott | 7d5badb | 2016-08-16 12:44:29 -0700 | [diff] [blame] | 163 | "a_key": "", # Properties of the object. Contains field @type with type URL. |
Jon Wayne Parrott | 36e41bc | 2016-02-19 16:02:29 -0800 | [diff] [blame] | 164 | }, |
Bu Sun Kim | 715bd7f | 2019-06-14 16:50:42 -0700 | [diff] [blame] | 165 | "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. |
| 166 | "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. |
| 167 | "code": 42, # The status code. For this API, this value either: <ul> <li> 10, indicating a `SCRIPT_TIMEOUT` error,</li> <li> 3, indicating an `INVALID_ARGUMENT` error, or</li> <li> 1, indicating a `CANCELLED` execution.</li> </ul> |
| 168 | "details": [ # An array that contains a single ExecutionError object that provides information about the nature of the error. |
Jon Wayne Parrott | 36e41bc | 2016-02-19 16:02:29 -0800 | [diff] [blame] | 169 | { |
Jon Wayne Parrott | 7d5badb | 2016-08-16 12:44:29 -0700 | [diff] [blame] | 170 | "a_key": "", # Properties of the object. Contains field @type with type URL. |
Jon Wayne Parrott | 36e41bc | 2016-02-19 16:02:29 -0800 | [diff] [blame] | 171 | }, |
| 172 | ], |
| 173 | }, |
Jon Wayne Parrott | 36e41bc | 2016-02-19 16:02:29 -0800 | [diff] [blame] | 174 | }</pre> |
| 175 | </div> |
| 176 | |
| 177 | </body></html> |