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.

Information about httr2: https://httr2.r-lib.org/

Possibly needed Libraries

library(httr)
library(httr2)
library(jsonlite)
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

Connect to API (Most Popular articles on NYTimes based on emails, shares, or views: https://developer.nytimes.com/docs/most-popular-product/1/overview) I have chosen to pull the most viewed articles for the last 7 days (/viewed/7.json)

api_key <- "8x82aaOG0aTGBMpIAN86jUui5e4Z3G8J" #personal Key from https://developer.nytimes.com/my-apps
api_url <- "https://api.nytimes.com/svc/mostpopular/v2/emailed/7.json?api-key="

api_path <- paste(api_url, api_key, sep = "")
# https://api.nytimes.com/svc/mostpopular/v2/emailed/7.json?api-key=8x82aaOG0aTGBMpIAN86jUui5e4Z3G8J

Put into dataframe

myframe <- as.data.frame(fromJSON(api_path))
head(myframe)
##   status                                                            copyright
## 1     OK Copyright (c) 2023 The New York Times Company.  All Rights Reserved.
## 2     OK Copyright (c) 2023 The New York Times Company.  All Rights Reserved.
## 3     OK Copyright (c) 2023 The New York Times Company.  All Rights Reserved.
## 4     OK Copyright (c) 2023 The New York Times Company.  All Rights Reserved.
## 5     OK Copyright (c) 2023 The New York Times Company.  All Rights Reserved.
## 6     OK Copyright (c) 2023 The New York Times Company.  All Rights Reserved.
##   num_results                                            results.uri
## 1          20     nyt://article/e3aead55-1e20-583a-89f0-28dee687be51
## 2          20     nyt://article/7ede225f-e7b9-5e00-91a7-0e8a8bbbe639
## 3          20     nyt://article/dc5d3a61-bcbf-5e0d-bfb3-c69c167ec878
## 4          20 nyt://interactive/2e69f0c9-7fde-5bb2-87b8-0fe84269f1c9
## 5          20     nyt://article/f0871efd-1743-5826-a840-b0056b963707
## 6          20     nyt://article/d3054f89-2727-5254-a63b-7f4d7e0ff51f
##                                                                              results.url
## 1                    https://www.nytimes.com/2023/10/24/us/witches-paddle-halloween.html
## 2               https://www.nytimes.com/2023/10/19/opinion/social-skills-connection.html
## 3                     https://www.nytimes.com/article/best-restaurants-philadelphia.html
## 4   https://www.nytimes.com/interactive/2023/10/22/magazine/hadley-vlahos-interview.html
## 5 https://www.nytimes.com/2023/10/23/opinion/alzheimers-dementia-advance-directives.html
## 6             https://www.nytimes.com/2023/10/26/well/move/skiing-injuries-workouts.html
##   results.id results.asset_id results.source results.published_date
## 1      1e+14            1e+14 New York Times             2023-10-24
## 2      1e+14            1e+14 New York Times             2023-10-19
## 3      1e+14            1e+14 New York Times             2023-10-23
## 4      1e+14            1e+14 New York Times             2023-10-22
## 5      1e+14            1e+14 New York Times             2023-10-23
## 6      1e+14            1e+14 New York Times             2023-10-26
##       results.updated results.section results.subsection results.nytdsection
## 1 2023-10-24 08:57:53            U.S.                                   u.s.
## 2 2023-10-21 12:07:47         Opinion                                opinion
## 3 2023-10-24 22:36:03            Food                                   food
## 4 2023-10-27 14:47:25        Magazine                               magazine
## 5 2023-10-28 01:23:26         Opinion                                opinion
## 6 2023-10-27 15:37:31            Well               Move                well
##                                                                                                                         results.adx_keywords
## 1                                                                                                          Halloween;Paddleboarding;Costumes
## 2                                                       Conversation;Empathy;Psychology and Psychologists;Books and Literature;Brooks, David
## 3                                                                                                        Restaurants;Chefs;Philadelphia (Pa)
## 4 Hospice Care;Social Media;Death and Dying;Elder Care;Nursing and Nurses;Books and Literature;Content Type: Personal Profile;Vlahos, Hadley
## 5                                                          Dementia;Alzheimer's Disease;Death and Dying;Living Wills and Health Care Proxies
## 6                                          Snowboarding;Content Type: Service;Skiing;Sports Injuries;Alpine Skiing;Exercise;Physical Therapy
##   results.column
## 1             NA
## 2             NA
## 3             NA
## 4             NA
## 5             NA
## 6             NA
##                                                                           results.byline
## 1                                                                          By Remy Tumin
## 2                                                                        By David Brooks
## 3 By Regan Stephens, Nikita Richardson, Brett Anderson, Priya Krishna and Sara Bonisteel
## 4                                                                      By David Marchese
## 5                                                                      By Sandeep Jauhar
## 6                                                                        By Jenny Marder
##   results.type
## 1      Article
## 2      Article
## 3      Article
## 4  Interactive
## 5      Article
## 6      Article
##                                                           results.title
## 1                                     Something Wicked This Way Paddles
## 2                                  The Essential Skills for Being Human
## 3                     The 25 Best Restaurants in Philadelphia Right Now
## 4                       A Hospice Nurse on Embracing the Grace of Dying
## 5 My Father Didn’t Want to Live if He Had Dementia. But Then He Had It.
## 6                 For a Ski Season Without Injury, Start Training Early
##                                                                                                                                                           results.abstract
## 1                         Every October, hundreds of revelers in witch costumes float on lakes and bays, ponds and harbors. Instead of brooms, they opt for paddle boards.
## 2                                                                                          Human beings long to have another person look at them with love and acceptance.
## 3 The dining scene here is having a moment, whether it’s outstanding pizza, fiery Ethiopian fried chicken or French inflected cuisine that feels like a cozy dinner party.
## 4                                                                Hadley Vlahos​, TikTok star and best-selling author​, wants us to let go of our fighting words​ about death.
## 5                                                                                             It is hard to know in advance what kind of existence you’ll be content with.
## 6           Hitting the slopes is an inherently risky endeavor. To protect your knees, shoulders and wrists this winter, here’s a 20-minute strength workout to start now.
##                                                                                                                   results.des_facet
## 1                                                                                               Halloween, Paddleboarding, Costumes
## 2                                                         Conversation, Empathy, Psychology and Psychologists, Books and Literature
## 3                                                                                                                Restaurants, Chefs
## 4 Hospice Care, Social Media, Death and Dying, Elder Care, Nursing and Nurses, Books and Literature, Content Type: Personal Profile
## 5                                              Dementia, Alzheimer's Disease, Death and Dying, Living Wills and Health Care Proxies
## 6                           Snowboarding, Content Type: Service, Skiing, Sports Injuries, Alpine Skiing, Exercise, Physical Therapy
##   results.org_facet results.per_facet results.geo_facet
## 1                                                      
## 2                       Brooks, David                  
## 3                                     Philadelphia (Pa)
## 4                      Vlahos, Hadley                  
## 5                                                      
## 6                                                      
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     results.media
## 1                                                         image, photo, Chatfield State Park in Colorado is one of dozens of places where witches take flight each fall — at least, on their paddle boards., Eli Imadali for The New York Times, 1, https://static01.nyt.com/images/2023/10/17/multimedia/00xp-witches-01-cwkm/00xp-witches-01-cwkm-thumbStandard.jpg, https://static01.nyt.com/images/2023/10/17/multimedia/00xp-witches-01-cwkm/00xp-witches-01-cwkm-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2023/10/17/multimedia/00xp-witches-01-cwkm/00xp-witches-01-cwkm-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 2                                                                                                                                                                                                                                                                                           image, photo, , Liana Finck, 1, https://static01.nyt.com/images/2023/10/20/opinion/20Brooks/20Brooks-thumbStandard-v5.jpg, https://static01.nyt.com/images/2023/10/20/opinion/20Brooks/20Brooks-mediumThreeByTwo210-v5.jpg, https://static01.nyt.com/images/2023/10/20/opinion/20Brooks/20Brooks-mediumThreeByTwo440-v5.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 3 image, photo, Marc Vetri opened the snug restaurant Fiorella in a former sausage shop in the Italian Market neighborhood., Steve Legato, 0, https://static01.nyt.com/images/2023/10/25/multimedia/25best-restaurants-philly-cover3-gmfj/23best-restaurants-philly-cover3-gmfj-thumbStandard.jpg, https://static01.nyt.com/images/2023/10/25/multimedia/25best-restaurants-philly-cover3-gmfj/23best-restaurants-philly-cover3-gmfj-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2023/10/25/multimedia/25best-restaurants-philly-cover3-gmfj/23best-restaurants-philly-cover3-gmfj-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 4                                                                                                                                                                                                                                               image, , , Mamadi Doumbouya for The New York Times, 1, https://static01.nyt.com/images/2023/10/29/magazine/29mag-talk-copy/29mag-talk-thumbStandard.jpg, https://static01.nyt.com/images/2023/10/29/magazine/29mag-talk-copy/29mag-talk-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2023/10/29/magazine/29mag-talk-copy/29mag-talk-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 5                                                                                                                                                                                                                                                                       image, photo, , Jalal Shamsazaran/NVP Images, 1, https://static01.nyt.com/images/2023/10/28/opinion/20jauhar-1/20jauhar-1-thumbStandard.jpg, https://static01.nyt.com/images/2023/10/28/opinion/20jauhar-1/20jauhar-1-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2023/10/28/opinion/20jauhar-1/20jauhar-1-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 6                                                                                                                                                                image, photo, , Gritchelle Fallesgon, 1, https://static01.nyt.com/images/2023/10/26/multimedia/26SKI-SEASON-TRAINING5-qfhb/26SKI-SEASON-TRAINING5-qfhb-thumbStandard.jpg, https://static01.nyt.com/images/2023/10/26/multimedia/26SKI-SEASON-TRAINING5-qfhb/26SKI-SEASON-TRAINING5-qfhb-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2023/10/26/multimedia/26SKI-SEASON-TRAINING5-qfhb/26SKI-SEASON-TRAINING5-qfhb-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
##   results.eta_id
## 1              0
## 2              0
## 3              0
## 4              0
## 5              0
## 6              0
colnames(myframe)
##  [1] "status"                 "copyright"              "num_results"           
##  [4] "results.uri"            "results.url"            "results.id"            
##  [7] "results.asset_id"       "results.source"         "results.published_date"
## [10] "results.updated"        "results.section"        "results.subsection"    
## [13] "results.nytdsection"    "results.adx_keywords"   "results.column"        
## [16] "results.byline"         "results.type"           "results.title"         
## [19] "results.abstract"       "results.des_facet"      "results.org_facet"     
## [22] "results.per_facet"      "results.geo_facet"      "results.media"         
## [25] "results.eta_id"