API Documentation
Everything you need to integrate News API PRO into your applications
Documentation
Getting Started
Welcome to the News API PRO documentation. Our API gives you access to breaking news headlines and historical news articles from over 10,000 sources worldwide.
To start using the News API PRO:
- Register for an API key
- Read through the documentation below
- Start making API requests
Authentication
All requests to the News API PRO must include your API key. You can pass this key using the
X-API-Key
header, or as a query parameter named
apiKey
.
curl -H "X-API-Key: YOUR_API_KEY" https://newsapi.pro/api/feed_contents/us/en
curl -H "X-API-Key: YOUR_API_KEY" \
"https://newsapi.pro/api/feed_contents/us/en?categories.name=TECHNOLOGY&source.url=nytimes.com"
Security Note
Never expose your API key in client-side code. Always make API calls from your server.
Quick Start Guide
Here's a quick example to get you started with News API PRO using different programming languages:
// Fetch technology news from the US (English)
fetch('https://newsapi.pro/api/feed_contents/us/en?categories.name=TECHNOLOGY', {
headers: {
'X-API-Key': 'YOUR_API_KEY'
}
})
.then(response => response.json())
.then(data => {
// Access the news items
const items = data.items;
// Process each news item
items.forEach(item => {
console.log('Title:', item.title);
console.log('Source:', item.source.name);
console.log('Categories:', item.categories.map(c => c.name).join(', '));
console.log('Published:', new Date(item.publishedAt).toLocaleString());
console.log('---');
});
// Access pagination info
console.log(`Page ${data.currentPage} of ${data.totalPages}`);
console.log(`Showing ${data.itemsPerPage} of ${data.totalItems} total items`);
})
.catch(error => console.error('Error:', error));
import requests
from datetime import datetime, timedelta
# API configuration
base_url = 'https://newsapi.pro/api/feed_contents/us/en'
headers = {
'X-API-Key': 'YOUR_API_KEY'
}
# Request parameters
params = {
'categories.name': 'TECHNOLOGY',
'source.url': 'nytimes.com',
'publishedAt[after]': (datetime.now() - timedelta(days=1)).isoformat(),
'page': 1,
'pageSize': 30
}
# Make request for US/English news (required parameters)
response = requests.get(base_url, headers=headers, params=params)
if response.status_code == 200:
data = response.json()
# Process news items
for item in data['items']:
print(f"Title: {item['title']}")
print(f"Source: {item['source']['name']}")
print(f"Categories: {', '.join(c['name'] for c in item['categories'])}")
print(f"Published: {item['publishedAt']}")
print('---')
# Print pagination info
print(f"\nPage {data['currentPage']} of {data['totalPages']}")
print(f"Showing {data['itemsPerPage']} of {data['totalItems']} total items")
else:
print(f"Error {response.status_code}: {response.text}")
<?php
// API configuration
$apiKey = 'YOUR_API_KEY';
$baseUrl = 'https://newsapi.pro/api/feed_contents/us/en';
// Request parameters
$params = http_build_query([
'categories.name' => 'TECHNOLOGY',
'source.url' => 'nytimes.com',
'page' => 1,
'pageSize' => 30
]);
// Setup request options
$options = [
'http' => [
'method' => 'GET',
'header' => [
"X-API-Key: $apiKey",
"Accept: application/json"
]
]
];
// Create context and fetch US/English news
$context = stream_context_create($options);
$response = file_get_contents("$baseUrl?$params", false, $context);
if ($response !== false) {
$data = json_decode($response, true);
// Process news items
foreach ($data['items'] as $item) {
echo "Title: {$item['title']}\n";
echo "Source: {$item['source']['name']}\n";
echo "Categories: " . implode(', ', array_column($item['categories'], 'name')) . "\n";
echo "Published: {$item['publishedAt']}\n";
echo "---\n";
}
// Print pagination info
echo "\nPage {$data['currentPage']} of {$data['totalPages']}\n";
echo "Showing {$data['itemsPerPage']} of {$data['totalItems']} total items\n";
} else {
echo "Error fetching news: " . error_get_last()['message'] . "\n";
}
?>
API Endpoints
News API PRO provides several endpoints to access different types of news data:
Endpoint | Description | Access |
---|---|---|
/api/feed_contents/{country}/{language}
|
Get news feed contents (country and language parameters are required) | All plans |
/api/websites
|
Get list of news sources | All plans |
/api/categories
|
Get available news categories | All plans |
/api/countries
|
Get available countries with supported languages | All plans |
/api/languages
|
Get available languages with supported countries | All plans |
Feed Contents
This endpoint provides news feed contents with filtering options for categories, sources, and publication dates.
https://newsapi.pro/api/feed_contents/us/en?categories.name=TECHNOLOGY&source.url=cnn.com&publishedAt[after]=2024-03-17T00:00:00Z
Countries
Get a list of all available countries with their supported languages.
https://newsapi.pro/api/countries
Languages
Get a list of all available languages with their supported countries.
https://newsapi.pro/api/languages
Request Parameters
The API supports various parameters to filter and customize your news queries:
Parameter | Type | Description |
---|---|---|
categories.name
|
String | Filter feed contents by category name. |
source.url
|
String | Filter feed contents by source website URL (single value, partial match) |
publishedAt[after]
|
String | Filter feed contents published after this date (ISO 8601 format, e.g., 2024-03-17T00:00:00Z). |
publishedAt[before]
|
String | Filter feed contents published before this date (ISO 8601 format, e.g., 2024-03-17T23:59:59Z). |
pageSize
|
Integer | The number of results to return per page (default: 10, max: 50). |
page
|
Integer | The page number for pagination (starting from 1). |
Responses
All API responses come in standard JSON format. Here's an example of what you can expect:
{
"status": "ok",
"items": [
{
"title": "Breaking: Major Tech Announcement",
"link": "https://techcrunch.com/2024/03/17/tech-news",
"publishedAt": "2024-03-17T10:00:00Z",
"description": "A comprehensive overview of the latest technology developments...",
"source": {
"name": "TechCrunch",
"url": "https://techcrunch.com"
},
"categories": [
{
"name": "TECHNOLOGY"
},
{
"name": "BUSINESS"
}
]
},
// More articles...
],
"totalItems": 150,
"itemsPerPage": 30,
"currentPage": 1,
"totalPages": 5
}
Error Handling
The API uses standard HTTP response codes to indicate success or failure:
Code | HTTP Code | Message |
---|---|---|
200
|
200 | Success - Request completed successfully |
Authentication Errors | ||
missing_api_key |
401 | API key is required to access this resource |
invalid_api_key |
401 | Invalid API key format. API key must start with 'ak_' |
api_key_no_user |
401 | No user found for this API key |
Rate Limiting Errors | ||
rate_limit_exceeded_per_second
|
429 | Rate limit exceeded: {X} requests per second allowed |
rate_limit_exceeded_daily
|
429 | Daily rate limit exceeded: {X} requests per day allowed |
rate_limit_exceeded_monthly
|
429 | Monthly call limit exceeded: {X} requests per month allowed |
Request Validation Errors | ||
missing_parameters
|
400 | Both country and language parameters are required |
invalid_country_format
|
400 | Country must be exactly 2 letters |
invalid_language_format
|
400 | Language must be exactly 2 letters |
Pagination Errors | ||
invalid_page_number
|
400 | Page number must be a positive integer |
invalid_items_per_page
|
400 | Items per page must be between 1 and 50 |
Data Format Errors | ||
invalid_date_format
|
400 | Invalid date format. Use ISO 8601 format (e.g., 2024-03-20T19:44:00Z) |
Database Errors | ||
database_error
|
500 | An error occurred while fetching data from the database |
Routing Errors | ||
route_not_found
|
404 | The requested route was not found |
Subscription Errors | ||
no_active_subscription
|
403 | No active subscription found for this API key |
{
"code": "invalid_api_key",
"message": "The provided API key is invalid"
}
Response Examples
Here are examples of responses from different endpoints:
Countries Response
[
{
"code": "US",
"name": "United States",
"languages": [
{
"code": "en",
"name": "English"
}
]
},
{
"code": "FR",
"name": "France",
"languages": [
{
"code": "fr",
"name": "French"
}
]
}
// More countries...
]
Languages Response
[
{
"code": "en",
"name": "English",
"countries": [
{
"code": "US",
"name": "United States"
},
{
"code": "GB",
"name": "United Kingdom"
}
]
},
{
"code": "fr",
"name": "French",
"countries": [
{
"code": "FR",
"name": "France"
}
]
}
// More languages...
]
Rate Limits
The API applies rate limits based on your subscription plan:
Plan | Requests per Day | Requests per Month | Monthly Cost | Requests per Second |
---|---|---|---|---|
Basic | 1,000 | 100 | Free | 1000 |
Pro | 1,000 | 10,000 | $5.99 | 1 |
Ultra Most Popular | 2,000 | 200,000 | $29 | 5 |
Mega | 5,000 | 500,000 | $59 | 10 |
Rate Limit Headers
The API includes rate limit information in response headers:
X-RateLimit-Limit
,
X-RateLimit-Remaining
, and
X-RateLimit-Reset
.
Ready to Start Building?
Get your API key today and integrate News API PRO into your application.