The everything Endpoint
Learn how to get all available articles to remain up-to-date.
The everything
endpoint is used to search through all available articles. This endpoint gives us access to more than 80,000 news sources. The base URI for this endpoint is https://newsapi.org/v2/everything
.
Query parameters
Parameter | Type | Description |
| string | These are keywords to look for in the title, description and body of the article. The value that can be set to this parameter can have a maximum length of 500 characters. It supports advanced search. Here’s how to use it:
|
| string | This is the section of the article where we want to search for the keyword. Its possible options are |
| string | These are the sources we want headlines from. Multiple sources are separated using commas. We’ll get these sources using the |
| string | The domains from which the user wants the news—for example, |
| string | The domains from which the user does not want the news—for example, |
| string | This refers to the date of the oldest article that the user wants in the result. The user can also mention the time. The format for the input is |
| string | This refers to the date of the newest article the user wants in the result. The user can also mention the time. The format for the input is |
| string | This is the code of the language that the user wants to get headlines in. The possible options are listed in the appendix. |
| string | This is the order in which to sort the articles. The possible options are listed in the appendix. |
| int | The number of results to return per page. It is |
| int | This is used to get a specific page in the results. It is |
We cannot call the everything
endpoint without a query parameter. It requires at least one query parameter.
Use cases
Use the everything
endpoint with a single query parameter
The code below shows us how we can use the everything
endpoint with a single query parameter. We’re using the sources
query parameter here and assigning it the id
saved in the previous lesson. Click the “Run” button to execute the code.
import requestsimport jsonURL=('https://newsapi.org/v2/everything?''sources={{sources}}')header = {'X-Api-Key': "{{API_KEY}}"}response = requests.request("GET", URL, headers=header).json()print(json.dumps(response, indent=4))
We’ll get the description
, title
, url
, author
, publishedAt
, content
, id
, and name
of the source
, and urlToImage
for each article we get using the specified source.
We can replace the query parameter in line 5 to search using other criteria.
Use the everything
endpoint with multiple query parameters
We can use multiple query parameters to narrow down the results to exactly what we want. The code below shows how we can use multiple parameters with this endpoint. Click the “Run” button to get filtered results.
import requestsimport jsonURL=('https://newsapi.org/v2/everything?''q=+Apple&''excludeDomains=wired.com')header = {'X-Api-Key': "{{API_KEY}}"}response = requests.request("GET", URL, headers=header).json()print(json.dumps(response, indent=4))
The +
symbol has also been added in line 5 with the query parameter q
. This will make sure that the results contain the searched word. We can replace +
with -
to exclude the word from the search results. We can also add more query parameters. All we have to do is separate them using &
, just like we separated q
and excludeDomains
in the code above.