What is UrlFetchApp in Google Sheets?
UrlFetchApp lets Apps Script send HTTP requests to external URLs and read the response. You use it to pull data from APIs, post webhooks, or sync sheet rows with tools like Slack, Stripe, or your own server. It is the bridge between your spreadsheet and the rest of the web.
When to use it
Use UrlFetchApp when sheet data must talk to an outside system: fetch exchange rates, push new leads to a CRM, call a REST API on a schedule, or verify a license key.
When to skip it
Skip UrlFetchApp when a built-in function like IMPORTXML or GOOGLEFINANCE is enough, or when a no-code connector handles the integration with less code to maintain.
How it works
-
1
Build a URL and optional options object with method, headers, payload, or muteHttpExceptions.
-
2
Call UrlFetchApp.fetch(url, options) and read the response with getContentText() or getBlob().
-
3
Parse JSON with JSON.parse when the API returns JSON.
-
4
Run once manually to authorize external request permissions.
-
5
Wrap calls in try/catch and log status codes when muteHttpExceptions is true.
-
6
Respect daily UrlFetch quotas and avoid tight loops that hammer the same endpoint.
Examples in Google Sheets
Daily rate lookup
A time-driven trigger fetches a JSON rate from a public API and writes the value to a Rates tab for formulas to reference.
Webhook on new row
onFormSubmit posts e.values as JSON to your server webhook URL so a database updates when a form arrives.
Slack alert
When a status cell changes to Urgent, UrlFetchApp posts a short message payload to a Slack incoming webhook URL.
Better Sheets resources
Common mistakes
-
Storing API keys in client-side HTML where anyone can view source instead of Script Properties.
-
Calling UrlFetchApp inside onEdit on every keystroke, slowing editors and burning quota.
-
Not setting muteHttpExceptions, so a 404 throws and stops the whole script.
-
Forgetting Content-Type application/json when posting JSON bodies.
-
Parsing response text as JSON without checking for empty or HTML error pages first.
Frequently asked questions
- Can UrlFetchApp do POST requests?
- Yes. Pass method POST and a payload string or object in the options parameter.
- Do I need to enable an API in Cloud Console?
- Basic UrlFetchApp works without extra setup. Some Google APIs need enabling under Advanced Google services.
- What are UrlFetchApp quotas?
- Google limits URL fetches per day per account. Check current Apps Script quota documentation for your account type.
- Can UrlFetchApp send headers?
- Yes. Include an headers object in options, for example Authorization Bearer tokens or API keys.
- Why does my fetch return authorization errors?
- The remote server may reject your token, block Google IPs, or require OAuth you have not implemented.
- Can I download a file with UrlFetchApp?
- Yes. Use getBlob() on the response and save with DriveApp or attach via MailApp.
- Is UrlFetchApp allowed in simple triggers?
- Simple triggers like onEdit cannot call UrlFetchApp. Use an installable trigger after authorization.
- How do I debug API responses?
- Logger.log the status code and first part of getContentText(), or write failures to a Debug tab with timestamps.
Related Tutorials
Watch how UrlFetchApp works
Spreadsheet Automation 101 Lesson 4: UrlFetchApp
Convert Google Sheets into a REST API
Quickstart Tutorial OpenAI API in Google Sheets
Automatic Screenshots in Apps Script
Scrape Google Maps
Curate Google Sheets Easily - Automatic Bookmarklet Maker
Related blog posts
Guides that explain UrlFetchApp in more depth.
Extract URLs from Google Sheets
Extract url from hyperlink google sheets.Skip the Command K. This Google Sheet tutorial will make it easier for you to extract URLS from Google Sheets.
Read post →Learn to Code in Google Sheets, For Programmers | For Advanced Google Sheet Users
If you know how to code, you'll learn in this step-by-step tutorial how to code in Google Sheets.
Read post →Google Sheets AI Formula
Does Google Sheets have an AI Formula? No but you can add one. Simple use Apps Script to add an AI formula to your sheets. You can use your own AI from Open AI and this comes out to be much cheaper than even $20 a month for ChatGPT at times. Depends on your use of AI. I just updated Better Sheets' AI apps script to use Open AI Omni. Get the full script here. Can I use ChatGPT in Google Sheets? No but you can create ChatGPT in Google Sheets. Let me show you! But I need help with Google...
Read post →Related terms
Google Sheets API
The Google Sheets API lets other programs read and update spreadsheets over HTTP using JSON. It is how dashboards, backends, and mobile apps sync data without opening the Google Sheets UI. Apps Script inside a file is simpler for sheet owners; the API fits systems built in Python, Node, or other stacks.
Read guide →Apps Script triggers
Triggers tell Apps Script when to run a function: on edit, on open, on a schedule, or when a form is submitted. Simple triggers use reserved names like onEdit. Installable triggers are created in the Apps Script Triggers page and can do more, including running as a specific user or on a timer.
Read guide →Google Sheets automation
Automation means work happens without repeating the same clicks every day: imports update, emails send, rows move, and dashboards refresh. In Sheets, automation usually stacks built-in features, Apps Script, and sometimes the Sheets API or add-ons. Start with the lightest tool that still solves the job.
Read guide →Apps Script web apps
A web app turns your script into a URL that runs doGet or doPost when someone visits or posts data. The page can read and write your spreadsheet behind the scenes, which is useful for simple forms, internal tools, and lightweight APIs without standing up a separate server.
Read guide →Done reading about UrlFetchApp?
Membership unlocks 600+ tutorials, unlimited generators, and every template. Practical lessons. Zero fluff.
Need this once
Jump to a free tool or a single tutorial for this topic.
Learning Sheets for real
Unlock the full library, generators, and templates with membership.