Turn a Google Sheet into a sending queue. One row is one signer. A menu item creates an envelope for each new row and writes the envelope id and status back into the sheet. A time-driven trigger then keeps each status up to date. Test mode only, no libraries.
Small teams already keep their signers in a spreadsheet: new hires, vendors, clients. Copying each row into a signing tool by hand is slow and error prone. Google Apps Script runs inside the sheet and can call the SignatureAPI REST API directly, so the sheet can be the whole interface.
Core.gs: the platform-agnostic core. It builds the request body, picks the rows that still need an envelope or a status refresh, and calls the API through an injectedhttpfunction. No Google service is used here.Code.gs: the thin Apps Script shim. It adds a menu, reads the key from Script Properties, callsUrlFetchApp, reads and writes the sheet, and installs the time-driven trigger.core.test.mjs: Node.js tests for both files.
Sheet layout, header in row 1: name, email, role, envelope_id, status.
Tested on the host with node --test (no Google account involved):
Core.gsloaded exactly as Apps Script loads it (a shared global scope), checking the payload, row selection for sending and for refreshing, the test-key guard, error handling and the exact HTTP call (URL,X-API-Keyheader, JSON body).Code.gsrun against hand-written fakes ofSpreadsheetApp,PropertiesService,UrlFetchApp,ScriptAppandUtilities, checking that ids and statuses are written back to the right cells, that a failing row does not stop the loop, that the refresh skips rows alreadycompleted,canceledorfailed, and that the trigger runsrefreshStatusesevery hour.- A live check that runs the real core against the API (create an envelope, then read it back), only when
SIGNATUREAPI_KEYis set. It is skipped otherwise.
Not tested here, because it needs Google's runtime: the real SpreadsheetApp, UrlFetchApp, PropertiesService and ScriptApp services, the menu in the sheet UI, the authorization prompt, and the trigger schedule. Those steps follow Google's public documentation, linked below. Run the script once in your own sheet to confirm them.
- A Google account and a Google Sheet with the columns above.
- A SignatureAPI test API key (
key_test_YOUR_KEY) from the dashboard. - Node.js 20 or newer to run the tests (optional).
- Open the script editor. In the sheet choose Extensions, then Apps Script. See the Apps Script overview.
- Add the files. Create
Core.gsandCode.gsand paste the contents of the files in this folder. In Project Settings, tick "Show appsscript.json manifest file in editor" and pasteappsscript.jsonso the script asks only for the scopes it uses. - Store the key. In Project Settings, under Script Properties, add
SIGNATUREAPI_KEYwith your test key. The code reads it withPropertiesService. Do not paste the key into the code. Anyone who can edit the script can read script properties, so share the script with care. - Understand the call.
httpFetch_wrapsUrlFetchApp.fetchwithmuteHttpExceptions: trueso an API error comes back as a status and body that the core turns into a readable message. - Run it. Reload the sheet, open the new SignatureAPI menu, choose "Send envelopes for new rows", and authorize the script when asked. For each row without an
envelope_id, the script posts toPOST /v1/envelopes, then writes the returned id and status into columns D and E. A failing row getserror: ...in the status column and the loop continues. A 200 ms pause between rows keeps you inside the rate limit.
- Install the trigger. In the editor, select
installRefreshTriggerand click Run once. It creates an installable time-driven trigger that runsrefreshStatusesevery hour. Approve the extra authorization prompt: managing triggers needs thescript.scriptappscope, whichappsscript.jsonlists. - What each run does.
refreshStatusesreads the first sheet. It skips rows without anenvelope_idand rows alreadycompleted,canceledorfailed. For every other row it callsGET /v1/envelopes/{id}with your key and writes the currentstatus. A failing read getserror: ...and the loop continues, with the same 200 ms pause between rows.
Why not a webhook? SignatureAPI counts a webhook delivery as successful only when the endpoint answers with a 2XX status. An Apps Script web app answers through a redirect to a one-time URL on script.googleusercontent.com (see Google's Content service guide), so it cannot acknowledge a delivery. Reading the status on a schedule avoids that.
Downloading the signed PDF. envelope.completed tells you the signing is done. It does not mean the PDF is ready. When a row turns completed, check deliverable.status in the same response: download only when it is generated. Until then deliverable.url is null, and the link expires after an hour. The refresh skips completed rows on later runs, so if you add a download, run it on every row that does not have its PDF yet, not only on rows that just turned completed.
npm test✔ core: builds a valid envelope payload from a sheet row
✔ core: pendingRows_ picks rows without an envelope id
✔ core: refuses a missing or live key
✔ core: rowsToRefresh_ picks rows whose envelope can still change
✔ core: getEnvelope_ refuses anything but an envelope UUID
✔ core: createEnvelope_ sends the key header and JSON body through the injected http function
✔ core: an API error becomes a readable exception
✔ shim: sendEnvelopesFromSheet writes the envelope id and status back to the row
✔ shim: a failing row gets an error status and the loop continues
✔ shim: refreshStatuses writes the current status of every open envelope and skips final rows
✔ shim: a failing read gets an error status and the refresh continues
✔ shim: installRefreshTrigger creates an hourly time-driven trigger for refreshStatuses
﹣ live: the core creates a test-mode envelope and reads it back # SIGNATUREAPI_KEY is not set, live test skipped
In the sheet, a processed row looks like this:
| name | role | envelope_id | status | |
|---|---|---|---|---|
| Jane Doe | jane.doe@example.com | Designer | eb4cf433-a8af-4161-b37b-7ef57d423e56 | processing |
- "Set the SIGNATUREAPI_KEY script property". The property is missing or has another name.
- "This example runs in test mode only". The key must start with
key_test_. - Authorization or "not permitted to call UrlFetchApp.fetch". The manifest scopes must include
script.external_request, and you must approve the prompt. See Google's authorization guide. 422in the status column. Usually a malformed email address in the row.- Script runs twice and creates duplicates. Rows with an
envelope_idare skipped, so a second run only sends new rows. If a run stops halfway, check the sheet before re-running. - Statuses never change. Check that the trigger exists (Triggers, in the editor's left menu) and that the sheet with the envelopes is the first sheet of the spreadsheet.
- "You do not have permission to call ScriptApp.newTrigger". The manifest must include the
script.scriptappscope. RuninstallRefreshTriggeragain and approve the prompt.