The first step in this assignment involves creating an API key, which is necessary for accessing the New York Times API. After obtaining the API key, the code focuses on using the Books API from the New York Times API options. The data is then retrieved by sending a GET request to a specific URL associated with the chosen API.
# Load required packages
library(jsonlite)
library(httr)
# API key
api_key <- "2lca2RgHicxRD5KnDOOgFb6na9UgO9ze"
# URL for the New York Times Books API
endpoint_url <- "https://api.nytimes.com/svc/books/v3/lists/current/hardcover-fiction.json"
# Query parameters
query_params <- list("api-key" = api_key)
# GET request to the API
response <- GET(url = endpoint_url, query = query_params)
# Checking if the request was successful
if (http_type(response) == "application/json") {
# Parse the JSON response
data <- fromJSON(content(response, "text", encoding = "UTF-8"))
# Extract and print the information from the response
print(data)
} else {
cat("API request failed.")
}
## $status
## [1] "OK"
##
## $copyright
## [1] "Copyright (c) 2023 The New York Times Company. All Rights Reserved."
##
## $num_results
## [1] 15
##
## $last_modified
## [1] "2023-10-25T22:24:41-04:00"
##
## $results
## $results$list_name
## [1] "Hardcover Fiction"
##
## $results$list_name_encoded
## [1] "hardcover-fiction"
##
## $results$bestsellers_date
## [1] "2023-10-21"
##
## $results$published_date
## [1] "2023-11-05"
##
## $results$published_date_description
## [1] "latest"
##
## $results$next_published_date
## [1] ""
##
## $results$previous_published_date
## [1] "2023-10-29"
##
## $results$display_name
## [1] "Hardcover Fiction"
##
## $results$normal_list_ends_at
## [1] 15
##
## $results$updated
## [1] "WEEKLY"
##
## $results$books
## rank rank_last_week weeks_on_list asterisk dagger primary_isbn10
## 1 1 0 1 0 0 0385548958
## 2 2 1 24 0 0 1649374046
## 3 3 2 76 0 0 038554734X
## 4 4 7 12 0 0 006332752X
## 5 5 3 7 0 0 1668016133
## 6 6 6 3 0 0 0593542819
## 7 7 10 51 0 0 0063251922
## 8 8 8 4 0 0 0525954996
## 9 9 11 25 0 0 0802162177
## 10 10 4 2 0 0 0525619992
## 11 11 0 25 0 0 0063204150
## 12 12 15 10 0 0 0593422945
## 13 13 5 2 0 0 1501101811
## 14 14 13 3 0 0 1984821954
## 15 15 0 1 0 0 0593598679
## primary_isbn13 publisher
## 1 9780385548953 Doubleday
## 2 9781649374042 Red Tower
## 3 9780385547345 Doubleday
## 4 9780063327528 Harper
## 5 9781668016138 Scribner
## 6 9780593542811 Putnam
## 7 9780063251922 Harper
## 8 9780525954996 Viking
## 9 9780802162175 Grove
## 10 9780525619994 Del Rey
## 11 9780063204157 Ecco
## 12 9780593422946 Riverhead
## 13 9781501101816 Scribner
## 14 9781984821959 Delacorte
## 15 9780593598672 Delacorte
## description
## 1 In a sequel to “The Firm,” Mitch McDeere, who is now a partner at the world’s largest law firm, gets caught up in a sinister plot.
## 2 Violet Sorrengail is urged by the commanding general, who also is her mother, to become a candidate for the elite dragon riders.
## 3 A scientist and single mother living in California in the 1960s becomes a star on a TV cooking show.
## 4 Three daughters, who return to their family orchard in the spring of 2020, learn about their mother’s relationship with a famous actor.
## 5 The private detective Holly Gibney investigates whether a married pair of octogenarian academics had anything to do with Bonnie Dahl’s disappearance.
## 6 The 33rd book in the Prey series. Davenport and Flowers investigate the murder of a federal judge and his two young sons.
## 7 Winner of a 2023 Pulitzer Prize for fiction. A reimagining of Charles Dickens’s “David Copperfield” set in the mountains of southern Appalachia.
## 8 The fifth book in the Kingsbridge series. Change and turmoil affect various aspects of society in the latter part of the 18th century.
## 9 Three generations of a family living on South India’s Malabar Coast suffer the loss of a family member by drowning.
## 10 An orphan who is the body double for a royal heir and a woman with magical abilities are drawn into the underworld of the city-state of Castellane.
## 11 A widow working the night shift at the Sowell Bay Aquarium is aided in solving a mystery by a giant Pacific octopus living there.
## 12 Secrets held by the residents of a dilapidated neighborhood come to life when a skeleton is found at the bottom of a well.
## 13 The second book in the Scott Brodie and Maggie Taylor series. After a mission in Venezuela, Brodie and Taylor search for the murderer of a fellow agent.
## 14 The former head of a Hollywood studio thinks the unfinished novel written by a woman he hired to get his affairs in order could be adapted for the screen.
## 15 After her grandmother’s death, a woman goes on a journey that might change the past and the future.
## price title author
## 1 0.00 THE EXCHANGE John Grisham
## 2 0.00 FOURTH WING Rebecca Yarros
## 3 0.00 LESSONS IN CHEMISTRY Bonnie Garmus
## 4 0.00 TOM LAKE Ann Patchett
## 5 0.00 HOLLY Stephen King
## 6 0.00 JUDGMENT PREY John Sandford
## 7 0.00 DEMON COPPERHEAD Barbara Kingsolver
## 8 0.00 THE ARMOR OF LIGHT Ken Follett
## 9 0.00 THE COVENANT OF WATER Abraham Verghese
## 10 0.00 SWORD CATCHER Cassandra Clare
## 11 0.00 REMARKABLY BRIGHT CREATURES Shel Van Pelt
## 12 0.00 THE HEAVEN & EARTH GROCERY STORE James McBride
## 13 0.00 BLOOD LINES Nelson DeMille and Alex DeMille
## 14 0.00 SECOND ACT Danielle Steel
## 15 0.00 THE UNMAKING OF JUNE FARROW Adrienne Young
## contributor contributor_note
## 1 by John Grisham
## 2 by Rebecca Yarros
## 3 by Bonnie Garmus
## 4 by Ann Patchett
## 5 by Stephen King
## 6 by John Sandford
## 7 by Barbara Kingsolver
## 8 by Ken Follett
## 9 by Abraham Verghese
## 10 by Cassandra Clare
## 11 by Shelby Van Pelt
## 12 by James McBride
## 13 by Nelson DeMille and Alex DeMille
## 14 by Danielle Steel
## 15 by Adrienne Young
## book_image
## 1 https://storage.googleapis.com/du-prd/books/images/9780385548953.jpg
## 2 https://storage.googleapis.com/du-prd/books/images/9781649374042.jpg
## 3 https://storage.googleapis.com/du-prd/books/images/9780385547345.jpg
## 4 https://storage.googleapis.com/du-prd/books/images/9780063327528.jpg
## 5 https://storage.googleapis.com/du-prd/books/images/9781668016138.jpg
## 6 https://storage.googleapis.com/du-prd/books/images/9780593542811.jpg
## 7 https://storage.googleapis.com/du-prd/books/images/9780063251922.jpg
## 8 https://storage.googleapis.com/du-prd/books/images/9780525954996.jpg
## 9 https://storage.googleapis.com/du-prd/books/images/9780802162175.jpg
## 10 https://storage.googleapis.com/du-prd/books/images/9780525619994.jpg
## 11 https://storage.googleapis.com/du-prd/books/images/9780063204157.jpg
## 12 https://storage.googleapis.com/du-prd/books/images/9780593422946.jpg
## 13 https://storage.googleapis.com/du-prd/books/images/9781501101816.jpg
## 14 https://storage.googleapis.com/du-prd/books/images/9781984821959.jpg
## 15 https://storage.googleapis.com/du-prd/books/images/9780593598672.jpg
## book_image_width book_image_height
## 1 329 500
## 2 309 500
## 3 328 500
## 4 331 500
## 5 327 500
## 6 331 500
## 7 329 500
## 8 330 500
## 9 320 500
## 10 329 500
## 11 329 500
## 12 331 500
## 13 331 500
## 14 329 500
## 15 331 500
## amazon_product_url age_group
## 1 https://www.amazon.com/dp/0385548958?tag=NYTBSREV-20
## 2 https://www.amazon.com/dp/1649374046?tag=NYTBSREV-20
## 3 https://www.amazon.com/dp/038554734X?tag=NYTBSREV-20
## 4 https://www.amazon.com/dp/006332752X?tag=NYTBSREV-20
## 5 https://www.amazon.com/dp/1668016133?tag=NYTBSREV-20
## 6 https://www.amazon.com/dp/0593542819?tag=NYTBSREV-20
## 7 https://www.amazon.com/dp/0063251922?tag=NYTBSREV-20
## 8 https://www.amazon.com/dp/0525954996?tag=NYTBSREV-20
## 9 https://www.amazon.com/dp/0802162177?tag=NYTBSREV-20
## 10 https://www.amazon.com/dp/0525619992?tag=NYTBSREV-20
## 11 https://www.amazon.com/dp/0063204150?tag=NYTBSREV-20
## 12 https://www.amazon.com/dp/0593422945?tag=NYTBSREV-20
## 13 https://www.amazon.com/dp/1501101811?tag=NYTBSREV-20
## 14 https://www.amazon.com/dp/1984821954?tag=NYTBSREV-20
## 15 https://www.amazon.com/dp/0593598679?tag=NYTBSREV-20
## book_review_link first_chapter_link sunday_review_link article_chapter_link
## 1
## 2
## 3
## 4
## 5
## 6
## 7
## 8
## 9
## 10
## 11
## 12
## 13
## 14
## 15
## isbns
## 1 0385548958, 0385548966, 9780385548953, 9780385548960
## 2 1649374046, 1649374089, 1705085059, 1705085032, 9781649374042, 9781649374080, 9781705085059, 9781705085035
## 3 038554734X, 0593507533, 0385547374, 0593862406, 9780385547345, 9780593507537, 9780385547376, 9780593862407
## 4 006332752X, 0063327546, 9780063327528, 9780063327542
## 5 1668016133, 1668014955, 1797161407, 9781668016138, 9781668014950, 9781797161402
## 6 0593542819, 0593542827, 9780593542811, 9780593542828
## 7 0063251922, 006325199X, 0063251981, 9780063251922, 9780063251991, 9780063251984
## 8 0525954996, 059365532X, 9780525954996, 9780593655320
## 9 0802162177, 1705070248, 1705070221, 9780802162175, 9781705070246, 9781705070222
## 10 0525619992, 0593600142, 0593724704, 0525620001, 9780525619994, 9780593600146, 9780593724705, 9780525620006
## 11 0063204150, 0063204185, 0063204169, 9780063204157, 9780063204188, 9780063204164
## 12 0593422945, 0593422961, 0593684125, 0593684141, 9780593422946, 9780593422960, 9780593684122, 9780593684146
## 13 1501101811, 1501101838, 9781501101816, 9781501101830
## 14 1984821954, 1984821962, 9781984821959, 9781984821966
## 15 0593598679, 9780593598672
## buy_links
## 1 Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop, IndieBound, https://www.amazon.com/dp/0385548958?tag=NYTBSREV-20, https://goto.applebooks.apple/9780385548953?at=10lIEQ, https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780385548953, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FTHE%2BEXCHANGE%2FJohn%2BGrisham%2F9780385548953, https://bookshop.org/a/3546/9780385548953, https://www.indiebound.org/book/9780385548953?aff=NYT
## 2 Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop, IndieBound, https://www.amazon.com/dp/1649374046?tag=NYTBSREV-20, https://goto.applebooks.apple/9781649374042?at=10lIEQ, https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9781649374042, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FFOURTH%2BWING%2FRebecca%2BYarros%2F9781649374042, https://bookshop.org/a/3546/9781649374042, https://www.indiebound.org/book/9781649374042?aff=NYT
## 3 Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop, IndieBound, https://www.amazon.com/dp/038554734X?tag=NYTBSREV-20, https://goto.applebooks.apple/9780385547345?at=10lIEQ, https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780385547345, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FLESSONS%2BIN%2BCHEMISTRY%2FBonnie%2BGarmus%2F9780385547345, https://bookshop.org/a/3546/9780385547345, https://www.indiebound.org/book/9780385547345?aff=NYT
## 4 Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop, IndieBound, https://www.amazon.com/dp/006332752X?tag=NYTBSREV-20, https://goto.applebooks.apple/9780063327528?at=10lIEQ, https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780063327528, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FTOM%2BLAKE%2FAnn%2BPatchett%2F9780063327528, https://bookshop.org/a/3546/9780063327528, https://www.indiebound.org/book/9780063327528?aff=NYT
## 5 Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop, IndieBound, https://www.amazon.com/dp/1668016133?tag=NYTBSREV-20, https://goto.applebooks.apple/9781668016138?at=10lIEQ, https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9781668016138, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FHOLLY%2FStephen%2BKing%2F9781668016138, https://bookshop.org/a/3546/9781668016138, https://www.indiebound.org/book/9781668016138?aff=NYT
## 6 Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop, IndieBound, https://www.amazon.com/dp/0593542819?tag=NYTBSREV-20, https://goto.applebooks.apple/9780593542811?at=10lIEQ, https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780593542811, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FJUDGMENT%2BPREY%2FJohn%2BSandford%2F9780593542811, https://bookshop.org/a/3546/9780593542811, https://www.indiebound.org/book/9780593542811?aff=NYT
## 7 Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop, IndieBound, https://www.amazon.com/dp/0063251922?tag=NYTBSREV-20, https://goto.applebooks.apple/9780063251922?at=10lIEQ, https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780063251922, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FDEMON%2BCOPPERHEAD%2FBarbara%2BKingsolver%2F9780063251922, https://bookshop.org/a/3546/9780063251922, https://www.indiebound.org/book/9780063251922?aff=NYT
## 8 Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop, IndieBound, https://www.amazon.com/dp/0525954996?tag=NYTBSREV-20, https://goto.applebooks.apple/9780525954996?at=10lIEQ, https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780525954996, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FTHE%2BARMOR%2BOF%2BLIGHT%2FKen%2BFollett%2F9780525954996, https://bookshop.org/a/3546/9780525954996, https://www.indiebound.org/book/9780525954996?aff=NYT
## 9 Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop, IndieBound, https://www.amazon.com/dp/0802162177?tag=NYTBSREV-20, https://goto.applebooks.apple/9780802162175?at=10lIEQ, https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780802162175, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FTHE%2BCOVENANT%2BOF%2BWATER%2FAbraham%2BVerghese%2F9780802162175, https://bookshop.org/a/3546/9780802162175, https://www.indiebound.org/book/9780802162175?aff=NYT
## 10 Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop, IndieBound, https://www.amazon.com/dp/0525619992?tag=NYTBSREV-20, https://goto.applebooks.apple/9780525619994?at=10lIEQ, https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780525619994, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FSWORD%2BCATCHER%2FCassandra%2BClare%2F9780525619994, https://bookshop.org/a/3546/9780525619994, https://www.indiebound.org/book/9780525619994?aff=NYT
## 11 Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop, IndieBound, https://www.amazon.com/dp/0063204150?tag=NYTBSREV-20, https://goto.applebooks.apple/9780063204157?at=10lIEQ, https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780063204157, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FREMARKABLY%2BBRIGHT%2BCREATURES%2FShel%2BVan%2BPelt%2F9780063204157, https://bookshop.org/a/3546/9780063204157, https://www.indiebound.org/book/9780063204157?aff=NYT
## 12 Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop, IndieBound, https://www.amazon.com/dp/0593422945?tag=NYTBSREV-20, https://goto.applebooks.apple/9780593422946?at=10lIEQ, https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780593422946, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FTHE%2BHEAVEN%2B%2526%2BEARTH%2BGROCERY%2BSTORE%2FJames%2BMcBride%2F9780593422946, https://bookshop.org/a/3546/9780593422946, https://www.indiebound.org/book/9780593422946?aff=NYT
## 13 Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop, IndieBound, https://www.amazon.com/dp/1501101811?tag=NYTBSREV-20, https://goto.applebooks.apple/9781501101816?at=10lIEQ, https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9781501101816, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FBLOOD%2BLINES%2FNelson%2BDeMille%2Band%2BAlex%2BDeMille%2F9781501101816, https://bookshop.org/a/3546/9781501101816, https://www.indiebound.org/book/9781501101816?aff=NYT
## 14 Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop, IndieBound, https://www.amazon.com/dp/1984821954?tag=NYTBSREV-20, https://goto.applebooks.apple/9781984821959?at=10lIEQ, https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9781984821959, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FSECOND%2BACT%2FDanielle%2BSteel%2F9781984821959, https://bookshop.org/a/3546/9781984821959, https://www.indiebound.org/book/9781984821959?aff=NYT
## 15 Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop, IndieBound, https://www.amazon.com/dp/0593598679?tag=NYTBSREV-20, https://goto.applebooks.apple/9780593598672?at=10lIEQ, https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780593598672, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FTHE%2BUNMAKING%2BOF%2BJUNE%2BFARROW%2FAdrienne%2BYoung%2F9780593598672, https://bookshop.org/a/3546/9780593598672, https://www.indiebound.org/book/9780593598672?aff=NYT
## book_uri
## 1 nyt://book/52c31163-754f-58c8-90d8-ea1f297f7030
## 2 nyt://book/106c2cf0-7d20-51b1-bad4-91c3ebcd131a
## 3 nyt://book/717e0ead-9782-567d-af27-d9a6cfb1856f
## 4 nyt://book/2430a2de-ff8f-5a25-88f8-50bd8137fa92
## 5 nyt://book/24a09504-4f13-5e38-a4a0-f6b8978e5ca7
## 6 nyt://book/0dfbdfc8-86ba-5616-a3fb-697390a00f32
## 7 nyt://book/dd6e4f9d-d082-552d-b888-7276a25b5aca
## 8 nyt://book/155373ee-247b-58fd-b6bc-ca6ed976ef23
## 9 nyt://book/5ebf1d34-4c68-560a-8330-7e65bedaaa1a
## 10 nyt://book/0140d611-8157-5401-a78e-6fd6807b1542
## 11 nyt://book/206a5e83-12f4-5ea9-8e63-1da5470a6ef5
## 12 nyt://book/7d47b076-7ad7-539c-a051-6664384636b9
## 13 nyt://book/74a9ef0d-b0b2-564c-9fbd-473906820032
## 14 nyt://book/2864bf9e-5327-5030-bccd-aef1a71a8782
## 15 nyt://book/459ade2c-bd75-5085-8195-dc451b6a15ee
##
## $results$corrections
## list()
After the Books API data has been loaded, the code further processes the information. It extracts and organizes specific columns, including the rank, title, author, publisher, and description. Finally, it arranges the data by the rank column and displays it in an interactive datatable for analysis and exploration.
library(tidyr)
library(DT)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
data_frame <- data$results$books
datatable(data_frame %>%
select(
rank, title, author, publisher, description
) %>%
arrange(rank))