Search Available Articles
Learn how to get all available articles with the News API.
When doing research on any topic, the best way to go about it is to read through different articles published in news sources and blogs on that particular topic. This broadens our understanding of the subject and allows us to acquire evidence to support our thesis and answer most questions.
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 URL for this endpoint is https://newsapi.org/v2/everything
.
Request parameters
The Everything endpoint uses the following query parameters:
Parameter | Type | Category | Description |
| String | Mandatory | This is the API key. |
| String | Mandatory | These are keywords to look for in the title, description, and body of the article. The value for this parameter can have a maximum length of 500 characters. It supports advanced search. Here’s how to use it:
|
| String | Optional | This is to restrict the search of the keyword search to the |
| String | Optional | These are the sources we want headlines from. Multiple sources are separated using commas. We’ll get these sources using the Sources endpoint. A maximum of 20 sources can be used in one search. |
| String | Optional | These are the domains from which the user wants the news—for example, |
| String | Optional | These are the domains from which the user does not want the news—for example, |
| String | Optional | 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. |
| String | Optional | 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". |
| String | Optional | This is the code of the language that the user wants to get headlines in. The possible options are listed in the appendix. |
| String | Optional | This is the order in which to sort the articles. The possible options are listed in the appendix. |
| Integer | Optional | This is the number of results to return per page. It is |
| Integer | Optional | This is used to get a specific page in the results. It is |
We’ll call the Everything endpoint to find articles about the Metaverse by using the code widget below. Click the "Run" button to see the response.
// Define endpoint URL hereconst endpointUrl = new URL("https://newsapi.org/v2/everything");const headerParameters = {contentType: "application/json",};// Define Query Parameters hereconst queryParameters = new URLSearchParams({apiKey: '{{API_KEY}}',q: 'Metaverse'});// Setting API call optionsconst options = {method: "GET",headers: headerParameters,};// Function to make API callasync function searchArticles() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);// Printing responseprintResponse(response);} catch (error) {// Printing error messageprintError(error);}}// Calling function to make API callsearchArticles();
In the above code widget:
Line 2: We define the Everything endpoint URL in the
endpointUrl
variable.Lines 9–12: We specify the
apiKey
andq
in thequeryParameters
variable.Line 16: We set the request method to
GET
.Line 24: We use the
fetch
function to make an API call.
Response fields
Some important response fields are listed in the table below:
Name | Type | Description |
| String | This is the status of the request. If the request is successful, its value is |
| Integer | This is the total number of articles available for your query. Only a limited number of articles are shown depending on the |
| Object [array] | This array contains information about the retrieved articles. |
| Object | This object contains the |
| String | This is the name of the author of the article. |
| String | This is the title of the article. |
| String | This is the description or a snippet of the article. |
| String | This is the direct URL of the article. |
| String | This is the URL to relevant image of the article. |
| String | This is the date and time, in UTC (+000) format, on which the article was published. |
| String | This contains unformatted content of the article where content is available. The content is truncated to 200 chars. |
Examples
Let’s look at a few use cases of the Everything endpoint.
Five VR headsets articles from yesterday
Let's search for articles that talk about VR Headsets with the following constraints:
We limit our search to only five articles.
We limit the search to only articles published yesterday.
We sort the articles with the newest first.
Click the "Run" button below to see the response.
const API_KEY = '{{API_KEY}}';const endpointUrl = new URL('https://newsapi.org/v2/everything');const queryParameters = new URLSearchParams({apiKey: API_KEY,q: 'VR Headsets',from: yesterday,to: yesterday,pageSize: 5,page: 1,sortBy: 'publishedAt'});const headerParameters = {contentType: "application/json",};const options = {method: 'GET',headers: headerParameters};async function fetchArticles() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);printResponse(response);}catch (error) {printError(error);}}fetchArticles();
In the above code widget:
Line 3: We assign the base URL of the Everything endpoint to the
endpointUrl
variable.Lines 5–13: The customized parameters are specified in the
queryParameters
in order to search for the desired result.Line 27: We use the
fetch
function to make the API call.
Top ten articles mentioning Web 3.0
Let's search for articles mentioning Web 3.0 with the following constraints:
We limit our search to only ten articles.
We limit the search to only articles published in the English language.
We limit the search to articles published by sources other than "bbc.co.uk."
We sort the articles depending on the popularity of the source and the relevancy of the article.
Click the "Run" button below to see the response.
const API_KEY = '{{API_KEY}}';const endpointUrl = new URL('https://newsapi.org/v2/everything');const queryParameters = new URLSearchParams({apiKey: API_KEY,q: 'Web 3.0',excludeDomains: 'bbc.co.uk',pageSize: 10,page: 1,sortBy: 'popularity,relevancy',language: 'en',});const headerParameters = {contentType: "application/json",};const options = {method: 'GET',headers: headerParameters};async function fetchArticles() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);printResponse(response);}catch (error) {printError(error);}}fetchArticles();
In the above code widget:
Line 3: We assign the URL of the Everything endpoint to the
endpointUrl
variable.Lines 5–13: The
queryParameters
variable contains the customized request parameters which are required in order to search for the desired result.Line 27: We use the
fetch
function to make the API call.