Search Available Articles

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

apiKey

String

Mandatory

This is the API key.

q

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:

  • 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

Optional


This is to restrict the search of the keyword search to the title, description, or content of the article. By default, the keyword is searched for throughout the entire article.

sources

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.

domains

String

Optional


These are 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

Optional


These are 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

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.

to

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".

language

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.

sortBy

String

Optional

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

pageSize

Integer

Optional

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

page

Integer

Optional

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

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.

Press + to interact
// Define endpoint URL here
const endpointUrl = new URL("https://newsapi.org/v2/everything");
const headerParameters = {
contentType: "application/json",
};
// Define Query Parameters here
const queryParameters = new URLSearchParams({
apiKey: '{{API_KEY}}',
q: 'Metaverse'
});
// Setting API call options
const options = {
method: "GET",
headers: headerParameters,
};
// Function to make API call
async function searchArticles() {
try {
endpointUrl.search = queryParameters;
const response = await fetch(endpointUrl, options);
// Printing response
printResponse(response);
} catch (error) {
// Printing error message
printError(error);
}
}
// Calling function to make API call
searchArticles();

In the above code widget:

  • Line 2: We define the Everything endpoint URL in the endpointUrl variable.

  • Lines 9–12: We specify the apiKey and q in the queryParameters 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

status

String

This is the status of the request. If the request is successful, its value is ok. Otherwise, it’s error. In case of an unsuccessful request, code and message are also populated.

totalResults

Integer

This is the total number of articles available for your query. Only a limited number of articles are shown depending on the pageSize parameter. The remaining articles can be viewed by calling API with the page parameter equal to the page number.

articles

Object [array]

This array contains information about the retrieved articles.

source

Object

This object contains the name and id of the source which published the article.

author

String

This is the name of the author of the article.

title

String

This is the title of the article.

description

String

This is the description or a snippet of the article.

url

String

This is the direct URL of the article.

urlToImage

String

This is the URL to relevant image of the article.

publishedAt

String

This is the date and time, in UTC (+000) format, on which the article was published.

content

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.

Press + to interact
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.

Press + to interact
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.