ESP32 logging to Google Sheets fails: Apps Script URL, redirects and permissions

Deploy the script as a web app and use the exec address, with access set to anyone.

What the message means

The script answers with a redirect. A client that does not follow it, or a deployment with limited access, gets an error page instead of your data.

Fix it in this order

  1. Deploy the script as a web app and copy the exec URL.
  2. Set access to anyone, knowing the link is then public, and keep it secret.
  3. Make the HTTP client follow redirects.
  4. Use HTTPS with the setting your library needs.
  5. After editing the script, deploy a new version, since the old one is still served.
  6. Test the URL in a browser first.

Why it happens

A request to an Apps Script web app first gets a redirect. Google’s documentation says content returned by the script is served from a one-time script.googleusercontent.com address, and that the HTTP client must be set to follow redirects. A client that stops at the redirect never sees your script’s reply.

Code edits do not reach the live web app on their own. Google’s documentation says to create a new version and point the deployment at it. The access setting is chosen when you deploy, so a setting that requires sign-in returns a login page instead of your data.

If you see this, do this

You seeDo this
Receives a login pageAccess is not set to anyone.
Gets a redirect code onlyFollow redirects.

HTTPS errors, HTTP error codes.

Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.

Why this happens

An Apps Script web app answers in two steps. The first request goes to the script.google.com address, which responds with a redirect. The second request, to a script.googleusercontent.com address, carries the real output. If the ESP32 HTTP client does not follow the redirect, it reports a redirect status code and never receives the text your script returned.

The deployment settings matter as well. ‘Execute as’ decides whose account runs the script, and ‘Who has access’ decides who may call it. If access requires sign-in, a request from a board gets an HTML login page back with a success code, which looks like a script bug. Test deployments use a different URL that works only for the owner. Only the deployment URL ending in /exec is the one a microcontroller should use.

How to confirm the cause

  • Paste the exec URL into a private browser window where you are not signed in. If you see a login page, the access setting is wrong. If you see your script’s text, the script side is fine.
  • Print the HTTP status code and the response body on the ESP32. A 302 or 303 means the redirect was not followed. A body that begins with HTML tags is a login or error page.
  • Open the Apps Script project and check the Executions list. A run that appears there means the request reached the script; no entry means it did not.
  • Add the values to the URL and test them from the browser first, for example ?temp=25.4, to check that e.parameter has the field you expect.
  • Confirm that you published a new version after changing the code. The old version keeps running until the deployment is updated.

Worked example

A small script and the ESP32 side that follows the redirect. The setInsecure call skips certificate checking, which is a trade-off to understand before using it outside a test:

// Apps Script, bound to the spreadsheet
function doGet(e) {
  SpreadsheetApp.getActiveSheet().appendRow([new Date(), e.parameter.temp]);
  return ContentService.createTextOutput('ok');
}

// ESP32 (Arduino core): WiFiClientSecure client; HTTPClient http;
client.setInsecure();
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
http.begin(client, "https://script.google.com/macros/s/YOUR_ID/exec?temp=25.4");
int code = http.GET();     // expect 200

Common mistakes

  • Using the test URL instead of the deployed /exec URL.
  • Editing the script and forgetting to deploy a new version.
  • Leaving spaces or symbols unencoded in the URL query.
  • Publishing the exec URL where others can read it. Anyone with the link can write to your sheet.
  • Sending data far more often than needed, which runs into Apps Script quotas.

If this did not fix it

  • The board’s connection itself: confirm Wi-Fi, DNS and the clock before blaming the script.
  • TLS needs memory. A board short of heap may fail the secure connection before sending anything.
  • The spreadsheet or script owner’s permissions may have changed, so the script runs but cannot write.