Skip to content

Generate Barcode Label PDFs from Google Sheets

Select product rows in Google Sheets, preserve text SKUs, submit a label batch, and save the completed PDF to Drive.

Gookit Team About 4 min read

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.

Before you begin

If this is your first API request, complete the three-label JSON walkthrough first. That lets you check the key, template and PDF separately from the spreadsheet integration.

Set up three columns

Use columns A, B and C in this order, with a header in row 1:

NameSKUQuantity
Trail BottleTB-10422
Desk TrayDT-20061

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.

The selected spreadsheet columns map to the saved template’s name and sku fields; column C supplies each record’s copy count.

Add the script and account settings

Open Extensions → Apps Script, paste the downloaded code into the script editor, and save the project. Open Project Settings → Script Properties, add the following values, then choose Save script properties:

PropertyValue
GOOKIT_API_KEYYour independent developer API key
GOOKIT_TEMPLATE_IDThe ID returned when you created the template

Enter the actual values, not the names of variables from your terminal. Google’s script properties guide describes these settings.

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.

This reference PDF was generated through the JSON batch API on September 20, 2026. It shows the expected label layout and copy counts; it is not evidence of an Apps Script or Drive test.

50 by 30 mm Trail Bottle label with a Code 128 barcode encoding TB-1042

Trail Bottle 2 copies

50 by 30 mm Desk Tray label with a Code 128 barcode encoding DT-2006

Desk Tray 1 copy

Sample output generated through Gookit Label API. Three pages, one label per page.

Download the three-label PDF ↓

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.

Start with the two-row example

Create a Gookit developer account and prepare the sample template. Once the JSON example works, run the two spreadsheet rows through submission, status checking and Drive download. For product scope and pricing, see Gookit Label API.