# Generate a QR code in Google Apps Script

> UrlFetchApp.fetch the keyless API and you have a QR blob: save it to Drive with DriveApp.createFile, place it in a Sheet with insertImage, or write =IMAGE() formulas into a column so every row gets its own code. No key, no OAuth scopes beyond fetch and the destination service.

Source: https://useqr.app/docs/developers/generate-a-qr-code-in-google-apps-script · Last reviewed 2026-08-21 · UseQR is free forever, no signup.

---

## First: do you even need a script?

If the goal is "a QR code next to each URL in my sheet", the no-code `=IMAGE()` formula
does it without Apps Script at all. That route is written up in
[how to make a QR code in Google Sheets](/docs/how-to/how-to-make-a-qr-code-in-google-sheets).
Reach for a script when you need files in Drive, codes in Docs or Slides, batch output, or
regeneration on a trigger.

## Fetch a code, save it to Drive

The [keyless API](/docs/developers/free-qr-code-api-no-key) needs no key, so
`UrlFetchApp` is the whole integration:

```javascript
function saveQrToDrive() {
  const url = "https://useqr.app/api/v1/qr?data="
    + encodeURIComponent("https://example.com") + "&size=1024";
  const blob = UrlFetchApp.fetch(url).getBlob().setName("qr.png");
  DriveApp.createFile(blob);
}
```

`encodeURIComponent` is mandatory, an unencoded `&` in the payload truncates the code's
contents silently. Add `format=svg` for vector output destined for
[print](/docs/print/qr-code-size-for-print).

## A code per row in a Sheet

Writing `=IMAGE()` formulas from script scales cleanly, because Sheets then fetches and
displays each image itself:

```javascript
function qrColumn() {
  const sheet = SpreadsheetApp.getActiveSheet();
  const urls = sheet.getRange("A2:A101").getValues().flat().filter(String);
  urls.forEach((u, i) => {
    sheet.getRange(i + 2, 2).setFormula(
      '=IMAGE("https://useqr.app/api/v1/qr?data=' + encodeURIComponent(u) + '&size=512")'
    );
  });
}
```

For an image anchored over the grid rather than in a cell, `sheet.insertImage(blob, 3, 2)`
places a fetched blob at column 3, row 2. Spreadsheet-driven batch workflows more broadly
(including CSV export routes) are covered in
[QR codes from a spreadsheet](/docs/how-to/how-to-make-qr-codes-from-a-spreadsheet).

## Quotas, and why formulas beat fetch loops

`UrlFetchApp` is quota-limited (20,000 calls per day on consumer accounts), and a fetch
loop over a big sheet burns it. The formula approach spends zero fetch quota (the
requests come from Sheets, not your script), and the API's immutable caching means each
distinct payload is only ever fetched once anyway.

## Regenerate on a trigger

Because static codes never expire, regeneration is only needed when the *source data*
changes. An installable trigger keeps a column honest:

```javascript
function onEditInstallable(e) {
  if (e.range.getColumn() !== 1) return;    // only react to URL edits in column A
  const row = e.range.getRow();
  const value = e.range.getValue();
  if (!value) return;
  e.source.getActiveSheet().getRange(row, 2).setFormula(
    '=IMAGE("https://useqr.app/api/v1/qr?data=' + encodeURIComponent(value) + '")'
  );
}
```

Install it via Triggers → Add Trigger → On edit. Time-driven triggers suit nightly batch
jobs that pull rows and write PNGs to a Drive folder. If your automation lives outside
Google's stack, the same API drops into
[n8n, Zapier and Make](/docs/developers/qr-codes-in-n8n-zapier-and-make) with an HTTP
node.

## FAQ

### How do I generate a QR code in Google Apps Script?
UrlFetchApp.fetch the keyless API URL with your data encoded, call getBlob(), and hand the blob to DriveApp, Sheets, Docs or Slides.

### How do I put a QR code in every row of a Google Sheet?
Loop the rows and setFormula an =IMAGE() call per row, or skip scripting entirely and drag the formula down, no quota is consumed either way.

### Does UrlFetchApp have a limit?
Yes: daily quotas apply (20,000 fetches on consumer accounts). Prefer =IMAGE() formulas for bulk sheets so Sheets does the fetching instead of your script.

### Can the QR codes update automatically when data changes?
Yes. An installable on-edit trigger can rewrite the formula for the edited row, and time-driven triggers handle scheduled batch regeneration.

## Try it

- https://useqr.app/url
- https://useqr.app/json
- https://useqr.app/validate
