-
Notifications
You must be signed in to change notification settings - Fork 4
/
scripts.clj
68 lines (59 loc) · 2.45 KB
/
scripts.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(ns happygapi.script.scripts
"Apps Script API: scripts.
Manages and executes Google Apps Script projects.
See: https://developers.google.com/apps-script/api/api/reference/rest/v1/scripts"
(:require [cheshire.core :as json]
[clj-http.client :as http]
[happy.util :as util]))
(defn run$
"https://developers.google.com/apps-script/api/api/reference/rest/v1/scripts/run
Required parameters: scriptId
Optional parameters: none
Body:
{:function string,
:devMode boolean,
:parameters [any],
:sessionState string}
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-scopes) 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."
{:scopes ["https://mail.google.com/"
"https://www.google.com/calendar/feeds"
"https://www.google.com/m8/feeds"
"https://www.googleapis.com/auth/admin.directory.group"
"https://www.googleapis.com/auth/admin.directory.user"
"https://www.googleapis.com/auth/documents"
"https://www.googleapis.com/auth/drive"
"https://www.googleapis.com/auth/forms"
"https://www.googleapis.com/auth/forms.currentonly"
"https://www.googleapis.com/auth/groups"
"https://www.googleapis.com/auth/spreadsheets"
"https://www.googleapis.com/auth/userinfo.email"]}
[auth args body]
{:pre [(util/has-keys? args #{:scriptId})]}
(util/get-response
(http/post
(util/get-url
"https://script.googleapis.com/"
"v1/scripts/{scriptId}:run"
#{:scriptId}
args)
(merge-with
merge
{:content-type :json,
:body (json/generate-string body),
:throw-exceptions false,
:query-params args,
:accept :json,
:as :json}
auth))))