NewsAPI
newsapi.org · Media
Headlines and articles from 80,000+ news sources and blogs worldwide. Search by keyword, source, or topic. Free developer tier: 100 requests/day.
Authentication
API Key
Free API key at newsapi.org. Pass as ?apiKey= query parameter or Authorization: Bearer header.
Sample Requests
GET
Top headlines
Get top US technology headlines.
https://newsapi.org/v2/top-headlines?apiKey=YOUR_KEY&country=us&category=technology&pageSize=5
Hover any highlighted part to learn what it does
curl -X GET "https://newsapi.org/v2/top-headlines?apiKey=YOUR_KEY&country=us&category=technology&pageSize=5"
import requests
params = {
"apiKey": "YOUR_KEY",
"country": "us",
"category": "technology",
"pageSize": "5"
}
response = requests.get(
"https://newsapi.org/v2/top-headlines",
params=params,
)
print(response.json())const url = new URL('https://newsapi.org/v2/top-headlines');
url.searchParams.set('apiKey', 'YOUR_KEY');
url.searchParams.set('country', 'us');
url.searchParams.set('category', 'technology');
url.searchParams.set('pageSize', '5');
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://newsapi.org/v2/top-headlines")
q := baseURL.Query()
q.Set("apiKey", "YOUR_KEY")
q.Set("country", "us")
q.Set("category", "technology")
q.Set("pageSize", "5")
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://newsapi.org/v2/top-headlines")
uri.query = URI.encode_www_form({
"apiKey" => "YOUR_KEY",
"country" => "us",
"category" => "technology",
"pageSize" => "5"
})
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://newsapi.org/v2/top-headlines?" . http_build_query([
"apiKey" => "YOUR_KEY",
"country" => "us",
"category" => "technology",
"pageSize" => "5"
]);
$opts = ["http" => [
"method" => "GET",
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));
GET
Search news
Search all news sources for a keyword.
https://newsapi.org/v2/everything?q=artificial intelligence&apiKey=YOUR_KEY&sortBy=publishedAt&pageSize=5
Hover any highlighted part to learn what it does
curl -X GET "https://newsapi.org/v2/everything?q=artificial%20intelligence&apiKey=YOUR_KEY&sortBy=publishedAt&pageSize=5"
import requests
params = {
"q": "artificial intelligence",
"apiKey": "YOUR_KEY",
"sortBy": "publishedAt",
"pageSize": "5"
}
response = requests.get(
"https://newsapi.org/v2/everything",
params=params,
)
print(response.json())const url = new URL('https://newsapi.org/v2/everything');
url.searchParams.set('q', 'artificial intelligence');
url.searchParams.set('apiKey', 'YOUR_KEY');
url.searchParams.set('sortBy', 'publishedAt');
url.searchParams.set('pageSize', '5');
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://newsapi.org/v2/everything")
q := baseURL.Query()
q.Set("q", "artificial intelligence")
q.Set("apiKey", "YOUR_KEY")
q.Set("sortBy", "publishedAt")
q.Set("pageSize", "5")
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://newsapi.org/v2/everything")
uri.query = URI.encode_www_form({
"q" => "artificial intelligence",
"apiKey" => "YOUR_KEY",
"sortBy" => "publishedAt",
"pageSize" => "5"
})
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://newsapi.org/v2/everything?" . http_build_query([
"q" => "artificial intelligence",
"apiKey" => "YOUR_KEY",
"sortBy" => "publishedAt",
"pageSize" => "5"
]);
$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
- Get a free API key at newsapi.org
- Pass apiKey=YOUR_KEY as query param
- Top headlines: GET /v2/top-headlines?country=us&category=business&apiKey=YOUR_KEY
- Everything: GET /v2/everything?q=bitcoin&sortBy=publishedAt&apiKey=YOUR_KEY
- Categories: business, entertainment, general, health, science, sports, technology