Assume the following simple setup for sending telemetry to Google Sheets:
Curl -> Google Apps Script deployed as Web App -> Google Sheet -> Cell 1:1
Google Apps script is a simple doPost() that prints the json payload into the Cell 1:1 of the Sheet it is an extension of.
This works fine for the most part. Data sent by Curl is being received by Google Sheet. However, the response from google's server comes with an Error 405: Moved Temporarily:
<H1>Moved Temporarily</H1> The document has moved <A HREF="https://script.googleusercontent.com/macros/echo?user_content_key=balhblah" But, even though the response indicates an error, the data still appears in the Google Sheet. What is the reason for 405-ing, and why does Google still accept data despite throwing an error?
Curl script line:
curl -X POST "https://script.google.com/macros/s/xxxxxxxx/exec" -H "Content-Type: application/json" Google Apps Script code for the doPost():
function doPost(e) { var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var rawData; if (e.postData) { rawData = e.postData.contents; // get the request's payload } else { rawData = ""; // fallback to empty string if there is no data } // Append to the end of the sheet sheet.appendRow([rawData]); return ContentService .createTextOutput("Data received."); }
-Lat the start of the command