Select product rows in Google Sheets and generate a PDF using a saved Gookit template. The Apps Script example reads the selected names, SKUs and quantities, submits one batch, and lets you check that job separately before saving its PDF to Drive.
This is a script you add to your own spreadsheet, not a native Gookit Sheets connector. Its data mapping and job handling have offline tests; Google authorization and saving the file to Drive have not been tested in a live workspace. Start with a copy containing fictional product data and verify the complete flow before using it for real batches.
Set up three columns
Use columns A, B and C in this order, with a header in row 1:
| Name | SKU | Quantity |
|---|---|---|
| Trail Bottle | TB-1042 | 2 |
| Desk Tray | DT-2006 | 1 |
Format SKU as plain text before entering identifiers with leading zeros. The script reads displayed values; it preserves 0001042 if the sheet still contains that representation, but cannot restore a zero that has already been lost.
Create the name/SKU template from the batch guide and retain its ID. The selected spreadsheet columns map to that template’s name and sku fields.
Add the script and account settings
Open Extensions → Apps Script, paste the file, and save the project. Add two script properties in project settings: GOOKIT_API_KEY and GOOKIT_TEMPLATE_ID. The first is your independent developer key; the second is the saved template ID.
This example uses PropertiesService for configuration and per-user job state. Restrict editing access to trusted collaborators: script properties are not a secret vault against people who can edit and run the script.
Submit the selected rows once
Select A2:C3, excluding the header. Run submitSelectedLabels from Apps Script and review Google’s requested authorization for the script. The function rejects selections outside columns A:C, blank fields, fractional quantities and batches above 1,000 labels.
It sends a server-side request using UrlFetchApp. After a 202 response, it saves the job ID in your user properties and tells you to check the job. Do not run two submissions concurrently: this small manual example is not a multi-user print queue.
Check and save the PDF
Wait a few seconds and run checkLabelJob. If the job is pending or processing, the function leaves the saved ID in place. Check again later rather than submitting again.
When the job completes, the script downloads its URL without the API key and creates gookit-labels.pdf in your Drive. The alert contains the Drive file link. The example does not change the file’s sharing settings; choose access deliberately if a warehouse team needs the file.
With the sample ROLL template, verify three pages and the two expected SKUs. Check a physical print on matching stock before applying the script to a large inventory list.
Understand the recovery boundary
The saved-job guard prevents an ordinary second submission while your user has an unfinished job. It is not an idempotency guarantee or a lock across collaborators. If the POST timed out, it may have been accepted even if no job ID was saved.
Keep failed or uncertain jobs for investigation. Only clear GOOKIT_PENDING_JOB from user properties after you have resolved that job and intentionally want a new batch. A failed Drive write leaves the job ID available for another check; a partially completed write can require checking Drive for an existing file.
A 429 status should be checked again only after Retry-After. The script performs one status request per manual run, keeping the control visible instead of using a long background loop.