Documentation
Sign up for free!
Get instant access to the API with your free API token. No billing details required!
Getting Started
Introduction
Our API was developed to provide global news from thousands of sources with exceptional response times. On average we add over 1 million articles weekly, so you will never be short of content. Even better, it is completely free!
To get started simply sign up and use your API token in any of the available API endpoints documented below for instant access.
If you have any questions or concerns, feel free to contact us.
Authentication
As mentioned above, when you sign up for free you will find your API token on your dashboard. Simply add this to any of our API endpoints as a GET parameter to gain access. Examples of how this is done can be found below.
API Endpoints
Top Stories
Endpoint
GET https://api.thenewsapi.com/v1/news/top HTTP/1.1
Use this endpoint to find live and historical top stories around the world or filter to get only top stories for specific countries. Filtering by language, category, source and publish date is also possible, as well as advanced searching on title and the main text of the article.
If you have issues with your requests, please ensure your GET parameters are URL-encoded.
All text data returned is UTF-8.
All dates are in UTC (GMT).
HTTP GET Parameters
name | required | description |
---|---|---|
api_token |
true | Your API token which can be found on your account dashboard. |
search |
false | Use the search as a basic search tool by entering regular search terms or it has more advanced usage to build search queries:+ signifies AND operation| signifies OR operation- negates a single token" wraps a number of tokens to signify a phrase for searching* at the end of a term signifies a prefix query( and ) signify precedence
To use one of these characters literally, escape it with a preceding backslash ( \ ).
Example 1: forex + (usd | gbp) -cad (searches for forex articles which include usd or gbp but excludes cad)Example 2: "Apple Inc" (searches for articles with exact matches for "Apple Inc")
For more advanced query examples, see our API Examples section. |
locale |
false | Comma separated list of country codes to include in the result set. Default is countries.
Click here for a list of supported countries.
Example: us,ca (US + Canada).
|
categories |
false | Comma separated list of categories to include.
Supported categories: general | science | sports | business | health | entertainment | tech | politics | food | travel Example: business,tech
|
exclude_categories |
false | Comma separated list of categories to exclude. |
domains |
false | Comma separated list of domains to include. List of domains can be obtained through our Sources endpoint, found further down this page.
Example: arstechnica.com,androidcentral.com |
exclude_domains |
false | Comma separated list of domains to exclude |
source_ids |
false | Comma separated list of source_ids to include. List of source_ids can be obtained through our Sources endpoint, found further down this page.
Example: arstechnica.com-1,androidcentral.com-1 |
exclude_source_ids |
false | Comma separated list of source_ids to exclude. |
language |
false | Comma separated list of languages to include. Default is all.
Click here for a list of supported languages. Examples: en,es (English + Spanish)
|
published_before |
false | Find all articles published before the specified date. Supported formats include:
Y-m-d\TH:i:s | Y-m-d\TH:i | Y-m-d\TH | Y-m-d | Y-m | Y .
Examples: 2021-04-13T01:52:00 |
2021-04-13T01:52 |
2021-04-13T01 |
2021-04-13 |
2021-04 |
2021
|
published_after |
false | Find all articles published after the specified date. Supported formats include:
Y-m-d\TH:i:s | Y-m-d\TH:i | Y-m-d\TH | Y-m-d | Y-m | Y .
Examples: 2021-04-13T01:52:00 |
2021-04-13T01:52 |
2021-04-13T01 |
2021-04-13 |
2021-04 |
2021
|
published_on |
false | Find all articles published on the specified date. Supported formats include: Y-m-d .
Examples: 2021-04-13
|
sort |
false | Sort by published_on or relevance_score (only available when used in conjunction with search ).
Default is published_at unless search is used and sorting by published_at is not included,
in which case relevance_score is used. |
limit |
false | Specify the number of articles you want to return in the request. The maximum limit is based on your plan. The default limit is the maximum specified for your plan. |
page |
false | Use this to paginate through the result set. Default is 1. Note that the max result set can't exceed 20,000. For example if your limit is 50, the max page you can have is 400 (50 * 400 = 20,000).
Example: page=2
|
Response Objects
name | description |
---|---|
meta > found |
The number of articles found for the request. |
meta > returned |
The number of articles returned on the page.
This is useful to determine the end of the result set as if this is lower than limit , there are no more articles after this page. |
meta > limit |
The limit based on the limit parameter. |
meta > page |
The page number based on the page parameter. |
data > uuid |
The unique identifier for an article in our system. Store this and use it to find specific articles using our single article endpoint. |
data > title |
The article title. |
data > description |
The article meta description. |
data > keywords |
The article meta keywords. |
data > snippet |
The first 60 characters of the article body. |
data > url |
The URL to the article. |
data > image_url |
The URL to the article image. |
data > language |
The language of the source. |
data > published_at |
The datetime the article was published. |
data > source |
The domain of the source. |
data > categories |
Array of strings which the source is categorized as. |
data > relevance_score |
Relevance score based on the search parameter. If the search parameter is not used, this will be null . |
data > locale |
Locale of the source. |
If no results are found, the data object will be empty.
Example Request
GET https://api.thenewsapi.com/v1/news/top?api_token=YOUR_API_TOKEN&locale=us&limit=3
Example Response
{
"meta": {
"found": 209611,
"returned": 3,
"limit": 3,
"page": 1
},
"data": [
{
"uuid": "24194e2e-3750-4dee-8705-47b56d4bad46",
"title": "Ex-Boston police officer and union chief stayed on force despite abuse allegation : news",
"description": "23.0m members in the news community. The place for news articles about current events in the United States and the rest of the world. Discuss it all …",
"keywords": "",
"snippet": "The place for news articles about current events in the United States and the rest of the world. Discuss it all here.",
"url": "https://www.reddit.com/r/news/comments/mplash/exboston_police_officer_and_union_chief_stayed_on/",
"image_url": "https://external-preview.redd.it/5b2NqOugAocL-3IhO2lu4zLh_PnBSOS22M6jSEjXRTc.jpg?auto=webp&s=cb3df3e231c84641a26b23007ad2dda66273bb72",
"language": "en",
"published_at": "2021-04-13T01:15:33.000000Z",
"source": "reddit.com",
"categories": [
"general",
"politics"
],
"relevance_score": null,
"locale": "us"
},
{
"uuid": "0e4a4b61-ed48-4742-868f-770bee693d97",
"title": "NCAA backs transgender athletes, says events to be in places 'free of discrimination' : news",
"description": "226 votes, 223 comments. 23.0m members in the news community. The place for news articles about current events in the United States and the rest of …",
"keywords": "",
"snippet": "The place for news articles about current events in the United States and the rest of the world. Discuss it all here.",
"url": "https://www.reddit.com/r/news/comments/mpotmz/ncaa_backs_transgender_athletes_says_events_to_be/",
"image_url": "https://external-preview.redd.it/MVvdg5duL2LW9SgSecLYGbFhPmZeeC0ZoQmajHmr7SY.jpg?auto=webp&s=c60558fef8350a7980571e1e6608ac2b026fdcfc",
"language": "en",
"published_at": "2021-04-13T01:15:33.000000Z",
"source": "reddit.com",
"categories": [
"general",
"politics"
],
"relevance_score": null,
"locale": "us"
},
{
"uuid": "fda029f9-83c8-4347-b7e6-b5530062dfb1",
"title": "Julian Edelman’s Top 10 moments with the Patriots",
"description": "Julian Edelman provided Patriots' fans with a top of great memories. Here's the best of the best.",
"keywords": "",
"snippet": "10. His opening act: On a hot August night in 2009, with the world watching Tom Brady in his first preseason game back after his 2008 knee injury, it was the ro...",
"url": "https://www.bostonglobe.com/2021/04/13/sports/julian-edelmans-top-10-moments-with-patriots/?camp=bg:brief:rss:feedly&rss_id=feedly_rss_brief",
"image_url": "https://bostonglobe-prod.cdn.arcpublishing.com/resizer/GzX8W0KH_QAcPY670CzukNgjQPk=/506x0/cloudfront-us-east-1.images.arcpublishing.com/bostonglobe/DGVIJHHMFAI6NF6MHKSHSGMQII.jpg",
"language": "en",
"published_at": "2021-04-13T01:04:21.000000Z",
"source": "bostonglobe.com",
"categories": [
"general"
],
"relevance_score": null,
"locale": "us"
}
]
}
All News
Endpoint
GET https://api.thenewsapi.com/v1/news/all HTTP/1.1
Use this endpoint to find all live and historical articles we collect. Filtering by language, category, source and publish date is also possible, as well as advanced searching on title and the main text of the article.
If you have issues with your requests, please ensure your GET parameters are URL-encoded.
All text data returned is UTF-8.
All dates are in UTC (GMT).
HTTP GET Parameters
name | required | description |
---|---|---|
api_token |
true | Your API token which can be found on your account dashboard. |
search |
false | Use the search as a basic search tool by entering regular search terms or it has more advanced usage to build search queries:+ signifies AND operation| signifies OR operation- negates a single token" wraps a number of tokens to signify a phrase for searching* at the end of a term signifies a prefix query( and ) signify precedence
To use one of these characters literally, escape it with a preceding backslash ( \ ).
Example 1: forex + (usd | gbp) -cad (searches for forex articles which include usd or gbp but excludes cad)Example 2: "Apple Inc" (searches for articles with exact matches for "Apple Inc")
For more advanced query examples, see our API Examples section. |
categories |
false | Comma separated list of categories to include.
Supported categories: general | science | sports | business | health | entertainment | tech | politics | food | travel Example: business,tech
|
exclude_categories |
false | Comma separated list of categories to exclude. |
domains |
false | Comma separated list of domains to include. List of domains can be obtained through our Sources endpoint, found further down this page.
Example: arstechnica.com,androidcentral.com |
exclude_domains |
false | Comma separated list of domains to exclude |
source_ids |
false | Comma separated list of source_ids to include. List of source_ids can be obtained through our Sources endpoint, found further down this page.
Example: arstechnica.com-1,androidcentral.com-1 |
exclude_source_ids |
false | Comma separated list of source_ids to exclude. |
language |
false | Comma separated list of languages to include. Default is all.
Click here for a list of supported languages. Examples: en,es (English + Spanish)
|
published_before |
false | Find all articles published before the specified date. Supported formats include:
Y-m-d\TH:i:s | Y-m-d\TH:i | Y-m-d\TH | Y-m-d | Y-m | Y .
Examples: 2021-04-13T01:52:00 |
2021-04-13T01:52 |
2021-04-13T01 |
2021-04-13 |
2021-04 |
2021
|
published_after |
false | Find all articles published after the specified date. Supported formats include:
Y-m-d\TH:i:s | Y-m-d\TH:i | Y-m-d\TH | Y-m-d | Y-m | Y .
Examples: 2021-04-13T01:52:00 |
2021-04-13T01:52 |
2021-04-13T01 |
2021-04-13 |
2021-04 |
2021
|
published_on |
false | Find all articles published on the specified date. Supported formats include: Y-m-d .
Examples: 2021-04-13
|
sort |
false | Sort by published_on or relevance_score (only available when used in conjunction with search ).
Default is published_at unless search is used and sorting by published_at is not included,
in which case relevance_score is used. |
limit |
false | Specify the number of articles you want to return in the request. The maximum limit is based on your plan. The default limit is the maximum specified for your plan. |
page |
false | Use this to paginate through the result set. Default is 1. Note that the max result set can't exceed 20,000. For example if your limit is 50, the max page you can have is 400 (50 * 400 = 20,000).
Example: page=2
|
Response Objects
name | description |
---|---|
meta > found |
The number of articles found for the request. |
meta > returned |
The number of articles returned on the page.
This is useful to determine the end of the result set as if this is lower than limit , there are no more articles after this page. |
meta > limit |
The limit based on the limit parameter. |
meta > page |
The page number based on the page parameter. |
data > uuid |
The unique identifier for an article in our system. Store this and use it to find specific articles using our single article endpoint. |
data > title |
The article title. |
data > description |
The article meta description. |
data > keywords |
The article meta keywords. |
data > snippet |
The first 60 characters of the article body. |
data > url |
The URL to the article. |
data > image_url |
The URL to the article image. |
data > language |
The language of the source. |
data > published_at |
The datetime the article was published. |
data > source |
The domain of the source. |
data > categories |
Array of strings which the source is categorized as. |
data > relevance_score |
Relevance score based on the search parameter. If the search parameter is not used, this will be null . |
If no results are found, the data object will be empty.
Example Request
GET https://api.thenewsapi.com/v1/news/all?api_token=YOUR_API_TOKEN&language=en&limit=3
Example Response
{
"meta": {
"found": 6679468,
"returned": 3,
"limit": 3,
"page": 1
},
"data": [
{
"uuid": "3bb56103-d774-45ab-8e6e-d915dd1d3f54",
"title": "Stephon Gilmore Wants to Stay with Patriots, Says Future Is 'Out of My Control'",
"description": "New England Patriots star Stephon Gilmore confirmed he \"for sure\" would like remain with the team for the 2021 NFL season but acknowledged the difficulty i...",
"keywords": "",
"snippet": "Winslow Townson/Associated Press\n\nNew England Patriots star Stephon Gilmore confirmed he \"for sure\" would like remain with the team for the 2021 NFL season but ...",
"url": "https://bleacherreport.com/articles/2939869-stephon-gilmore-wants-to-stay-with-patriots-says-future-is-out-of-my-control",
"image_url": "https://img.bleacherreport.net/img/images/photos/003/910/000/hi-res-34e26f34dacb18f8ff0e3d5da87c05d9_crop_exact.jpg?w=1200&h=1200&q=75",
"language": "en",
"published_at": "2021-04-13T01:51:56.000000Z",
"source": "bleacherreport.com",
"categories": [
"sports"
],
"relevance_score": null
},
{
"uuid": "eaff3ebb-063d-4080-9332-dcc893b76d37",
"title": "Second Australian case of blood clots likely linked to AZ shot",
"description": "The national medical regulator has concluded a recently reported case of blood clots is likely linked to the AstraZeneca COVID-19 vaccine.",
"keywords": "",
"snippet": "The national medical regulator has concluded a recently reported case of blood clots is likely linked to the AstraZeneca COVID-19 vaccine.\n\nIt is the second Aus...",
"url": "https://thenewdaily.com.au/news/coronavirus/2021/04/13/blood-clot-australia-covid/",
"image_url": "https://1v1d1e1lmiki1lgcvx32p49h8fe-wpengine.netdna-ssl.com/wp-content/uploads/2020/04/GettyImages-1213304774-960x600.jpg",
"language": "en",
"published_at": "2021-04-13T01:44:32.000000Z",
"source": "thenewdaily.com.au",
"categories": [
"general"
],
"relevance_score": null
},
{
"uuid": "a1aa1698-e042-4bcd-aee0-ccaf5626cdf2",
"title": "蓝蓝的拼音 LanLanDe PinYin",
"description": "Mac Apps, Mac App Store, iPad, iPhone and iPod touch app store listings, news, and price drops",
"keywords": "Mac Apps, Mac App Store, iPad, iPhone, iPod, touch, iPod touch, app store, apps, itunes, deals, sales, price drops, rss, feeds",
"snippet": "",
"url": "https://appshopper.com:443/education/%E8%93%9D%E8%93%9D%E7%9A%84%E6%8B%BC%E9%9F%B3-lanlande-pinyin",
"image_url": "https://appshopper.com:443/as-style/img/favicons/Icon-29.png",
"language": "en",
"published_at": "2021-04-13T01:44:16.000000Z",
"source": "appshopper.com",
"categories": [
"tech"
],
"relevance_score": null
}
]
}
Similar News
Endpoint
GET https://api.thenewsapi.com/v1/news/similar/uuid HTTP/1.1
Use this endpoint to find similar stories to a specific article based on its UUID.
If you have issues with your requests, please ensure your GET parameters are URL-encoded.
All text data returned is UTF-8.
All dates are in UTC (GMT).
HTTP GET Parameters
name | required | description |
---|---|---|
api_token |
true | Your API token which can be found on your account dashboard. |
categories |
false | Comma separated list of categories to include.
Supported categories: general | science | sports | business | health | entertainment | tech | politics | food | travel Example: business,tech
|
exclude_categories |
false | Comma separated list of categories to exclude. |
domains |
false | Comma separated list of domains to include. List of domains can be obtained through our Sources endpoint, found further down this page.
Example: arstechnica.com,androidcentral.com |
exclude_domains |
false | Comma separated list of domains to exclude |
source_ids |
false | Comma separated list of source_ids to include. List of source_ids can be obtained through our Sources endpoint, found further down this page.
Example: arstechnica.com-1,androidcentral.com-1 |
exclude_source_ids |
false | Comma separated list of source_ids to exclude. |
language |
false | Comma separated list of languages to include. Default is all.
Click here for a list of supported languages. Examples: en,es (English + Spanish)
|
published_before |
false | Find all articles published before the specified date. Supported formats include:
Y-m-d\TH:i:s | Y-m-d\TH:i | Y-m-d\TH | Y-m-d | Y-m | Y .
Examples: 2021-04-13T01:52:00 |
2021-04-13T01:52 |
2021-04-13T01 |
2021-04-13 |
2021-04 |
2021
|
published_after |
false | Find all articles published after the specified date. Supported formats include:
Y-m-d\TH:i:s | Y-m-d\TH:i | Y-m-d\TH | Y-m-d | Y-m | Y .
Examples: 2021-04-13T01:52:00 |
2021-04-13T01:52 |
2021-04-13T01 |
2021-04-13 |
2021-04 |
2021
|
published_on |
false | Find all articles published on the specified date. Supported formats include: Y-m-d .
Examples: 2021-04-13
|
limit |
false | Specify the number of articles you want to return in the request. The maximum limit is based on your plan. The default limit is the maximum specified for your plan. |
page |
false | Use this to paginate through the result set. Default is 1. Note that the max result set can't exceed 20,000. For example if your limit is 50, the max page you can have is 400 (50 * 400 = 20,000).
Example: page=2
|
Response Objects
name | description |
---|---|
meta > found |
The number of articles found for the request. |
meta > returned |
The number of articles returned on the page.
This is useful to determine the end of the result set as if this is lower than limit , there are no more articles after this page. |
meta > limit |
The limit based on the limit parameter. |
meta > page |
The page number based on the page parameter. |
data > uuid |
The unique identifier for an article in our system. Store this and use it to find specific articles using our single article endpoint. |
data > title |
The article title. |
data > description |
The article meta description. |
data > keywords |
The article meta keywords. |
data > snippet |
The first 60 characters of the article body. |
data > url |
The URL to the article. |
data > image_url |
The URL to the article image. |
data > language |
The language of the source. |
data > published_at |
The datetime the article was published. |
data > source |
The domain of the source. |
data > categories |
Array of strings which the source is categorized as. |
data > relevance_score |
Relevance score based on the article provided. |
If no results are found, the data object will be empty.
Example Request
GET https://api.thenewsapi.com/v1/news/similar/cc11e3ab-ced0-4a42-9146-e426505e2e67?api_token=YOUR_API_TOKEN&language=en&published_on=2020-12-01
Example Response
{
"meta": {
"found": 3571,
"returned": 3,
"limit": 3,
"page": 1
},
"data": [
{
"uuid": "df4ad427-a672-4c67-b6c6-6f81aa00e164",
"title": "Tesla stock jumps after announcement it will join S&P 500 in one go",
"description": "Tesla's stock price surged early Tuesday after the company b...",
"keywords": "Business, s&p 500, stocks, tesla",
"snippet": "Tesla’s stock price surged early Tuesday after the company...",
"url": "https://nypost.com/2020/12/01/tesla-stock-jumps-on-news-it-will-join-sp-500-in-one-shot/",
"image_url": "https://nypost.com/wp-content/uploads/sites/2/2020/12/tesla-52.jpg?quality=90&strip=all&w=1200",
"language": "en",
"published_at": "2020-12-01T14:35:46.000000Z",
"source": "nypost.com",
"categories": [
"business"
],
"relevance_score": 153.61266
},
{
"uuid": "c9a23881-12dd-4005-8982-7b6552a2eb50",
"title": "Tesla To Join S&P 500 With Full Market Cap On December 21",
"description": "Tesla will be added to the S&P 500 index all at once at its ...",
"keywords": "Tesla, S&P500, EV, Automotive, Stocks, Investing",
"snippet": "Tesla (NASDAQ: TSLA) will be added to the S&P 500 index all ...",
"url": "https://oilprice.com/Latest-Energy-News/World-News/Tesla-To-Join-SP-500-With-Full-Market-Cap-On-December-21.html",
"image_url": "https://d32r1sh890xpii.cloudfront.net/news/718x300/2020-12-01_xwjdajwctl.jpg",
"language": "en",
"published_at": "2020-12-01T16:30:00.000000Z",
"source": "oilprice.com",
"categories": [
"general",
"business"
],
"relevance_score": 146.92773
},
{
"uuid": "18afdb1c-7742-4016-bf8c-a2f114e11199",
"title": "Tesla to Enter S&P 500 at Full Weight in December",
"description": "The electric-vehicle maker will be added to the broad stock-...",
"keywords": "Motor Vehicles, Alternative Fuel Vehicles, Trusts Funds Financial Vehicles, Diversified Holding Companies, Automotive",
"snippet": "S&P Dow Jones Indices said it will add Tesla Inc.’s full w...",
"url": "https://www.wsj.com/articles/tesla-to-enter-s-p-500-at-full-weight-in-december-11606780897?mod=pls_whats_news_us_business_f",
"image_url": "https://images.wsj.net/im-265933/social",
"language": "en",
"published_at": "2020-12-01T00:01:00.000000Z",
"source": "online.wsj.com",
"categories": [
"business"
],
"relevance_score": 128.22346
}
]
}
News by UUID
Endpoint
GET https://api.thenewsapi.com/v1/news/uuid/uuid HTTP/1.1
Use this endpoint to find specific articles by the UUID which is returned on our search endpoints. This is useful if you wish to store the UUID to return the article later.
If you have issues with your requests, please ensure your GET parameters are URL-encoded.
All text data returned is UTF-8.
All dates are in UTC (GMT).
HTTP GET Parameters
name | required | description |
---|---|---|
api_token |
true | Your API token which can be found on your account dashboard. |
Response Objects
name | description |
---|---|
uuid |
The unique identifier for an article in our system. Store this and use it to find specific articles using our single article endpoint. |
title |
The article title. |
description |
The article meta description. |
keywords |
The article meta keywords. |
snippet |
The first 60 characters of the article body. |
url |
The URL to the article. |
image_url |
The URL to the article image. |
language |
The language of the source. |
published_at |
The datetime the article was published. |
source |
The domain of the source. |
categories |
Array of strings which the source is categorized as. |
If no results are found, a resource_not_found
error will be returned.
Example Request
GET https://api.thenewsapi.com/v1/news/uuid/147013d8-6c2c-4d50-8bad-eb3c8b7f5740?api_token=YOUR_API_TOKEN
Example Response
{
"uuid": "147013d8-6c2c-4d50-8bad-eb3c8b7f5740",
"title": "These Are The Four American Companies Worth Over $1 Trillion Each – 24",
"description": "America’s major market indexes set records in the early pa...",
"keywords": "",
"snippet": "These Are The Four American Companies Worth Over $1 Trillion...",
"url": "https://247wallst.com/investing/2020/10/17/these-are-the-four-american-companies-worth-over-1-trillion-each/",
"image_url": "https://247wallst.com/wp-content/uploads/2020/08/imageForEntry2-Qrj.jpg",
"language": "en",
"published_at": "2020-10-17T11:16:20.000000Z",
"source": "247wallst.com",
"categories": [
"business"
]
}
Sources
Endpoint
GET https://api.thenewsapi.com/v1/news/sources HTTP/1.1
Use this endpoint to sources to use in your news API requests. Note that the limit is 50 for all requests.
If you have issues with your requests, please ensure your GET parameters are URL-encoded.
All text data returned is UTF-8.
HTTP GET Parameters
name | required | description |
---|---|---|
categories |
false | Comma separated list of categories to include
Example: business,tech
|
exclude_categories |
false | Comma separated list of categories to exclude |
language |
false | Comma separated list of languages to include. Default is all.
Click here for a list of supported languages. Examples: en,es (English + Spanish)
|
page |
false | Use this to paginate through the result set. Default is 1.
Example: page=2
|
Response Objects
name | description |
---|---|
meta > found |
The number of sources found for the request. |
meta > returned |
The number of sources returned on the page. |
meta > limit |
The limit is 50. This currently can not be changed. |
meta > page |
The page number based on the page parameter. |
data > source_id |
The unique ID of the source feed. Use this for the source_ids or exclude_source_ids parameters in the news endpoints.
There may be many source_ids for each domain, therefore we would generally suggest using the domains filter instead the source_ids filter. |
data > domain |
The domain of the source. You can use this for the domains or exclude_domains parameters in the news endpoints. |
data > language |
The source language. |
data > locale |
The source locale. Note that only select sources have locales. |
data > categories |
Array of strings which the source is categorized as. |
If no results are found, the data object will be empty.
Example Request
GET https://api.thenewsapi.com/v1/news/sources?api_token=YOUR_API_TOKEN&language=en
Example Response
{
"meta": {
"found": 15453,
"returned": 50,
"limit": 50,
"page": 1
},
"data": [
{
"source_id": "arstechnica.com-1",
"domain": "arstechnica.com",
"language": "en",
"locale": null,
"categories": [
"tech"
]
},
{
"source_id": "androidcentral.com-1",
"domain": "androidcentral.com",
"language": "en",
"locale": null,
"categories": [
"tech"
]
},
{
"source_id": "adweek.com-1",
"domain": "adweek.com",
"language": "en",
"locale": null,
"categories": [
"business"
]
},
...
Errors
Errors
If your request was unsuccessful, you will receive a JSON formatted error. Below you will find the potential errors you may encounter when using the API.
Errors
error code | HTTP status | description |
---|---|---|
malformed_parameters |
400 |
Validation of parameters failed. The failed parameters are usually shown in the error message. |
invalid_api_token |
401 |
Invalid API token. |
usage_limit_reached |
402 |
Usage limit of your plan has been reached. Usage limit and remaining requests can be found on the X-UsageLimit-Limit header. |
endpoint_access_restricted |
403 |
Access to the endpoint is not available on your current subscription plan. |
resource_not_found |
404 |
Resource could not be found. |
invalid_api_endpoint |
404 |
API route does not exist. |
rate_limit_reached |
429 |
Too many requests in the past 60 seconds. Rate limit and remaining requests can be found on the X-RateLimit-Limit header. |
server_error |
500 |
A server error occured. |
maintenance_mode |
503 |
The service is currently under maintenance. |
Example Error Response
{
"error": {
"code": "malformed_parameters",
"message": "The published_before parameter(s) are incorrectly formatted."
}
}
Examples
API Examples
Our endpoints are very useful for filtering to find only specific resources you need. Follow each example request below to see how you can build dynamic queries.
Example Request 1
This is a basic request which will return all articles which match the search term "usd" within the title or body of the article:
GET https://api.thenewsapi.com/v1/news/all?api_token=YOUR_API_TOKEN&search=usd
Example Request 2
This will return all articles which match the search term "usd" OR "gbp":
GET https://api.thenewsapi.com/v1/news/all?api_token=YOUR_API_TOKEN&search=usd%20%7C%20gbp
Example Request 3
This will return all articles which match the search term "usd" AND "gbp":
GET https://api.thenewsapi.com/v1/news/all?api_token=YOUR_API_TOKEN&search=usd%20%2B%20gbp
Example Request 4
This will return all articles which match the search term "usd" AND "gbp" but removes any articles which mentions "cad":
GET https://api.thenewsapi.com/v1/news/all?api_token=YOUR_API_TOKEN&search=usd%20%2B%20gbp%20-cad
Example Request 5
This will return all articles which match the search term "forex" AND "usd" OR "gbp" but removes any articles which mentions "cad":
GET https://api.thenewsapi.com/v1/news/all?api_token=YOUR_API_TOKEN&search=forex%20%2B%20%28usd%20%7C%20gbp%29%20-cad
Example Request 6
This is the same as Example Request 5 but will also ensure the articles returned are in English and categorized by business or tech but not travel, and are published within the last week:
GET https://api.thenewsapi.com/v1/news/all?api_token=YOUR_API_TOKEN&search=forex%20%2B%20%28usd%20%7C%20gbp%29%20-cad&language=en&categories=business%2Ctech&exclude_categories=travel&published_after=2021-04-06
Code Examples
See our prepared examples below to quickly get started implementing our API into your next project.
PHP
$queryString = http_build_query([
'api_token' => 'YOUR_API_TOKEN',
'categories' => 'business,tech',
'search' => 'apple',
'limit' => 50,
]);
$ch = curl_init(sprintf('%s?%s', 'https://api.thenewsapi.com/v1/news/all', $queryString));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
curl_close($ch);
$apiResult = json_decode($json, true);
print_r($apiResult);
Python
# Python 3
import http.client, urllib.parse
conn = http.client.HTTPSConnection('api.thenewsapi.com')
params = urllib.parse.urlencode({
'api_token': 'YOUR_API_TOKEN',
'categories': 'business,tech',
'limit': 50,
})
conn.request('GET', '/v1/news/all?{}'.format(params))
res = conn.getresponse()
data = res.read()
print(data.decode('utf-8'))
Go
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
func main() {
baseURL, _ := url.Parse("https://thenewsapi.com")
baseURL.Path += "v1/news/all"
params := url.Values{}
params.Add("api_token", "YOUR_API_TOKEN")
params.Add("categories", "business,tech")
params.Add("search", "apple")
params.Add("limit", "50")
baseURL.RawQuery = params.Encode()
req, _ := http.NewRequest("GET", baseURL.String(), nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}
JavaScript
var requestOptions = {
method: 'GET'
};
var params = {
api_token: 'YOUR_API_TOKEN',
categories: 'business,tech',
search: 'apple',
limit: '50'
};
var esc = encodeURIComponent;
var query = Object.keys(params)
.map(function(k) {return esc(k) + '=' + esc(params[k]);})
.join('&');
fetch("https://api.thenewsapi.com/v1/news/all?" + query, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
C#
var client = new RestClient("https://api.thenewsapi.com/v1/news/all");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddQueryParameter("api_token", "YOUR_API_TOKEN");
request.AddQueryParameter("categories", "business,tech");
request.AddQueryParameter("search", "apple");
request.AddQueryParameter("limit", "50");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
Java
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
HttpUrl.Builder httpBuilder = HttpUrl.parse("https://api.thenewsapi.com/v1/news/all").newBuilder();
httpBuilder.addQueryParameter("api_token", "YOUR_API_TOKEN");
httpBuilder.addQueryParameter("categories", "business,tech");
httpBuilder.addQueryParameter("search", "apple");
httpBuilder.addQueryParameter("limit", "50");
Request request = new Request.Builder().url(httpBuilder.build()).build();
Response response = client.newCall(request).execute();
More
Stock Market News APIs
We also provide a dedicated finance and stock market news and analysis API, perfect for financial apps. Check it out here: marketaux.com.