Another place that Fiddler can be handy is if you are populating a sheet with data retrieved from an API. The examples use the Itunes API which will return tabular data as an array of JSON objects.
This class – Fiddler can be found in my cUseful library.
Here’s the key, and it’s also on github
Mcbr-v4SsYKJP7JMohttAZyz3TLx7pV4j
Populating an API with all fields from a JSON object
To start with, we need get some data from an API, and open a sheet to dump the data to.
// lets get some data from an API var result = getFromItunes ("REM"); if (!result.ok) throw result.content; // either create or use an existing sheet var ss = SpreadsheetApp.openById('1181bwZspoKoP98o4KuzO0S11IsvE59qCwiw4la9kL4o'); var sheet = ss.getSheetByName ("itunesapi") || ss.insertSheet("itunesapi");
Now This is easy, as we can just let fiddler do its thing. It’s a one liner of 3 methods chained together
function onOpen() { DocumentApp.getUi() .createMenu('Abstracts') .addItem('Get abstract', 'getAbstract') .addItem('Insert abstract', 'insertAbstract') .addToUi(); }
// first of all, create a sheet with all the data, clearing it first new cUseful.Fiddler(sheet.clearContents()) .setData (result.data.results) .dumpValues();
And you’ll get this.
Populating API with some fields from an API
In this case we want just a couple of fields. It’s almost exactly the same, except we filter out the columns we don’t want.
// we'll use fiddler to organize the data, and populate with selected fields from the API // after first clearing the sheet new cUseful.Fiddler(sheet.clearContents()) // use the data from the API .setData (result.data.results) // but just keep a couple of the columns .filterColumns (function (column) { return ["artistName","collectionName","trackName"].indexOf(column) !== -1; }) // and write it out .dumpValues();
Now this is the result

Adding to an existing sheet
Now it get’s a little more complicated. Rather than specifying the fields required, this time we’ll use whatever fields are already on the sheet, and append the new data to whatever is already there.
First get some additional data to append
// Now if the columns are already set var result = getFromItunes ("Lady Gaga"); if (!result.ok) throw result.content;
Now append it using these steps
- get the current data from the sheet into a fiddler
- get the column names
- filter the data returned from the API to reduce it to just the properties that match the column headings
- insert those at the end of the fiddler, and dump the values
//1 get the current data var fiddler = new cUseful.Fiddler(sheet); //2 these are the existing columns var columns = fiddler.getHeaders(); //3 this is the data with the stuff we dont want filtered out var filteredData = result.data.results.map (function (row) { return Object.keys(row).reduce (function (p,c) { if (columns.indexOf (c) !== -1) { p = row; } return p; },{}); }); //4 use the data from the API to insert at the end fiddler.insertRows (undefined ,filteredData.length , filteredData) // and write it all out .dumpValues();
The result – notice the new data added to the end, but only the columns that already existed

The Itunes API
Here’s function used to so an Itunes search. It’s only set to get the first 50 for the purposes of this demo and will need pagination to get more.
// generaral itunes search function getFromItunes (searchTerm) { var response = cUseful.Utils.expBackoff( function () { return UrlFetchApp.fetch("https://itunes.apple.com/search" + "?term=" + encodeURIComponent(searchTerm), { muteHttpExceptions:true }); }); return response.getResponseCode() === 200 ? { data: JSON.parse (response.getContentText()), ok:true } : { ok:false, code:response.getResponseCode(), content:response.getContentText() }; }
For more like this see Google Apps Scripts Snippets
- A functional approach to fiddling with sheet data
- A functional approach to updating master sheet
- A recursive extend function for Apps Script
- A webapp to share copies of the contents of folders
- Abstracting services with closures
- Add-on spinner
- Addressing namespace and library methods from google.script.run
- Anonymous user registration with the Apps Script PropertiesService
- Apps for Office – binding example comparison
- Apps Script as a proxy
- Apps Script const scoping problems
- Calculating image dimensions in server side apps script
- Calculating the last day of a given weekday in the month
- Canvasser
- Chaining JavaScript
- Changing class properties dynamically
- Checking the argument types in Apps Script
- Cleaning up a document format
- Cleaning up heading levels
- Column numbers to characters
- Composing functions and functional programming
- Configurable canvas meter
- Convert JSON to XML
- Converting SVG to PNG with JavaScript
- Converting timestamps to dates formula
- Copying canvas and svg images from your Add-on
- Copying to new host location
- Copying to new host location
- Counting script and library usage
- Create sha1 signatures with apps script
- Creating a key digest to use for a cache key or to compare content
- Creating a pile of files list from Google Drive
- Creating and working with transposed sheet data arrays
- Cross Origin Resource sharing (CORS)
- CryptoJS libraries for Google Apps Script
- Custom checking for exponential backoff
- Data wrangling with named columns in Google Spreadsheet
- Dealing with objects that are too large for the property or cache store
- Detecting Spreadsheet tables automatically with Google Apps Script
- Direction minimizer – other usages
- Do something useful with GAS in 5 minutes
- Dynamically creating tables with clusterize.js
- EasyCron Library
- ES6 JavaScript features
- Exponential backoff
- Exponential backoff for promises
- Fiddler and rangeLists
- Fiddling with text fields that look like dates
- Filling ranges in Google Sheets
- Finding a Drive App folder by path
- Finding where Drive hosting is being used in Sites
- Flattening an object with dot syntax
- Flattening and unflattening objects to spreadsheets
- Formatting GraphQL queries
- Formatting sheet column data with fiddler
- From notes to frequencies and back again
- From Xml to JSON
- Generating and managing random lists with JavaScript and Apps Script
- Generating coupon codes with expiry dates
- Generating test data for sheets and tables
- Get GAS library info
- Getting an htmlservice template from a library
- Getting insights into Sheets performance
- Google Drive as cache
- Header formatting with fiddler
- Highlight duplicate rows in a sheet – map and reduce
- Highlight duplicate rows in a sheet – map, filter and every
- How to determine what kind of object something is in Apps Script
- How to get stats about youtube videos in your channel with apps script
- How to pass non stringifyable objects to html service
- How to transpose spreadsheet data with apps script
- Identify duplicates on Drive
- Identifying hosted files
- Implementing a client side progress bar reporting on server side work for htmlService
- Importing Predictwise data
- Improved namespace pattern for Apps Script
- Including the stack in custom errors
- JavaScript closures – how, where and why
- JavaScript currying and functional programming
- JavaScript currying and functional programming – even more
- JavaScript recursion primer
- JSONP and JSON and Google Apps Script webapps
- Loading large JSON datasets into BigQuery with Apps Script
- Logging differences in strings in Apps Script
- Measuring library load speed
- Migrating user and script properties
- Minimizing maps directionfinder api calls
- More client server code sharing
- More recursion – parents and children
- More sheet data fiddling
- Multiple inserts in Fusion Tables
- Namespaces in libraries and scripts
- Normalizing the header level of blank paragraphs
- Optimizing sheet formatting with Apps Script
- Optimizing showing and hiding rows and columns
- Organizing asynchronous calls to google.script.run
- Organizing parallel streams of server calls with google.script.run promises
- Parallel process orchestration with HtmlService
- Passing data to html service
- Patching site html
- Proxy jsonp
- Pseudo binding in HTML service
- Queuing asynchronous tasks with rate limit and concurrency constraints
- Recursive async functions
- Removing duplicate paragraphs
- Reporting file, function and line number in Apps Script
- Resumable uploads – writing large files to Drive with Apps Script
- Reusing html stuff between Apps Script projects
- Roughly matching text
- Serving apps script to JavaScript app
- Sharing code between client and server
- Shortcut for adding nested properties to a JavaScript object
- Simple server side polling
- Sorting Google Sheet DisplayValues
- Squeezing more into (and getting more out of) Cache services
- Styling Gmail html tables
- Summarizing emails to a sheet
- SunCalc
- TimeSimmer : An adjustable timer for apps that need to speed up or slow down time
- Transform dates for add-on transfer
- Transposing sheet data
- Traversing a tree
- Unique values with data fiddler
- Unnesting data to sheet values
- Untangling with promises
- Use Drive properties to find app files
- Use promise instead of callback for settimeout
- Using Advanced Drive service to convert files
- Using Apps Script for xml json conversion
- Using array formulas to improve performance
- Using crossfilter with Google Apps Script
- Using D3 in server side Gas
- Using es6 promises server side in Apps Script
- Using Es6 with Apps Script
- Using exponential backoff with github api – dealing with data “in preparation”
- Using Google sheets via Bigquery from Apps Script
- Using named locks with Google Apps Scripts
- Using promises to orchestrate Html service polling
- Using promises with apps script
- Using the Itunes API with Apps Script
- Using the slideshare API from Apps Script
- Using timing functions to get insight into Sheets
- Watching docs for changes
- Watching for server side changes from the client html service
- What JavaScript engine is Apps Script running on?
- Why Base64
- Zipping to make stuff fit in cache or properties service.
More on this topic available here
- A functional approach to fiddling with sheet data
- Unique values with data fiddler
- More sheet data fiddling
- Fiddling with text fields that look like dates
- A functional approach to updating master sheet
- Populating sheets with API data using a Fiddler
- Header formatting with fiddler
- Formatting sheet column data with fiddler
- Styling Gmail html tables
- Sorting Google Sheet DisplayValues
Why not join our forum, follow the blog or follow me on twitter to ensure you get updates when they are available.