Debugging external host communication with UrlFetchApp

There is a large and growing number of Web APIs available out there, many of which can extend our ability to obtain information or automate workflows from our Google Apps Scripts. Using the URL Fetch Service is a little more challenging than the majority of the services provided by Google, and when things don’t work it can be significantly more difficult to figure out than those services.

We’re going to look at debugging techniques unique to the UrlFetchApp today. For people unfamiliar with HTTP’s arcane messages and responses, we’ll get an overview that should help unlock this powerful capability.

Continue reading

Did you know? (You can log to a spreadsheet from client JavaScript!)

Google Apps Script has a Logger class, intended to help debug by enabling you to log the operation of your code, and examine run-time data. Viewing those logs is supported through the View > Logs menu option in the Google Apps Script editor.

Unfortunately, the built-in Logger doesn’t work in every situation. A requirement is that you must be running your script with an attached editor / debugger session, so that precludes logging trigger functions (when reacting to actual events), and many asynchronous operations such as UI interactions. If you want to compare results between sessions, you’ll be frustrated to find the output of the Logger is transient – the next time your script is executed, all previous logs are lost.

Today’s post is a quick tip for generating persistent logs from your whole application, including client-side JavaScript running in a user’s browser, such as an add-on sidebar or dialog, menu-driven functions, and autonomous functions such as triggers. Custom functions are not permitted to modify spreadsheet contents directly, so they are the one exception for this technique.

Continue reading