Migration guide v2 to v3
Step-by-step guide for migrating from News API v2 to v3
This guide provides practical instructions for migrating from News API v2 to v3, with Python code examples for each endpoint.
Prerequisites
Before starting your migration:
- Obtain your v3 API token.
- Review the API changes v2 vs v3.
- Have Python with the
requests
library installed.
Basic setup
To get started, change authentication and base URLs:
Search endpoint migration
The search endpoint enables news search with enhanced filtering capabilities in v3. Key changes include parameter renaming, updated response fields, and new filtering options.
Parameter changes
Rename date parameters
Replace from
and to
with from_
and to_
respectively:
Update topic to theme
Replace topic
with theme
and enable NLP:
Update search fields
Replace search_in
format:
Complete search example
Usage example
Response structure changes
Latest headlines migration
The latest headlines endpoint provides access to recent news articles. Migration involves similar parameter updates as the search endpoint, with additional time-based filtering options.
Parameter changes
Update topic to theme
Replace topic
with theme
and enable NLP:
Time range specification
Optionally specify time range with the when
parameter:
Complete latest headlines example
Usage example
Additional filtering options
V3 provides enhanced filtering capabilities for latest headlines:
For a complete list of /latest_headlines
parameters, see the Latest
headlines
reference documentation.
Response structure changes
Sources endpoint migration
The sources endpoint in v3 provides enhanced metadata about news sources. Key
changes include the removal of the topic
parameter and introduction of new
filtering capabilities.
Parameter changes
Remove topic parameter
The topic
parameter is removed in v3. Instead, use new filtering options:
Enable additional metadata
Use include_additional_info
to get enhanced source information:
Complete sources example
Usage example
Advanced filtering options
V3 provides additional parameters for precise source filtering:
Response structure changes
Next steps
- Test your migrated implementation.
- Review How-to documentation for v3 usage.
- Explore News API v3 endpoints for additional capabilities.
Was this page helpful?