Skip to content

Commit 1ba755d

Browse files
Update Docusign.gs
1 parent ca18faf commit 1ba755d

File tree

1 file changed

+74
-77
lines changed

1 file changed

+74
-77
lines changed

samples/Docusign.gs

Lines changed: 74 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,84 @@
11
/**
2-
* Authorizes and makes a request to the Docusign API.
3-
*/
4-
function rundocusign() {
5-
var payload=
6-
{
7-
'emailSubject': 'EMAIL-SUBJECT',
8-
'status': 'sent',
9-
'emailBlurb': 'EMAIL-CONTENT',
10-
'templateId': 'TEMPLATE-ID-TO-BE-USED',
11-
'templateRoles': [
12-
{
13-
'email': '[email protected]',
14-
'name': 'Joe Blogger',
15-
'roleName': 'role1'
16-
}
17-
]
18-
};
19-
var service = getService();
20-
if (service.hasAccess()) {
21-
var url = 'https://demo.docusign.net/restapi/v2/accounts/[ACCOUNT-ID]/envelopes';
22-
var response = UrlFetchApp.fetch(url, {
23-
headers: {
24-
Authorization: 'Bearer ' + service.getAccessToken()
2+
* Authorizes and makes a request to the Docusign API.
3+
*/
4+
function rundocusign() {
5+
var payload = {
6+
'emailSubject': 'EMAIL-SUBJECT',
7+
'status': 'sent',
8+
'emailBlurb': 'EMAIL-CONTENT',
9+
'templateId': 'TEMPLATE-ID-TO-BE-USED',
10+
'templateRoles': [{
11+
'email': '[email protected]',
12+
'name': 'Joe Blogger',
13+
'roleName': 'role1'
14+
}]
15+
};
16+
var service = getService();
17+
if (service.hasAccess()) {
18+
var url = 'https://demo.docusign.net/restapi/v2/accounts/[ACCOUNT-ID]/envelopes';
19+
var response = UrlFetchApp.fetch(url, {
20+
headers: {
21+
Authorization: 'Bearer ' + service.getAccessToken()
2522

26-
},
27-
method: 'post',
28-
contentType: 'application/json',
29-
grant_type: 'authorization_code',
30-
payload: JSON.stringify(payload)
31-
});
32-
var result = response.getContentText();
33-
Logger.log(result, null, 1);
34-
} else {
35-
var authorizationUrl = service.getAuthorizationUrl();
36-
Logger.log('Open the following URL and re-run the script: %s',
37-
authorizationUrl);
23+
},
24+
method: 'post',
25+
contentType: 'application/json',
26+
grant_type: 'authorization_code',
27+
payload: JSON.stringify(payload)
28+
});
29+
var result = response.getContentText();
30+
Logger.log(result, null, 1);
31+
} else {
32+
var authorizationUrl = service.getAuthorizationUrl();
33+
Logger.log('Open the following URL and re-run the script: %s',
34+
authorizationUrl);
35+
}
3836
}
39-
}
4037

41-
/**
42-
* Reset the authorization state, so that it can be re-tested.
43-
*/
44-
function reset() {
45-
getService().reset();
46-
}
38+
/**
39+
* Reset the authorization state, so that it can be re-tested.
40+
*/
41+
function reset() {
42+
getService().reset();
43+
}
4744

48-
/**
49-
* Configures the service.
50-
*/
51-
function getService() {
52-
return OAuth2.createService('Docusign')
53-
// Set the endpoint URLs.
54-
.setAuthorizationBaseUrl('https://account-d.docusign.com/oauth/auth')
55-
.setTokenUrl('https://account-d.docusign.com/oauth/token')
45+
/**
46+
* Configures the service.
47+
*/
48+
function getService() {
49+
return OAuth2.createService('Docusign')
50+
// Set the endpoint URLs.
51+
.setAuthorizationBaseUrl('https://account-d.docusign.com/oauth/auth')
52+
.setTokenUrl('https://account-d.docusign.com/oauth/token')
5653

57-
// Set the client ID and secret.
58-
.setClientId('...')
59-
.setClientSecret('..')
54+
// Set the client ID and secret.
55+
.setClientId('...')
56+
.setClientSecret('..')
6057

61-
// Set the name of the callback function that should be invoked to
62-
// complete the OAuth flow.
63-
.setCallbackFunction('usercallback')
58+
// Set the name of the callback function that should be invoked to
59+
// complete the OAuth flow.
60+
.setCallbackFunction('usercallback')
6461

65-
// Set the property store where authorized tokens should be persisted.
66-
.setPropertyStore(PropertiesService.getUserProperties())
67-
.setScope('openid');
68-
};
69-
/**
70-
* Handles the OAuth callback.
71-
*/
72-
function authCallback(request) {
73-
var service = getService();
74-
var authorized = service.handleCallback(request);
75-
if (authorized) {
76-
return HtmlService.createHtmlOutput('Success!');
77-
} else {
78-
return HtmlService.createHtmlOutput('Denied.');
62+
// Set the property store where authorized tokens should be persisted.
63+
.setPropertyStore(PropertiesService.getUserProperties())
64+
.setScope('openid');
65+
};
66+
/**
67+
* Handles the OAuth callback.
68+
*/
69+
function authCallback(request) {
70+
var service = getService();
71+
var authorized = service.handleCallback(request);
72+
if (authorized) {
73+
return HtmlService.createHtmlOutput('Success!');
74+
} else {
75+
return HtmlService.createHtmlOutput('Denied.');
76+
}
7977
}
80-
}
8178

82-
/**
83-
* Logs the redict URI to register in the Dropbox application settings.
84-
*/
85-
function logRedirectUri() {
86-
Logger.log(OAuth2.getRedirectUri());
87-
}
79+
/**
80+
* Logs the redict URI to register in the Dropbox application settings.
81+
*/
82+
function logRedirectUri() {
83+
Logger.log(OAuth2.getRedirectUri());
84+
}

0 commit comments

Comments
 (0)