blob: 6505951a32e5d3668ba426256f9cbd7e04e3c127 [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">
Thomas Coffee2f245372017-03-27 10:39:26 -070078 <code><a href="#run">run(scriptId, body, 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">
Thomas Coffee2f245372017-03-27 10:39:26 -070082 <code class="details" id="run">run(scriptId, body, 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
88least one of the scopes listed in the [Authorization](#authorization)
89section; script projects that do not require authorization cannot be
90executed through this API. To find the correct scopes to include in the
91authentication token, open the project in the script editor, then select
92**File > Project properties** and click the **Scopes** tab.
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -080093
Bu Sun Kim715bd7f2019-06-14 16:50:42 -070094The error `403, PERMISSION_DENIED: The caller does not have permission`
95indicates that the Cloud Platform project used to authorize the request is
96not the same as the one used by the script.
97
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -080098Args:
Bu Sun Kim715bd7f2019-06-14 16:50:42 -070099 scriptId: string, The script ID of the script to be executed. To find the script ID, open
Sai Cheemalapatic30d2b52017-03-13 12:12:03 -0400100the project in the script editor and select **File > Project properties**. (required)
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -0800101 body: object, The request body. (required)
102 The object takes the form of:
103
Sai Cheemalapatic30d2b52017-03-13 12:12:03 -0400104{ # 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 Kim715bd7f2019-06-14 16:50:42 -0700108 # include parentheses or parameters. It can reference a function in an
109 # included library such as `Library.libFunction1`.
Sai Cheemalapati4ba8c232017-06-06 18:46:08 -0400110 "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 Kim715bd7f2019-06-14 16:50:42 -0700112 # the Apps Script API. Optional; default is `false`.
Sai Cheemalapati4ba8c232017-06-06 18:46:08 -0400113 "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 Kim715bd7f2019-06-14 16:50:42 -0700120 "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 Cheemalapatic30d2b52017-03-13 12:12:03 -0400124 # 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 Kim715bd7f2019-06-14 16:50:42 -0700126 # [bound](https://developers.google.com/apps-script/guides/bound)
127 # script&mdash;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 Cheemalapatic30d2b52017-03-13 12:12:03 -0400130 # `Intent.getStringExtra("com.google.android.apps.docs.addons.SessionState")`.
131 # Optional.
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -0800132 }
133
134 x__xgafv: string, V1 error format.
Sai Cheemalapatic30d2b52017-03-13 12:12:03 -0400135 Allowed values
136 1 - v1 error format
137 2 - v2 error format
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -0800138
139Returns:
140 An object of the form:
141
Bu Sun Kim715bd7f2019-06-14 16:50:42 -0700142 { # 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 Parrott7d5badb2016-08-16 12:44:29 -0700163 "a_key": "", # Properties of the object. Contains field @type with type URL.
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -0800164 },
Bu Sun Kim715bd7f2019-06-14 16:50:42 -0700165 "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 Parrott36e41bc2016-02-19 16:02:29 -0800169 {
Jon Wayne Parrott7d5badb2016-08-16 12:44:29 -0700170 "a_key": "", # Properties of the object. Contains field @type with type URL.
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -0800171 },
172 ],
173 },
Jon Wayne Parrott36e41bc2016-02-19 16:02:29 -0800174 }</pre>
175</div>
176
177</body></html>