The everything Endpoint

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

q

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:

  • Enquote the keywords for an exact match ("keyword".)
  • Add the + symbol before the keyword if is a must-have in the article ("+keyword".)
  • Add the - symbol before the words that must not appear in the article ("-keyword".)
  • We can also use the AND, OR, and NOT`operators with the keywords.

searchIn

string

This is the section of the article where we want to search for the keyword. Its possible options are title, description, and content. By default, the keyword is searched for throughout the entire article.

sources

string

These are the sources we want headlines from. Multiple sources are separated using commas. We’ll get these sources using the source endpoint. A maximum of 20 sources can be used in one search.

domains

string

The domains from which the user wants the news—for example, bbc.co.uk. There can be multiple domains separated by a comma.

excludeDomains

string

The domains from which the user does not want the news—for example, bbc.co.uk. There can be multiple domains separated by a comma.

from

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 YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS. The user cannot request articles that predate the user's subscription.

to

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 YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS.

language

string

This is the code of the language that the user wants to get headlines in. The possible options are listed in the appendix.

sortBy

string

This is the order in which to sort the articles. The possible options are listed in the appendix.

pageSize

int

The number of results to return per page. It is 100 by default.

page

int

This is used to get a specific page in the results. It is 1 by default.

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.

Press + to interact
import requests
import json
URL=('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.

Press + to interact
import requests
import json
URL=('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.