forked from googleworkspace/apps-script-oauth2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDomo.gs
53 lines (46 loc) · 1.36 KB
/
Domo.gs
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
/*
* This sample demonstrates how to configure the library for the Domo API.
* Instructions on how to generate OAuth credentuals is available here:
* https://developer.domo.com/docs/authentication/overview-4
*/
var CLIENT_ID = '...';
var CLIENT_SECRET = '...';
/**
* Authorizes and makes a request to the Domo API.
*/
function run() {
var service = getService();
if (service.hasAccess()) {
var url = 'https://api.domo.com/v1/users';
var response = UrlFetchApp.fetch(url, {
headers: {
Authorization: 'Bearer ' + service.getAccessToken()
}
});
var result = JSON.parse(response.getContentText());
Logger.log(JSON.stringify(result, null, 2));
} else {
Logger.log(service.getLastError());
}
}
/**
* Reset the authorization state, so that it can be re-tested.
*/
function reset() {
getService().reset();
}
/**
* Configures the service.
*/
function getService() {
return OAuth2.createService('Domo')
// Set the endpoint URLs.
.setTokenUrl('https://api.domo.com/oauth/token')
// Set the client ID and secret.
.setClientId(CLIENT_ID)
.setClientSecret(CLIENT_SECRET)
// Sets the custom grant type to use.
.setGrantType('client_credentials')
// Set the property store where authorized tokens should be persisted.
.setPropertyStore(PropertiesService.getUserProperties());
}