The New York Times web site provides a rich set of APIs, as described here: https://developer.nytimes.com/apis. You’ll need to start by signing up for an API key. Your task is to choose one of the New York Times APIs, construct an interface in R to read in the JSON data, and transform it into an R DataFrame.

Loading required libraries:

library(httr)
library(jsonlite)
library(kableExtra)

API key:

api.key <- '2UA3cNoRNwal6giF6kSPsQFfQr1dppUa'

Get data from API: US and World

# url for United States data
top.stories.us.url <- paste("https://api.nytimes.com/svc/topstories/v2/us.json?api-key=", api.key, sep='')

# convert json data received from api to a data frame
us.top.stories.data <- fromJSON(top.stories.us.url) %>% 
  as.data.frame()


# url for world data
top.stories.world.url <- paste("https://api.nytimes.com/svc/topstories/v2/world.json?api-key=", api.key, sep='')

# convert json data received from api to a data frame
world.top.stories.data <- fromJSON(top.stories.world.url) %>% 
  as.data.frame()

top.stories.us.and.world<- rbind(us.top.stories.data,world.top.stories.data)
kbl(top.stories.us.and.world[1:5,]) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed"))
status copyright section last_updated num_results results.section results.subsection results.title results.abstract results.url results.uri results.byline results.item_type results.updated_date results.created_date results.published_date results.material_type_facet results.kicker results.des_facet results.org_facet results.per_facet results.geo_facet results.multimedia results.short_url
OK Copyright (c) 2025 The New York Times Company. All Rights Reserved. U.S. News 2024-06-27T14:23:45-04:00 24 us Musk Says ‘Destiny of Humanity’ Rests on Wisconsin Judicial Race “What’s happening on Tuesday is a vote for which party controls the U.S. House of Representatives,” Elon Musk told a crowd in Green Bay. “That is why it is so significant.” https://www.nytimes.com/2025/03/30/us/elon-musk-wisconsin-supreme-court.html nyt://article/6ccfe678-4d76-5413-8a5b-ac23bc47ff09 By Theodore Schleifer Article 2025-03-30T22:21:11-04:00 2025-03-30T21:27:04-04:00 2025-03-30T21:27:04-04:00 United States Politics and Government, Conservatism (US Politics) Government Efficiency Department (US) Musk, Elon , Trump, Donald J, Schimel, Brad Wisconsin https://static01.nyt.com/images/2025/03/30/multimedia/30pol-wisconsin-musk-mqwb/30pol-wisconsin-musk-mqwb-superJumbo-v3.jpg , https://static01.nyt.com/images/2025/03/30/multimedia/30pol-wisconsin-musk-mqwb/30pol-wisconsin-musk-mqwb-threeByTwoSmallAt2X-v3.jpg, https://static01.nyt.com/images/2025/03/30/multimedia/30pol-wisconsin-musk-mqwb/30pol-wisconsin-musk-mqwb-thumbLarge-v3.jpg , Super Jumbo , threeByTwoSmallAt2X , Large Thumbnail , 1365 , 400 , 150 , 2048 , 600 , 150 , image , image , image , photo , photo , photo , Elon Musk campaigning on Sunday at a town hall in Green Bay, Wis., for a conservative judicial candidate. , Elon Musk campaigning on Sunday at a town hall in Green Bay, Wis., for a conservative judicial candidate. , Elon Musk campaigning on Sunday at a town hall in Green Bay, Wis., for a conservative judicial candidate. , Jim Vondruska for The New York Times , Jim Vondruska for The New York Times , Jim Vondruska for The New York Times
OK Copyright (c) 2025 The New York Times Company. All Rights Reserved. U.S. News 2024-06-27T14:23:45-04:00 24 us politics Fire at New Mexico Republican Party Headquarters Being Investigated as Arson Officials confirmed that the headquarters had been damaged in a fire, which the Republican Party called a “deliberate act of arson.” https://www.nytimes.com/2025/03/30/us/politics/republican-party-new-mexico-fire-arson.html nyt://article/655b1cb8-b613-59f6-ab1c-97b2b3ca791b By Livia Albeck-Ripka Article 2025-03-30T21:09:52-04:00 2025-03-30T18:04:18-04:00 2025-03-30T18:04:18-04:00 Arson , United States Politics and Government, Vandalism , Politics and Government Republican Party New Mexico , Albuquerque (NM) https://static01.nyt.com/images/2025/03/30/multimedia/30xp-firebomb-03/30xp-firebomb-03-superJumbo.jpg , https://static01.nyt.com/images/2025/03/30/multimedia/30xp-firebomb-03/30xp-firebomb-03-threeByTwoSmallAt2X.jpg , https://static01.nyt.com/images/2025/03/30/multimedia/30xp-firebomb-03/30xp-firebomb-03-thumbLarge.jpg , Super Jumbo , threeByTwoSmallAt2X , Large Thumbnail , 1342 , 400 , 150 , 2013 , 600 , 150 , image , image , image , photo , photo , photo , The headquarters of the Republican Party of New Mexico in Albuquerque was damaged early on Sunday in a fire that is being investigated as an act of arson., The headquarters of the Republican Party of New Mexico in Albuquerque was damaged early on Sunday in a fire that is being investigated as an act of arson., The headquarters of the Republican Party of New Mexico in Albuquerque was damaged early on Sunday in a fire that is being investigated as an act of arson., Republican Party of New Mexico , Republican Party of New Mexico , Republican Party of New Mexico
OK Copyright (c) 2025 The New York Times Company. All Rights Reserved. U.S. News 2024-06-27T14:23:45-04:00 24 us politics Trump’s New Concession on Tariffs Is His Most Striking The president said he “couldn’t care less” if automakers raised prices in response to planned tariffs, reasoning that buyers would choose U.S.-made cars over foreign brands. https://www.nytimes.com/2025/03/30/us/politics/trump-auto-tariffs.html nyt://article/3826423b-7078-5f7b-9d1b-dd602d53c5f0 By Talya Minsberg Article 2025-03-30T21:59:16-04:00 2025-03-30T18:01:23-04:00 2025-03-30T18:01:23-04:00 International Trade and World Market , United States Politics and Government, Customs (Tariff) , United States Economy Ford Motor Co , General Motors, Stellantis NV Fain, Shawn , Trump, Donald J United States, Canada , Mexico https://static01.nyt.com/images/2025/03/30/multimedia/30trump-news-auto-prices-vwmp/30trump-news-auto-prices-vwmp-superJumbo.jpg , https://static01.nyt.com/images/2025/03/30/multimedia/30trump-news-auto-prices-vwmp/30trump-news-auto-prices-vwmp-threeByTwoSmallAt2X.jpg, https://static01.nyt.com/images/2025/03/30/multimedia/30trump-news-auto-prices-vwmp/30trump-news-auto-prices-vwmp-thumbLarge.jpg , Super Jumbo , threeByTwoSmallAt2X , Large Thumbnail , 1365 , 400 , 150 , 2048 , 600 , 150 , image , image , image , photo , photo , photo , The Ford Assembly Plant in Wayne, Mich., in 2023. , The Ford Assembly Plant in Wayne, Mich., in 2023. , The Ford Assembly Plant in Wayne, Mich., in 2023. , Nic Antaya for The New York Times , Nic Antaya for The New York Times , Nic Antaya for The New York Times
OK Copyright (c) 2025 The New York Times Company. All Rights Reserved. U.S. News 2024-06-27T14:23:45-04:00 24 us White House Takes Highly Unusual Step of Directly Firing Line Prosecutors Two prosecutors were dismissed out of the blue, notified by a terse one-sentence email stating no reason for the move other than that it was on behalf of the president himself. https://www.nytimes.com/2025/03/30/us/line-prosecutors-fired-trump-doj.html nyt://article/43eeccad-e29e-5cc2-ab20-58ed88962c4b By Devlin Barrett and Maggie Haberman Article 2025-03-30T19:42:03-04:00 2025-03-30T16:47:23-04:00 2025-03-30T16:47:23-04:00 Presidential Power (US) , United States Politics and Government, Appointments and Executive Changes Democratic Party , Fatburger , Los Angeles Times Biden, Joseph R Jr, Leavitt, Karoline , Loomer, Laura , Schleifer, Adam , Trump, Donald J https://static01.nyt.com/images/2025/03/30/multimedia/30dc-prosecutors1-mfhb/30dc-prosecutors1-mfhb-superJumbo.jpg , https://static01.nyt.com/images/2025/03/30/multimedia/30dc-prosecutors1-mfhb/30dc-prosecutors1-mfhb-threeByTwoSmallAt2X.jpg , https://static01.nyt.com/images/2025/03/30/multimedia/30dc-prosecutors1-mfhb/30dc-prosecutors1-mfhb-thumbLarge.jpg , Super Jumbo , threeByTwoSmallAt2X , Large Thumbnail , 1366 , 400 , 150 , 2048 , 600 , 150 , image , image , image , photo , photo , photo , The Department of Justice building in Washington this month. The ousters reflected a more aggressive effort by the White House to reach deep inside U.S. attorney offices across the country. , The Department of Justice building in Washington this month. The ousters reflected a more aggressive effort by the White House to reach deep inside U.S. attorney offices across the country. , The Department of Justice building in Washington this month. The ousters reflected a more aggressive effort by the White House to reach deep inside U.S. attorney offices across the country. , Eric Lee/The New York Times , Eric Lee/The New York Times , Eric Lee/The New York Times
OK Copyright (c) 2025 The New York Times Company. All Rights Reserved. U.S. News 2024-06-27T14:23:45-04:00 24 us politics Trump-Era Pivot on Seabed Mining Draws Global Rebuke Diplomats from more than 30 nations have criticized a proposal that could allow the start of seabed mining by 2027. https://www.nytimes.com/2025/03/30/us/politics/trump-mining-metals-company.html nyt://article/add8d241-fd2d-5284-ac30-ecd7681fffeb By Eric Lipton Article 2025-03-30T15:47:17-04:00 2025-03-30T15:35:32-04:00 2025-03-30T15:35:32-04:00 United States Politics and Government, Offshore Drilling and Exploration , International Relations Metals Company, The https://static01.nyt.com/images/2022/06/23/multimedia/30dc-seabed3/30dc-seabed3-superJumbo.jpg , https://static01.nyt.com/images/2022/06/23/multimedia/30dc-seabed3/30dc-seabed3-threeByTwoSmallAt2X.jpg , https://static01.nyt.com/images/2022/06/23/multimedia/30dc-seabed3/30dc-seabed3-thumbLarge.jpg , Super Jumbo , threeByTwoSmallAt2X , Large Thumbnail , 1366 , 400 , 150 , 2048 , 600 , 150 , image , image , image , photo , photo , photo , The Maersk Launcher, a ship chartered by The Metals Company to explore the viability of mining the seabed for metals used in electric vehicle batteries, waiting in Mexican waters in 2021., The Maersk Launcher, a ship chartered by The Metals Company to explore the viability of mining the seabed for metals used in electric vehicle batteries, waiting in Mexican waters in 2021., The Maersk Launcher, a ship chartered by The Metals Company to explore the viability of mining the seabed for metals used in electric vehicle batteries, waiting in Mexican waters in 2021., Tamir Kalifa for The New York Times , Tamir Kalifa for The New York Times , Tamir Kalifa for The New York Times