blob: 1033fb3e5191b6dcd0e4ed8580465cda793916e4 [file] [log] [blame]
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -08001<html><body>
2<style>
3
4body, 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
15body {
16 font-size: 13px;
17 padding: 1em;
18}
19
20h1 {
21 font-size: 26px;
22 margin-bottom: 1em;
23}
24
25h2 {
26 font-size: 24px;
27 margin-bottom: 1em;
28}
29
30h3 {
31 font-size: 20px;
32 margin-bottom: 1em;
33 margin-top: 1em;
34}
35
36pre, code {
37 line-height: 1.5;
38 font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace;
39}
40
41pre {
42 margin-top: 0.5em;
43}
44
45h1, h2, h3, p {
46 font-family: Arial, sans serif;
47}
48
49h1, 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 Kim715bd7f2019-06-14 16:50:42 -070075<h1><a href="script_v1.html">Apps Script API</a> . <a href="script_v1.scripts.html">scripts</a></h1>
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -080076<h2>Instance Methods</h2>
77<p class="toc_element">
Dan O'Mearadd494642020-05-01 07:42:23 -070078 <code><a href="#run">run(scriptId, body=None, x__xgafv=None)</a></code></p>
Bu Sun Kim715bd7f2019-06-14 16:50:42 -070079<p class="firstline">Runs a function in an Apps Script project. The script project must be</p>
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -080080<h3>Method Details</h3>
81<div class="method">
Dan O'Mearadd494642020-05-01 07:42:23 -070082 <code class="details" id="run">run(scriptId, body=None, x__xgafv=None)</code>
Bu Sun Kim715bd7f2019-06-14 16:50:42 -070083 <pre>Runs a function in an Apps Script project. The script project must be
84deployed for use with the Apps Script API and the calling application must
85share the same Cloud Platform project.
Sai Cheemalapatic30d2b52017-03-13 12:12:03 -040086
87This method requires authorization with an OAuth 2.0 token that includes at
Dan O'Mearadd494642020-05-01 07:42:23 -070088least one of the scopes listed in the
89[Authorization](#authorization-scopes) section; script projects that do not
90require authorization cannot be executed through this API. To find the
91correct scopes to include in the authentication token, open the project in
92the script editor, then select **File &gt; Project properties** and click the
93**Scopes** tab.
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -080094
Bu Sun Kim715bd7f2019-06-14 16:50:42 -070095The error `403, PERMISSION_DENIED: The caller does not have permission`
96indicates that the Cloud Platform project used to authorize the request is
97not the same as the one used by the script.
98
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -080099Args:
Bu Sun Kim715bd7f2019-06-14 16:50:42 -0700100 scriptId: string, The script ID of the script to be executed. To find the script ID, open
Dan O'Mearadd494642020-05-01 07:42:23 -0700101the project in the script editor and select **File &gt; Project properties**. (required)
102 body: object, The request body.
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -0800103 The object takes the form of:
104
Sai Cheemalapatic30d2b52017-03-13 12:12:03 -0400105{ # A request to run the function in a script. The script is identified by the
106 # specified `script_id`. Executing a function on a script returns results
107 # based on the implementation of the script.
108 "function": "A String", # The name of the function to execute in the given script. The name does not
Bu Sun Kim715bd7f2019-06-14 16:50:42 -0700109 # include parentheses or parameters. It can reference a function in an
110 # included library such as `Library.libFunction1`.
Dan O'Mearadd494642020-05-01 07:42:23 -0700111 "sessionState": "A String", # &lt;b&gt;Deprecated&lt;/b&gt;. For use with Android add-ons only. An ID that represents
112 # the user's current session in the Android app for Google Docs or Sheets,
113 # included as extra data in the
114 # [Intent](https://developer.android.com/guide/components/intents-filters.html)
115 # that launches the add-on. When an Android add-on is run with a session
116 # state, it gains the privileges of a
117 # [bound](https://developers.google.com/apps-script/guides/bound)
118 # script&amp;mdash;that is, it can access information like the user's current
119 # cursor position (in Docs) or selected cell (in Sheets). To retrieve the
120 # state, call
121 # `Intent.getStringExtra("com.google.android.apps.docs.addons.SessionState")`.
122 # Optional.
Sai Cheemalapati4ba8c232017-06-06 18:46:08 -0400123 "parameters": [ # The parameters to be passed to the function being executed. The object type
124 # for each parameter should match the expected type in Apps Script.
125 # Parameters cannot be Apps Script-specific object types (such as a
126 # `Document` or a `Calendar`); they can only be primitive types such as
127 # `string`, `number`, `array`, `object`, or `boolean`. Optional.
128 "",
129 ],
Dan O'Mearadd494642020-05-01 07:42:23 -0700130 "devMode": True or False, # If `true` and the user is an owner of the script, the script runs at the
131 # most recently saved version rather than the version deployed for use with
132 # the Apps Script API. Optional; default is `false`.
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -0800133 }
134
135 x__xgafv: string, V1 error format.
Sai Cheemalapatic30d2b52017-03-13 12:12:03 -0400136 Allowed values
137 1 - v1 error format
138 2 - v2 error format
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -0800139
140Returns:
141 An object of the form:
142
Dan O'Mearadd494642020-05-01 07:42:23 -0700143 { # 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). &lt;p&gt;After execution has started, it can have one of four outcomes:&lt;/p&gt; &lt;ul&gt; &lt;li&gt; If the script function returns successfully, the
Bu Sun Kim715bd7f2019-06-14 16:50:42 -0700144 # response field contains an
145 # ExecutionResponse object
Dan O'Mearadd494642020-05-01 07:42:23 -0700146 # with the function's return value in the object's `result` field.&lt;/li&gt;
147 # &lt;li&gt; If the script function (or Apps Script itself) throws an exception, the
Bu Sun Kim715bd7f2019-06-14 16:50:42 -0700148 # error field contains a
149 # Status object. The `Status` object's `details`
150 # field contains an array with a single
151 # ExecutionError object that
Dan O'Mearadd494642020-05-01 07:42:23 -0700152 # provides information about the nature of the error.&lt;/li&gt;
153 # &lt;li&gt; If the execution has not yet completed,
Bu Sun Kim715bd7f2019-06-14 16:50:42 -0700154 # the done field is `false` and
Dan O'Mearadd494642020-05-01 07:42:23 -0700155 # the neither the `response` nor `error` fields are present.&lt;/li&gt;
156 # &lt;li&gt; If the `run` call itself fails (for example, because of a
Bu Sun Kim715bd7f2019-06-14 16:50:42 -0700157 # malformed request or an authorization error), the method returns an HTTP
158 # response code in the 4XX range with a different format for the response
159 # body. Client libraries automatically convert a 4XX response into an
Dan O'Mearadd494642020-05-01 07:42:23 -0700160 # exception class.&lt;/li&gt;
161 # &lt;/ul&gt;
Bu Sun Kim715bd7f2019-06-14 16:50:42 -0700162 "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.
163 "response": { # If the script function returns successfully, this field contains an ExecutionResponse object with the function's return value.
Jon Wayne Parrott7d5badb2016-08-16 12:44:29 -0700164 "a_key": "", # Properties of the object. Contains field @type with type URL.
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -0800165 },
Bu Sun Kim715bd7f2019-06-14 16:50:42 -0700166 "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.
167 "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.
Dan O'Mearadd494642020-05-01 07:42:23 -0700168 "code": 42, # The status code. For this API, this value either: &lt;ul&gt; &lt;li&gt; 10, indicating a `SCRIPT_TIMEOUT` error,&lt;/li&gt; &lt;li&gt; 3, indicating an `INVALID_ARGUMENT` error, or&lt;/li&gt; &lt;li&gt; 1, indicating a `CANCELLED` execution.&lt;/li&gt; &lt;/ul&gt;
Bu Sun Kim715bd7f2019-06-14 16:50:42 -0700169 "details": [ # An array that contains a single ExecutionError object that provides information about the nature of the error.
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -0800170 {
Jon Wayne Parrott7d5badb2016-08-16 12:44:29 -0700171 "a_key": "", # Properties of the object. Contains field @type with type URL.
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -0800172 },
173 ],
174 },
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -0800175 }</pre>
176</div>
177
178</body></html>