From 46edfefa0e975ff3c8fcdcb93e1785f80dd7d39c Mon Sep 17 00:00:00 2001 From: ianmurray1994 Date: Sun, 9 Feb 2020 16:58:50 -0500 Subject: [PATCH 1/4] Create Docusign.gs Sample Auth for Creating an Envelope using a Template for DocuSign. --- samples/Docusign.gs | 97 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 samples/Docusign.gs diff --git a/samples/Docusign.gs b/samples/Docusign.gs new file mode 100644 index 00000000..dc5e2c2e --- /dev/null +++ b/samples/Docusign.gs @@ -0,0 +1,97 @@ + + + /** + * Authorizes and makes a request to the Docusign API. + */ +function rundocusign() { + var payload = + { + "emailSubject": "EMAIL-SUBJECT", + "status": "sent", + "emailBlurb": "EMAIL-CONTENT", + "templateId": "TEMPLATE-ID-TO-BE-USED", + "templateRoles": [ + { + "email": "joebloggs@sample.com", + "name": "Joe Blogger", + "roleName": "role1" + } + ] +} + var service = getService(); + if (service.hasAccess()) { + var url = 'https://demo.docusign.net/restapi/v2/accounts/[INSERT-ACCOUNT-ID-HERE]/envelopes'; + var response = UrlFetchApp.fetch(url, { + headers: { + Authorization: 'Bearer ' + service.getAccessToken() + + }, + method: 'post', + contentType: 'application/json', + grant_type: 'authorization_code', + payload : JSON.stringify(payload) + + }); + var result = response.getContentText(); + Logger.log(result, null, 1); + } else { + + + var authorizationUrl = service.getAuthorizationUrl(); + Logger.log('Open the following URL and re-run the script: %s', + authorizationUrl); + } +} + +/** + * Reset the authorization state, so that it can be re-tested. + */ +function reset() { + getService().reset(); +} + +/** + * Configures the service. + */ +function getService() { + return OAuth2.createService("Docusign") + // Set the endpoint URLs. + .setAuthorizationBaseUrl('https://account-d.docusign.com/oauth/auth') + .setTokenUrl('https://account-d.docusign.com/oauth/token') + + // Set the client ID and secret. + .setClientId("...") + .setClientSecret("...") + + // Set the name of the callback function that should be invoked to + // complete the OAuth flow. + .setCallbackFunction('usercallback') + + // Set the property store where authorized tokens should be persisted. + .setPropertyStore(PropertiesService.getUserProperties()) + .setScope('openid') + + // Set the response type to code (required). + + +} + +/** + * Handles the OAuth callback. + */ +function authCallback(request) { + var service = getService(); + var authorized = service.handleCallback(request); + if (authorized) { + return HtmlService.createHtmlOutput('Success!'); + } else { + return HtmlService.createHtmlOutput('Denied.'); + } +} + +/** + * Logs the redict URI to register in the Dropbox application settings. + */ +function logRedirectUri() { + Logger.log(OAuth2.getRedirectUri()); +} From 315bc2786a7eead6180d42f533974e64b1b736dc Mon Sep 17 00:00:00 2001 From: ianmurray1994 Date: Mon, 10 Feb 2020 21:33:29 -0500 Subject: [PATCH 2/4] Update Docusign.gs --- samples/Docusign.gs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/samples/Docusign.gs b/samples/Docusign.gs index dc5e2c2e..70471ab5 100644 --- a/samples/Docusign.gs +++ b/samples/Docusign.gs @@ -1,5 +1,3 @@ - - /** * Authorizes and makes a request to the Docusign API. */ @@ -17,25 +15,25 @@ function rundocusign() { "roleName": "role1" } ] -} +}; var service = getService(); if (service.hasAccess()) { - var url = 'https://demo.docusign.net/restapi/v2/accounts/[INSERT-ACCOUNT-ID-HERE]/envelopes'; + var url = 'https://demo.docusign.net/restapi/v2/accounts/[ACCOUNT-ID]/envelopes'; var response = UrlFetchApp.fetch(url, { headers: { Authorization: 'Bearer ' + service.getAccessToken() - + }, method: 'post', - contentType: 'application/json', + contentType: 'application/json', grant_type: 'authorization_code', payload : JSON.stringify(payload) - + }); var result = response.getContentText(); Logger.log(result, null, 1); } else { - + var authorizationUrl = service.getAuthorizationUrl(); Logger.log('Open the following URL and re-run the script: %s', @@ -60,8 +58,8 @@ function getService() { .setTokenUrl('https://account-d.docusign.com/oauth/token') // Set the client ID and secret. - .setClientId("...") - .setClientSecret("...") + .setClientId('...') + .setClientSecret('..') // Set the name of the callback function that should be invoked to // complete the OAuth flow. @@ -71,10 +69,7 @@ function getService() { .setPropertyStore(PropertiesService.getUserProperties()) .setScope('openid') - // Set the response type to code (required). - - -} +}; /** * Handles the OAuth callback. From ca18faf04f3dc0a9e5de0a8404730b47e7b18d24 Mon Sep 17 00:00:00 2001 From: ianmurray1994 Date: Mon, 10 Feb 2020 21:42:28 -0500 Subject: [PATCH 3/4] Update Docusign.gs --- samples/Docusign.gs | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/samples/Docusign.gs b/samples/Docusign.gs index 70471ab5..479efdfe 100644 --- a/samples/Docusign.gs +++ b/samples/Docusign.gs @@ -2,17 +2,17 @@ * Authorizes and makes a request to the Docusign API. */ function rundocusign() { - var payload = + var payload= { - "emailSubject": "EMAIL-SUBJECT", - "status": "sent", - "emailBlurb": "EMAIL-CONTENT", - "templateId": "TEMPLATE-ID-TO-BE-USED", - "templateRoles": [ + 'emailSubject': 'EMAIL-SUBJECT', + 'status': 'sent', + 'emailBlurb': 'EMAIL-CONTENT', + 'templateId': 'TEMPLATE-ID-TO-BE-USED', + 'templateRoles': [ { - "email": "joebloggs@sample.com", - "name": "Joe Blogger", - "roleName": "role1" + 'email': 'joebloggs@sample.com', + 'name': 'Joe Blogger', + 'roleName': 'role1' } ] }; @@ -27,14 +27,11 @@ function rundocusign() { method: 'post', contentType: 'application/json', grant_type: 'authorization_code', - payload : JSON.stringify(payload) - + payload: JSON.stringify(payload) }); var result = response.getContentText(); Logger.log(result, null, 1); - } else { - - +} else { var authorizationUrl = service.getAuthorizationUrl(); Logger.log('Open the following URL and re-run the script: %s', authorizationUrl); @@ -52,7 +49,7 @@ function reset() { * Configures the service. */ function getService() { - return OAuth2.createService("Docusign") + return OAuth2.createService('Docusign') // Set the endpoint URLs. .setAuthorizationBaseUrl('https://account-d.docusign.com/oauth/auth') .setTokenUrl('https://account-d.docusign.com/oauth/token') @@ -67,10 +64,8 @@ function getService() { // Set the property store where authorized tokens should be persisted. .setPropertyStore(PropertiesService.getUserProperties()) - .setScope('openid') - + .setScope('openid'); }; - /** * Handles the OAuth callback. */ From 1ba755da516b6b696865f3cdfe8adeeaefc3bde4 Mon Sep 17 00:00:00 2001 From: ianmurray1994 Date: Tue, 11 Feb 2020 18:22:30 -0500 Subject: [PATCH 4/4] Update Docusign.gs --- samples/Docusign.gs | 151 ++++++++++++++++++++++---------------------- 1 file changed, 74 insertions(+), 77 deletions(-) diff --git a/samples/Docusign.gs b/samples/Docusign.gs index 479efdfe..360d8db6 100644 --- a/samples/Docusign.gs +++ b/samples/Docusign.gs @@ -1,87 +1,84 @@ /** - * Authorizes and makes a request to the Docusign API. - */ -function rundocusign() { - var payload= - { - 'emailSubject': 'EMAIL-SUBJECT', - 'status': 'sent', - 'emailBlurb': 'EMAIL-CONTENT', - 'templateId': 'TEMPLATE-ID-TO-BE-USED', - 'templateRoles': [ - { - 'email': 'joebloggs@sample.com', - 'name': 'Joe Blogger', - 'roleName': 'role1' - } - ] -}; - var service = getService(); - if (service.hasAccess()) { - var url = 'https://demo.docusign.net/restapi/v2/accounts/[ACCOUNT-ID]/envelopes'; - var response = UrlFetchApp.fetch(url, { - headers: { - Authorization: 'Bearer ' + service.getAccessToken() + * Authorizes and makes a request to the Docusign API. + */ + function rundocusign() { + var payload = { + 'emailSubject': 'EMAIL-SUBJECT', + 'status': 'sent', + 'emailBlurb': 'EMAIL-CONTENT', + 'templateId': 'TEMPLATE-ID-TO-BE-USED', + 'templateRoles': [{ + 'email': 'joebloggs@sample.com', + 'name': 'Joe Blogger', + 'roleName': 'role1' + }] + }; + var service = getService(); + if (service.hasAccess()) { + var url = 'https://demo.docusign.net/restapi/v2/accounts/[ACCOUNT-ID]/envelopes'; + var response = UrlFetchApp.fetch(url, { + headers: { + Authorization: 'Bearer ' + service.getAccessToken() - }, - method: 'post', - contentType: 'application/json', - grant_type: 'authorization_code', - payload: JSON.stringify(payload) - }); - var result = response.getContentText(); - Logger.log(result, null, 1); -} else { - var authorizationUrl = service.getAuthorizationUrl(); - Logger.log('Open the following URL and re-run the script: %s', - authorizationUrl); + }, + method: 'post', + contentType: 'application/json', + grant_type: 'authorization_code', + payload: JSON.stringify(payload) + }); + var result = response.getContentText(); + Logger.log(result, null, 1); + } else { + var authorizationUrl = service.getAuthorizationUrl(); + Logger.log('Open the following URL and re-run the script: %s', + authorizationUrl); + } } -} -/** - * Reset the authorization state, so that it can be re-tested. - */ -function reset() { - getService().reset(); -} + /** + * Reset the authorization state, so that it can be re-tested. + */ + function reset() { + getService().reset(); + } -/** - * Configures the service. - */ -function getService() { - return OAuth2.createService('Docusign') - // Set the endpoint URLs. - .setAuthorizationBaseUrl('https://account-d.docusign.com/oauth/auth') - .setTokenUrl('https://account-d.docusign.com/oauth/token') + /** + * Configures the service. + */ + function getService() { + return OAuth2.createService('Docusign') + // Set the endpoint URLs. + .setAuthorizationBaseUrl('https://account-d.docusign.com/oauth/auth') + .setTokenUrl('https://account-d.docusign.com/oauth/token') - // Set the client ID and secret. - .setClientId('...') - .setClientSecret('..') + // Set the client ID and secret. + .setClientId('...') + .setClientSecret('..') - // Set the name of the callback function that should be invoked to - // complete the OAuth flow. - .setCallbackFunction('usercallback') + // Set the name of the callback function that should be invoked to + // complete the OAuth flow. + .setCallbackFunction('usercallback') - // Set the property store where authorized tokens should be persisted. - .setPropertyStore(PropertiesService.getUserProperties()) - .setScope('openid'); -}; -/** - * Handles the OAuth callback. - */ -function authCallback(request) { - var service = getService(); - var authorized = service.handleCallback(request); - if (authorized) { - return HtmlService.createHtmlOutput('Success!'); - } else { - return HtmlService.createHtmlOutput('Denied.'); + // Set the property store where authorized tokens should be persisted. + .setPropertyStore(PropertiesService.getUserProperties()) + .setScope('openid'); + }; + /** + * Handles the OAuth callback. + */ + function authCallback(request) { + var service = getService(); + var authorized = service.handleCallback(request); + if (authorized) { + return HtmlService.createHtmlOutput('Success!'); + } else { + return HtmlService.createHtmlOutput('Denied.'); + } } -} -/** - * Logs the redict URI to register in the Dropbox application settings. - */ -function logRedirectUri() { - Logger.log(OAuth2.getRedirectUri()); -} + /** + * Logs the redict URI to register in the Dropbox application settings. + */ + function logRedirectUri() { + Logger.log(OAuth2.getRedirectUri()); + }