New York Times API
api.nytimes.com · Media
Article search, top stories, most popular, books bestsellers, movie reviews, and more from The New York Times. Free API key required.
Authentication
API Key
Free API key at developer.nytimes.com. Pass as ?api-key= query parameter.
Sample Requests
GET
Search articles
Search NYT articles by keyword.
https://api.nytimes.com/svc/search/v2/articlesearch.json?q=technology&sort=newest&api-key=YOUR_KEY
Hover any highlighted part to learn what it does
curl -X GET "https://api.nytimes.com/svc/search/v2/articlesearch.json?q=technology&sort=newest&api-key=YOUR_KEY"
import requests
params = {
"q": "technology",
"sort": "newest",
"api-key": "YOUR_KEY"
}
response = requests.get(
"https://api.nytimes.com/svc/search/v2/articlesearch.json",
params=params,
)
print(response.json())const url = new URL('https://api.nytimes.com/svc/search/v2/articlesearch.json');
url.searchParams.set('q', 'technology');
url.searchParams.set('sort', 'newest');
url.searchParams.set('api-key', 'YOUR_KEY');
const response = await fetch(url);
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
"net/url"
)
func main() {
baseURL, _ := url.Parse("https://api.nytimes.com/svc/search/v2/articlesearch.json")
q := baseURL.Query()
q.Set("q", "technology")
q.Set("sort", "newest")
q.Set("api-key", "YOUR_KEY")
baseURL.RawQuery = q.Encode()
targetURL := baseURL.String()
req, _ := http.NewRequest("GET", targetURL, nil)
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://api.nytimes.com/svc/search/v2/articlesearch.json")
uri.query = URI.encode_www_form({
"q" => "technology",
"sort" => "newest",
"api-key" => "YOUR_KEY"
})
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Get.new(uri)
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://api.nytimes.com/svc/search/v2/articlesearch.json?" . http_build_query([
"q" => "technology",
"sort" => "newest",
"api-key" => "YOUR_KEY"
]);
$opts = ["http" => [
"method" => "GET",
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));
GET
Top stories
Get top technology stories.
https://api.nytimes.com/svc/topstories/v2/technology.json?api-key=YOUR_KEY
Hover any highlighted part to learn what it does
curl -X GET "https://api.nytimes.com/svc/topstories/v2/technology.json?api-key=YOUR_KEY"
import requests
params = {
"api-key": "YOUR_KEY"
}
response = requests.get(
"https://api.nytimes.com/svc/topstories/v2/technology.json",
params=params,
)
print(response.json())const url = new URL('https://api.nytimes.com/svc/topstories/v2/technology.json');
url.searchParams.set('api-key', 'YOUR_KEY');
const response = await fetch(url);
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
"net/url"
)
func main() {
baseURL, _ := url.Parse("https://api.nytimes.com/svc/topstories/v2/technology.json")
q := baseURL.Query()
q.Set("api-key", "YOUR_KEY")
baseURL.RawQuery = q.Encode()
targetURL := baseURL.String()
req, _ := http.NewRequest("GET", targetURL, nil)
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://api.nytimes.com/svc/topstories/v2/technology.json")
uri.query = URI.encode_www_form({
"api-key" => "YOUR_KEY"
})
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Get.new(uri)
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://api.nytimes.com/svc/topstories/v2/technology.json?" . http_build_query([
"api-key" => "YOUR_KEY"
]);
$opts = ["http" => [
"method" => "GET",
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));Postman Setup Guide
- Register at developer.nytimes.com for a free API key
- Pass api-key=YOUR_KEY on every request
- Sections: home, arts, automobiles, books, business, fashion, food, health, insider, magazine, movies, nyregion, obituaries, opinion, politics, realestate, science, sports, sundayreview, technology, theater, t-magazine, travel, upshot, us, world