Create Dynamic QR Codes From a Google Sheet With Apps Script
To create dynamic QR codes from a Google Sheet, put one link per row with your own reference ID, paste a short Apps Script into the sheet, store your API token in the script properties, and run it from a menu. The script sends the rows to the QR Maker REST API in batches of 100 and writes the short link for each row back into the sheet. Running it again only fills in rows that are still empty, so it never creates duplicates.
When this is the right tool
A spreadsheet is where most product lists, table plans and campaign trackers already live. If someone on your team maintains that list by hand, creating the codes from the same sheet keeps the list and the codes in step without a developer in the loop. Typical cases are a code per product SKU for packaging, a code per table or room, or a code per sales rep or location for the same campaign.
If you need the codes inside your own application, call the API from your server instead. The REST API guide covers that.
What you need
- A QR Maker Business plan and an API token. Create the token under Settings, API Tokens. It starts with
qrs_and is shown once. - A Google Sheet with a header in row 1 and these columns: A
external_id, Btarget_url, Cname(optional), Dshort_link(leave empty), Estatus(leave empty).
The external_id is your own reference for the row: a SKU, a table number, a rep code. It must be unique within your account and may contain letters, digits, dots, underscores, colons and hyphens.
Step 1: add the script
Open the sheet, choose Extensions, then Apps Script, delete the placeholder code and paste the contents of google-sheets.gs. Save the project.
Step 2: store the token safely
In the Apps Script editor open Project Settings, scroll to Script properties and add a property named QR_TOKEN with your token as the value.
Do not paste the token into a cell. Everyone who can open the sheet can read its cells, and anyone holding the token can create, change and delete codes in your account. Script properties are only visible to people who can edit the script.
Step 3: run it
Reload the sheet. A new QR Maker menu appears. Choose "Create codes for new rows". The first time, Google asks you to authorize the script to edit the sheet and call an external service.
For each row that has an ID and a link but no short link yet, the script creates a dynamic code and fills in column D. Column E shows created, or already existed if a code with that ID was made earlier, or an error code if the row was rejected: INVALID_TARGET_URL for a link that is not a valid http or https address, or a code starting with URL_BLOCKED_ when the destination is refused by the safety checks, for example a link to another URL shortener.
Step 4: get the images
The short link in column D is what the printed code must encode. For the picture itself you have two options:
- Download each code as SVG from your QR Maker dashboard, where you can also apply your colours and logo.
- Fetch it from the API with
GET /v1/qrcodes/by-external-id/{external_id}?include=svg, which returns the code with the SVG text indata.svg. The Python example saves one SVG per row and is the quicker route for hundreds of codes.
Changing a destination later
Editing column B and running the script again does not move an existing code. That is deliberate: a POST with a known ID and a different link returns a conflict instead of silently redirecting a code that may already be printed. Change the destination in the dashboard, or call PATCH /v1/qrcodes/by-external-id/{external_id} with the new target_url.
Limits to keep in mind
Each run sends up to 100 rows per request, and each row that succeeds counts as one call against the 50,000 a month included in the Business plan. Rows that fail do not count. Apps Script itself stops after about six minutes per run, which is enough for several thousand rows; for more, run it again and it continues where it stopped.
FAQ
Do I need a server for this?
No. Apps Script runs on Google's servers, so the token never reaches a browser. That is also why this works even though the API does not accept calls from web pages.
Can colleagues with view-only access see my token?
No. Script properties are visible only to people who can edit the script project. Viewers and commenters cannot open them.
What if I delete a row?
Nothing happens to the code. Deleting a row only removes it from the sheet. Disable or delete the code in the dashboard, or with the API, if it should stop working.