DocuSign REST API Access from Google Apps Script

For a client project, I needed to call the DocuSign REST API from Google Apps Script. The idea is to attach a script to a Google Spreadsheet that gets a list of completed DocuSign envelope IDs, populates the sheet with information about each envelope, and downloads the combined pdf of the envelope’s documents to Drive.

DocuSign announced a Google Apps Script library, but I wasn’t able to obtain access. However, I discovered that it’s not difficult to call the API from Apps Script without additional libraries.

Every call to the DocuSign REST API requires an access token. Because the script needs to run without user interaction, we need to use “JWT Grant authentication” to get an access token to send with our requests. See this page and video for more information about the JWT Grant authentication process: https://developers.docusign.com/platform/auth/jwt/jwt-get-token/

Once I found Amit Agarwal’s code to create a JSON Web Token in Google Apps script, the biggest “gotcha” was that the RSA private key created in DocuSign needs to be converted into a different form for use in the createJwt function.

I’ve published some sample code in a github repo: https://github.com/karlkranich/google-apps-script-docusign. The comments in the files, combined with the DocuSign video linked above, should be a good start towards a functioning Google Apps Script connection to DocuSign.

Leave a Reply

Your email address will not be published. Required fields are marked *