Skip to content

Diagnostic reference

Exception: Limit Exceeded: URLFetch URL Length

Fix Exception: Limit Exceeded: URLFetch URL Length in Google Apps Script when a GET URL exceeds 2,082 characters by moving data to a POST payload or batching.

Updated December 6, 2026

Apps Script error

Exception: Limit Exceeded: URLFetch URL Length.

What it means

Google Apps Script enforces a 2,082-character hard limit on every URL passed to UrlFetchApp.fetch() or UrlFetchApp.fetchAll(). Stuffing long filter lists, JSON payloads, or base64 strings into query parameters exceeds that limit before the request even leaves Google's servers.

Related error messages

  • Exception: Limit Exceeded: URLFetch POST Size.
  • Exception: Limit Exceeded: URLFetch Headers Size.

Before and after

The code before and after the fix.

Problem 4 changed lines
function syncBatchToApi(records) {
  // Fails when the serialized query string pushes the URL past 2,082 characters.
  const url =
    'https://api.example.com/import?rows=' + encodeURIComponent(JSON.stringify(records));
  return UrlFetchApp.fetch(url).getContentText();
}
Fixed 6 changed lines
function syncBatchToApi(records) {
  return UrlFetchApp.fetch('https://api.example.com/import', {
    method: 'post',
    contentType: 'application/json',
    payload: JSON.stringify({ rows: records }),
    muteHttpExceptions: true,
  }).getContentText();
}

How to fix it

  • When the endpoint accepts POST requests, move large parameters out of the query string into payload with contentType: application/json (or form encoding).
  • When calling a GET-only endpoint with a long list of IDs, split the IDs into smaller chunks so every URL stays well under 2,082 characters, then send chunks with UrlFetchApp.fetchAll().
  • Avoid double-encoding URLs with encodeURIComponent(), which inflates string length quickly.

Things to check

  • UrlFetchApp POST payloads allow up to 50 MB per request, compared with 2,082 characters for the URL itself.
  • myFunction flags static UrlFetchApp URLs over 2,082 characters before execution.

In the Apps Script editor

Catch errors like this before clicking Run.

myFunction (published as Error Checker for Google Apps Script on the Chrome Web Store) checks your code while you edit at script.google.com. Diagnostics, autocomplete, and rule-based quick fixes are free without an account, run in your browser, and request no Google Drive, Gmail, or Apps Script project OAuth scopes. Writing Apps Script with an AI coding agent? Connect the Apps Script MCP server to run the same static checks before pasting code.