Question

I feel like I should be able to figure this out but I'm stuck on the syntax for google api calls in node using google-api-nodejs-client.

Here is my code to query for books that accepts a search string as 'query', and this works just fine.

client.books.volumes.list({q: query}).withAuthClient(oath2Client);

As it is now, it returns a list of books with all of the data pertaining to those books. But how do I change this to filter the results to say just id, title, and authors?

Was it helpful?

Solution

According to the API documentation at https://developers.google.com/books/docs/v1/reference/volumes/list, you can "Restrict information returned to a set of selected fields." using the projection parameter. So the call might look something like

client.books.volumes.list({
  q: query,
  projection: 'lite'
}).withAuthClient(oauth2Client);

Although the documentation doesn't say so, it does look like you can also use the "fields" parameter to specify exactly which fields you want. Use the field editor as part of the "Try it!" block on that page to get the exact configuration you want, but something like this should also work to get just the book ID, the title, and authors:

client.books.volumes.list({
  q: query,
  fields: 'items(id,volumeInfo(authors,title))'
}).withAuthClient(oauth2Client);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top