Retrieve Available Sources
Learn about different news publishers available on News API and how to find them.
When writing reports on events or issues, we provide citations of the sources we use to support our thesis. For those citations to be significant, they must come from credible sources. That's why it is always important that we know our sources.
The Sources endpoint
Using the Sources endpoint, we can find details about the different sources (news publishers) provided by the News API. This endpoint returns the subset of news publishers that published the top headlines provided by the News API.
The base URL of this endpoint is https://newsapi.org/v2/top-headlines/sources
.
Request parameters
The table below contains the query parameters that we can use with the Sources endpoint:
Parameter | Type | Category | Description |
| String | Mandatory | This is the API key. |
| String | Optional | This helps us find sources that display news of a specific category. By default, the user will get sources for all categories in the result. |
| String | Optional | This is used to find sources that display news in a specific language. The possible options are listed in the appendix. |
| String | Optional | This query parameter finds sources from a specific country. The possible options are listed in the appendix. |
Using the code widget below, we'll call the Sources endpoint without any query parameters to get all the available sources. Click the "Run" button below to see the response.
// Define endpoint URL hereconst endpointUrl = new URL("https://newsapi.org/v2/top-headlines/sources");const headerParameters = {contentType: "application/json",};// Define Query Parameters hereconst queryParameters = new URLSearchParams({apiKey: '{{API_KEY}}',});// Setting API call optionsconst options = {method: "GET",headers: headerParameters,};// Function to make API callasync function getSources() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);// Printing responseprintResponse(response);} catch (error) {// Printing error messageprintError(error);}}// Calling function to make API callgetSources();
In the above code widget:
Line 2: We define the endpoint URL in the
endpointUrl
variable.Lines 9–11: We assign
apiKey
in thequeryParameters
variable because it's a mandatory parameter for the Sources endpoint.Line 23: We use the
fetch
function to make an API call.
Response fields
Some important response fields of the Sources endpoint 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 |
| Object[array] | This array contains information about the retrieved sources. |
| String | This is the ID of the news source. |
| String | This is the name of the news source. |
| String | This is the description of the news source. |
| String | This is the URL to news source's homepage. |
| String | This is the kind of news to anticipate from this source. |
| String | This the the language that this news source writes in. |
| String | This is the country where this news organization is based (and primarily writes about). |
Examples
Let’s look at a few use cases of the Sources endpoint.
Sources for sports
We can find out which sources published articles in the sports category by using the Sources endpoint in the widget provided below. Click the "Run" button to see the response.
const API_KEY = '{{API_KEY}}';const endpointUrl = new URL("https://newsapi.org/v2/top-headlines/sources");const queryParameters = new URLSearchParams({apiKey: API_KEY,category: 'sports',});const headerParameters = {contentType: "application/json",};const options = {method: 'GET',headers: headerParameters};async function fetchSources() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);printResponse(response);}catch (error) {printError(error);}}fetchSources();
In the above code widget:
Line 3: We assign the base URL of Sources endpoint to the
endpointUrl
variable.Lines 5–8: The
queryParameters
variable is given request parameters with the following constraints:The
category
query parameter is set tosports
to get sports sources.
Line 22: We use the
fetch
function to call the API endpoint.
Sources in the United States
Using the widget below, we’ll search for sources that are based in the United States. Click the "Run" button below to see the response.
const API_KEY = '{{API_KEY}}';const endpointUrl = new URL("https://newsapi.org/v2/top-headlines/sources");const queryParameters = new URLSearchParams({apiKey: API_KEY,country: 'us',});const headerParameters = {contentType: "application/json",};const options = {method: 'GET',headers: headerParameters};async function fetchSources() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);printResponse(response);}catch (error) {printError(error);}}fetchSources();
In the above code widget:
Line 3: We assign the base URL of the Sources endpoint to the
endpointUrl
variable.Lines 5–8: We set the
country
tous
in thequeryParameters
in order to find sources whose country is the United States.Line 22: We give the
endpointUrl
andoptions
as input parameters to thefetch
function to make the API call.