> โญ Hint: See the Tutorials Section for more walk-throughs
> ๐ Contact us to spotlight your app on this page!
> ๐ Hire us to build an API for you at www.StrataConsultingLLC.com
NewsAPI is a premium data provider, delivering real time news from the highest quality sources at a lower price than other news APIs. News results and search functionality are powered by Google News. This means newsAPI provides news for 141 regions and 41 languages.
What is the difference between newsAPI and others?
newsAPI provides more data points than other news APIs. Not only do you get hundreds of high quality news headlines per request, but newsAPI also nests related news articles within each result (if available). Additionally, newsAPI provides a topic id for each result that you can use to get more in-depth coverage of a specific news story. newsAPI also provides the image url for the logo of the source publisher as well as the image URL for the article itself. This is all in addition to providing the article title, link, publisher domain, date, and a flag to indicate if the article is a video.
Include these as part of your query
parameter (see example below).
You can include any combination of these terms in your search query to filter the results.
Politics+after:2020-12-31
Politics+before:2020-12-31
intitle:Politics
allintitle:Elon+Musk+Buys+Twitter
intext:Festival
allintext:Chicago+Mayoral+Race
inurl:Tribune
or inurl:www.cnn.com
You can combine filters as well. For example, to search for articles within a specific time range published by CNN:
after:2016-12-31+before:2020-12-31+inurl:www.cnn.com
Here is a full example:
GET https://newsapi90.p.rapidapi.com/search?query=coronavirus+before:2020-12-31
Topic idโs are hashed strings generated by Google News which represent news stories or general news categories. They generally look something like this:
CAAqJggKIiBDQkFTRWdvSUwyMHZNRFZxYUdjU0FtVnVHZ0pWVXlnQVAB
Usually, article data that you request from newsAPI will include a topicId
field in the response object. You can use this id with the /topic
endpoint to find articles that are related to that news story.
Here is an example:
GET https://newsapi90.p.rapidapi.com/topic/{topicId}
You can also provide the topicId
as a query parameter instead:
GET https://newsapi90.p.rapidapi.com/topic?topicId={topicId}
Note: If you provide the topicId
in both the url path and the query parameter, the url path will take precedence. It is not necessary (or recommended) to provide it in both places.
If you do not know a specific topicId
, you can use one of the following pre-defined general categories instead. The options are:
For example:
GET https://newsapi90.p.rapidapi.com/topic/technology
Trending topics are sourced from Google Trends.
This can be accessed by calling the /trendingTopics
endpoint. It requires no parameters. The resulting list usually contains approximately 20 items.
This endpoint returns a list of currently trending topics, however it does not include the associated topicId
. Therefore, if you are going to use this data to search for news related to a trending topic, you could use newsAPIโs /search
endpoint, and provide the topic as a keyword in your query
parameter.
Here is an example:
// Get the results from the trendingTopics endpoint:
GET https://newsapi90.p.rapidapi.com/trendingTopics
// Returns ["topic_1", "topic_2", "topic_3" ...]
// Get more news for the topic you are interested in:
GET https://newsapi90.p.rapidapi.com/search?query=topic_1
newsAPI is able to provide news for 141 regions in 41 languages.
This is an optional query parameter. If left blank, it will default to U.S. English (en-US
).
The available language codes can be found at this link: Google Language Codes
Here is an example of how you would make a query for latest news in French:
GET https://newsapi90.p.rapidapi.com/topic/latest?language=fr
This is an optional query parameter. If left blank, it will default to the United States (US
).
The available region codes can be found at this link: Google Region Codes
Here is an example of how you would make a query for latest news from Brazil:
GET https://newsapi90.p.rapidapi.com/topic/latest?region=BR