The Goodreads API in a Custom Function

September 17, 2017Web App, Google Apps Scriptgithub, urlfetchapp, custom functions, google sheets, goodreads api

Do you ever keep lists of books for your students on Goodreads? In this video I am showing how we can write a custom function to get data straight from the Goodreads API into a spreadsheet.

There are tons of things you can do with custom functions. I have made several videos demonstrating some of those things.

function GETAUTHOR(book) {
  book = encodeURIComponent(book);
  var url =
    'https://www.goodreads.com/search/index.xml?key=0VWQwPpAjauc0yyC4GFwdg&q=' +
    book;

  var response = UrlFetchApp.fetch(url).getContentText();

  var xml = XmlService.parse(response);

  var root = xml.getRootElement();

  var author = root
    .getChild('search')
    .getChild('results')
    .getChild('work')
    .getChild('best_book')
    .getChild('author')
    .getChild('name')
    .getValue();

  return author;
}

Check out my video about how you can use autocompleting to make your custom functions more accessible to collaborators.

jordan rhea

Jordan Rhea - I’m a front-end web developer. Follow me at @rheajt if you want to talk, discuss, or fix any of my code! I am passionate about using JavaScript in Google projects, but there are many more applications. I want to learn them all.