### API Authentication Example Source: https://mediastack.com/documentation/index This example demonstrates how to authenticate with the mediastack API by including your unique access key as a GET parameter in the base URL. Ensure you replace 'YOUR_ACCESS_KEY' with your actual key. HTTPS is recommended for secure connections. ```plaintext https://api.mediastack.com/v1/news ? access_key = YOUR_ACCESS_KEY ``` -------------------------------- ### Go Code Example Source: https://mediastack.com/documentation/index Example of how to fetch news articles using the MediaStack API with Go, including filtering by sources, categories, and languages. ```APIDOC ## Code Example - Go ### Description This Go code snippet demonstrates how to make an HTTP GET request to the MediaStack news API, specifying sources, categories, and languages. ### Language Go ### Code ```go package main import ( "fmt" "io/ioutil" "net/http" "net/url" ) func main() { baseURL, _ := url.Parse("https://api.mediastack.com") baseURL.Path += "v1/news" params := url.Values{} // Access Key params.Add("access_key", "ACCESS_KEY") // Parameters params.Add("sources", "cnn,bbc") params.Add("categories", "sports,general") params.Add("languages", "-en") // It will exclude english results 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)) } ``` ``` -------------------------------- ### Fetch News with Filters - Go Example Source: https://mediastack.com/documentation/index This Go code snippet illustrates how to make an HTTP GET request to the MediaStack API to retrieve news articles. It constructs the URL with query parameters for `access_key`, `sources`, `categories`, and `languages`, including an example of excluding English results. It then reads and prints the response body. ```go package main import ( "fmt" "io/ioutil" "net/http" "net/url" ) func main() { baseURL, _ := url.Parse("https://api.mediastack.com") baseURL.Path += "v1/news" params := url.Values{} // Access Key params.Add("access_key", "ACCESS_KEY") // Parameters params.Add("sources", "cnn,bbc") params.Add("categories", "sports,general") params.Add("languages", "-en") // It will exclude english results 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)) } ``` -------------------------------- ### Python Code Example Source: https://mediastack.com/documentation/index Example of how to fetch news articles using the MediaStack API with Python, including filtering by categories. ```APIDOC ## Code Example - Python ### Description This Python code snippet demonstrates how to make a request to the MediaStack news API, specifying categories and sorting order. ### Language Python ### Code ```python # Python 3 import http.client, urllib.parse conn = http.client.HTTPConnection('api.mediastack.com') params = urllib.parse.urlencode({ 'access_key': 'ACCESS_KEY', 'categories': '-general,-sports', 'sort': 'published_desc', 'limit': 10, }) conn.request('GET', '/v1/news?{}'.format(params)) res = conn.getresponse() data = res.read() print(data.decode('utf-8')) ``` ``` -------------------------------- ### PHP Code Example Source: https://mediastack.com/documentation/index Example of how to fetch news articles using the MediaStack API with PHP, including filtering by keywords and categories. ```APIDOC ## Code Example - PHP ### Description This PHP code snippet demonstrates how to make a request to the MediaStack news API, specifying keywords and categories. ### Language PHP ### Code ```php 'ACCESS_KEY', 'keywords' => 'Wall street -wolf', 'categories' => '-entertainment', 'sort' => 'popularity', ]); $ch = curl_init(sprintf('%s?%s', 'https://api.mediastack.com/v1/news', $queryString)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $json = curl_exec($ch); curl_close($ch); $apiResult = json_decode($json, true); print_r($apiResult); ?> ``` ``` -------------------------------- ### Fetch News with Filters - Python Example Source: https://mediastack.com/documentation/index This Python 3 code snippet shows how to fetch news articles from the MediaStack API. It uses the `http.client` and `urllib.parse` modules to construct and send the GET request. The example includes filtering by categories and sorting the results. ```python # Python 3 import http.client, urllib.parse conn = http.client.HTTPConnection('api.mediastack.com') params = urllib.parse.urlencode({ 'access_key': 'ACCESS_KEY', 'categories': '-general,-sports', 'sort': 'published_desc', 'limit': 10, }) conn.request('GET', '/v1/news?{}'.format(params)) res = conn.getresponse() data = res.read() print(data.decode('utf-8')) ``` -------------------------------- ### Example News API Request Source: https://mediastack.com/documentation/index This is an example API request to the mediastack news endpoint. It demonstrates how to include your access key and filter by keywords and countries. Ensure you replace 'YOUR_ACCESS_KEY' with your actual API key. ```http https://api.mediastack.com/v1/news ? access_key = YOUR_ACCESS_KEY & keywords = tennis & countries = us, gb, de ``` -------------------------------- ### jQuery Code Example Source: https://mediastack.com/documentation/index Example of how to fetch news articles using the MediaStack API with jQuery, including filtering by languages and countries. ```APIDOC ## Code Example - jQuery ### Description This jQuery code snippet demonstrates how to make an AJAX request to the MediaStack news API, specifying languages, countries, and pagination. ### Language JavaScript (jQuery) ### Code ```javascript $.ajax({ url: 'https://api.mediastack.com/v1/news', data: { access_key: 'ACCESS_KEY', languages: 'fr,-en', countries: 'ca,fr', limit: 30, offset: 30, } }).done(function(data) { console.log(JSON.parse(data)); }); ``` ``` -------------------------------- ### Example News API Response Structure Source: https://mediastack.com/documentation/index This is an example of a successful API response from the mediastack news endpoint. It includes pagination details and a 'data' array containing news article objects, each with fields like author, title, description, and publication date. ```json { "pagination": { "limit": 100, "offset": 0, "count": 100, "total": 293 }, "data": [ { "author": "TMZ Staff", "title": "Rafael Nadal Pulls Out Of U.S. Open Over COVID-19 Concerns", "description": "Rafael Nadal is officially OUT of the U.S. Open ... the tennis legend said Tuesday it's just too damn unsafe for him to travel to America during the COVID-19 pandemic. \"The situation is very complicated worldwide,\" Nadal wrote in a statement. \"The…", "url": "https://www.tmz.com/2020/08/04/rafael-nadal-us-open-tennis-covid-19-concerns/", "source": "TMZ.com", "image": "https://imagez.tmz.com/image/fa/4by3/2020/08/04/fad55ee236fc4033ba324e941bb8c8b7_md.jpg", "category": "general", "language": "en", "country": "us", "published_at": "2020-08-05T05:47:24+00:00" }, [...] ] } ``` -------------------------------- ### Fetch News with Filters - PHP Example Source: https://mediastack.com/documentation/index This PHP code snippet demonstrates how to make an API request to fetch news articles. It utilizes `http_build_query` for parameter construction and `curl` for making the HTTP request. The example shows filtering by keywords and categories, and sorting by popularity. ```php $queryString = http_build_query([ 'access_key' => 'ACCESS_KEY', 'keywords' => 'Wall street -wolf', // the word "wolf" will be 'categories' => '-entertainment', 'sort' => 'popularity', ]); $ch = curl_init(sprintf('%s?%s', 'https://api.mediastack.com/v1/news', $queryString)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $json = curl_exec($ch); curl_close($ch); $apiResult = json_decode($json, true); print_r($apiResult); ``` -------------------------------- ### Example API Error Response Source: https://mediastack.com/documentation/index This JSON structure illustrates a typical API error response from mediastack. It includes an 'error' object containing 'code', 'message', and 'context' to help diagnose the issue, such as an invalid 'date' parameter. ```json { "error": { "code": "validation_error", "message": "Validation error", "context": { "date": [ "NO_SUCH_CHOICE_ERROR" ] } } } ``` -------------------------------- ### GET /v1/news Source: https://mediastack.com/documentation/index Retrieve news articles based on specified criteria. Supports real-time and historical data retrieval. ```APIDOC ## GET /v1/news ### Description Retrieve news articles based on specified criteria. Supports real-time and historical data retrieval. ### Method GET ### Endpoint https://api.mediastack.com/v1/news ### Parameters #### Query Parameters - **access_key** (string) - Required - Your unique API access key. - **date** (string) - Required - Historical date or date range in YYYY-MM-DD format. Example: `2020-01-01` or `2020-12-24,2020-12-31`. - **sources** (string) - Optional - Comma-separated news sources to include or exclude. Example: `cnn,-bbc`. - **categories** (string) - Optional - Comma-separated news categories to include or exclude. Example: `business,-sports`. - **countries** (string) - Optional - Comma-separated country codes to include or exclude. Example: `au,-us`. - **languages** (string) - Optional - Comma-separated language codes to include or exclude. Example: `en,-de`. - **keywords** (string) - Optional - Comma-separated search keywords to include or exclude. Example: `virus,-corona`. - **sort** (string) - Optional - Sorting order. Available values: `published_desc` (default), `published_asc`, `popularity`. - **limit** (integer) - Optional - Number of results per page. Default: `25`, Max: `100`. - **offset** (integer) - Optional - Pagination offset value. Default: `0`. ### Request Example ``` https://api.mediastack.com/v1/news?access_key=YOUR_ACCESS_KEY&date=2020-07-17&categories=general ``` ### Response #### Success Response (200) - **pagination** (object) - **limit** (integer) - The pagination limit value. - **offset** (integer) - The pagination offset value. - **count** (integer) - The number of results on the current page. - **total** (integer) - The total count of available results. - **data** (array of objects) - **author** (string) - The name of the author of the news article. - **title** (string) - The title text of the news article. - **description** (string) - The description text of the news article. - **url** (string) - The URL leading to the news article. - **source** (string) - The news source. - **image** (string) - An image URL associated with the news article. - **category** (string) - The category associated with the news article. - **language** (string) - The language of the news article. - **country** (string) - The country code of the news article. - **published_at** (string) - The exact timestamp the news article was published. #### Response Example ```json { "pagination": { "limit": 100, "offset": 0, "count": 100, "total": 293 }, "data": [ { "author": "CNN Staff", "title": "This may be the big winner of the market crash", "description": "This may be the big winner of the market crash", "url": "http://rss.cnn.com/~r/rss/cnn_topstories/~3/KwE80_jkKo8/a-sa-dd-3", "source": "CNN", "image": "https://cdn.cnn.com/cnnnext/dam/assets/150325082152-social-gfx-cnn-logo-super-169.jpg", "category": "general", "language": "en", "country": "us", "published_at": "2020-07-17T23:35:06+00:00" } ] } ``` ``` -------------------------------- ### Fetch News with Filters - jQuery Example Source: https://mediastack.com/documentation/index This jQuery code snippet demonstrates fetching news articles using an AJAX request. It configures the request with parameters such as `access_key`, `languages`, `countries`, `limit`, and `offset`. The response is then parsed as JSON and logged to the console. ```javascript $.ajax({ url: 'https://api.mediastack.com/v1/news', data: { access_key: 'ACCESS_KEY', languages: 'fr,-en', countries: 'ca,fr', limit: 30, offset: 30, } }).done(function(data) { console.log(JSON.parse(data)); }); ``` -------------------------------- ### Mediastack API Example Request with Date Parameter Source: https://mediastack.com/documentation/index This snippet demonstrates how to construct an API request to retrieve historical news data. It requires an access key and specifies a date parameter in YYYY-MM-DD format. This functionality is available on the Standard Plan and higher. ```HTTP https://api.mediastack.com/v1/news ? access_key = YOUR_ACCESS_KEY & date = 2020-07-17 ``` -------------------------------- ### GET /v1/news Source: https://mediastack.com/documentation/index Retrieves a list of news articles. Supports filtering by keywords, sources, categories, countries, languages, and date. Allows for sorting, pagination, and limiting results. ```APIDOC ## GET /v1/news ### Description Retrieves a list of news articles from the mediastack API. This endpoint allows for extensive filtering and customization of news results based on various parameters. ### Method GET ### Endpoint https://api.mediastack.com/v1/news ### Parameters #### Query Parameters - **access_key** (string) - Required - Your unique API access key. - **keywords** (string) - Optional - Search for specific keywords. Can also exclude words by prefixing with '-'. Example: `news -breaking" - **sources** (string) - Optional - Include or exclude specific news sources. Comma-separated. Example: `cnn,-bbc` - **categories** (string) - Optional - Include or exclude specific news categories. Comma-separated. Example: `business,-sports` - **countries** (string) - Optional - Include or exclude specific countries. Comma-separated. Example: `au,-us` - **languages** (string) - Optional - Include or exclude specific languages. Comma-separated. Example: `en,-de` - **date** (string) - Optional - Specify a date or date range. Example: `2020-01-01` or `2020-12-24,2020-12-31` - **sort** (string) - Optional - Sorting order. Available values: `published_desc` (default), `published_asc`, `popularity`. - **limit** (integer) - Optional - Number of results per page. Default: 25, Max: 100. - **offset** (integer) - Optional - Pagination offset value. Default: 0. ### Request Example ``` https://api.mediastack.com/v1/news?access_key=YOUR_ACCESS_KEY&keywords=tennis&countries=us,gb,de ``` ### Response #### Success Response (200) - **pagination** (object) - **limit** (integer) - The pagination limit used for the request. - **offset** (integer) - The pagination offset used for the request. - **count** (integer) - The number of results on the current page. - **total** (integer) - The total number of available results. - **data** (array of objects) - An array containing news article objects. - **author** (string) - The author of the news article. - **title** (string) - The title of the news article. - **description** (string) - A brief description of the news article. - **url** (string) - The URL to the full news article. - **source** (string) - The news source. - **image** (string) - URL of an image associated with the article. - **category** (string) - The category of the news article. - **language** (string) - The language of the news article. - **country** (string) - The country associated with the news article. - **published_at** (string) - The publication date and time of the article. #### Response Example ```json { "pagination": { "limit": 100, "offset": 0, "count": 100, "total": 293 }, "data": [ { "author": "TMZ Staff", "title": "Rafael Nadal Pulls Out Of U.S. Open Over COVID-19 Concerns", "description": "Rafael Nadal is officially OUT of the U.S. Open ... the tennis legend said Tuesday it's just too damn unsafe for him to travel to America during the COVID-19 pandemic. \"The situation is very complicated worldwide,\" Nadal wrote in a statement. \"The…", "url": "https://www.tmz.com/2020/08/04/rafael-nadal-us-open-tennis-covid-19-concerns/", "source": "TMZ.com", "image": "https://imagez.tmz.com/image/fa/4by3/2020/08/04/fad55ee236fc4033ba324e941bb8c8b7_md.jpg", "category": "general", "language": "en", "country": "us", "published_at": "2020-08-05T05:47:24+00:00" } ] } ``` ``` -------------------------------- ### GET /v1/sources - List Available News Sources Source: https://mediastack.com/documentation/index Retrieves a list of all news sources supported by the MediaStack API. This endpoint is useful for obtaining source metadata, including the `id` required for requesting news. ```APIDOC ## GET /v1/sources ### Description Retrieves a list of all news sources supported by the MediaStack API. This endpoint is useful for obtaining source metadata, including the `id` required for requesting news. ### Method GET ### Endpoint https://api.mediastack.com/v1/sources ### Parameters #### Query Parameters - **access_key** (string) - Required - Your unique API access key. - **search** (string) - Required - One or multiple search keywords. - **countries** (string) - Optional - Comma-separated list of countries to include or exclude. - **languages** (string) - Optional - Comma-separated list of languages to include or exclude. - **categories** (string) - Optional - Comma-separated list of news categories to include or exclude. - **limit** (integer) - Optional - Number of results per page. Default: 25, Max: 100. - **offset** (integer) - Optional - Pagination offset value. Default: 0. ### Request Example ``` GET https://api.mediastack.com/v1/sources?access_key=YOUR_ACCESS_KEY&search=abc ``` ### Response #### Success Response (200) - **pagination** (object) - **limit** (integer) - The pagination limit value. - **offset** (integer) - The pagination offset value. - **count** (integer) - The results count on the current page. - **total** (integer) - The total count of available results. - **data** (array of objects) - **id** (string) - The source ID of the news source. - **name** (string) - The name of the news source. - **category** (string) - The category associated with the news source. - **country** (string) - The country associated with the news source. - **language** (string) - The language associated with the news source. - **url** (string) - A URL leading to the news source. #### Response Example ```json { "pagination": { "limit": 100, "offset": 0, "count": 100, "total": 1364 }, "data": [ { "id": "abc-au", "name": "ABC AU", "category": "general", "country": "au", "language": "en", "url": "http://abc.net.au/" }, [...] ] } ``` ``` -------------------------------- ### Filter News by Keywords - API Request Source: https://mediastack.com/documentation/index This example illustrates how to narrow down news searches using the `keywords` parameter, which accepts one or more comma-separated keywords. Both inclusion and exclusion (using '-') of keywords are supported. This parameter is available on all plans. ```api https://api.mediastack.com/v1/news ? access_key = YOUR_ACCESS_KEY & keywords = virus,-corona ``` -------------------------------- ### Mediastack API Example Response Structure Source: https://mediastack.com/documentation/index This snippet shows the typical JSON structure of a response from the mediastack API. It includes pagination details and a 'data' array containing individual news articles with fields like author, title, description, URL, source, image, category, language, country, and publication timestamp. ```JSON { "pagination": { "limit": 100, "offset": 0, "count": 100, "total": 293 }, "data": [ { "author": "CNN Staff", "title": "This may be the big winner of the market crash", "description": "This may be the big winner of the market crash", "url": "http://rss.cnn.com/~r/rss/cnn_topstories/~3/KwE80_jkKo8/a-sa-dd-3", "source": "CNN", "image": "https://cdn.cnn.com/cnnnext/dam/assets/150325082152-social-gfx-cnn-logo-super-169.jpg", "category": "general", "language": "en", "country": "us", "published_at": "2020-07-17T23:35:06+00:00" }, [...] ] } ``` -------------------------------- ### GET /v1/news - Fetch News Articles Source: https://mediastack.com/documentation/index Retrieves news articles based on specified filters. You can filter by news sources, categories, countries, languages, and more. ```APIDOC ## GET /v1/news ### Description Retrieves news articles based on specified filters. You can filter by news sources, categories, countries, languages, and more. ### Method GET ### Endpoint https://api.mediastack.com/v1/news ### Parameters #### Query Parameters - **access_key** (string) - Required - Your unique API access key. - **sources** (string) - Optional - Comma-separated list of news source IDs to include or exclude (prepend with `-` to exclude). - **categories** (string) - Optional - Comma-separated list of news categories to include or exclude (prepend with `-` to exclude). Available categories: `general`, `business`, `entertainment`, `health`, `science`, `sports`, `technology`. - **countries** (string) - Optional - Comma-separated list of countries to include or exclude. - **languages** (string) - Optional - Comma-separated list of languages to include or exclude. - **keywords** (string) - Optional - Search for articles containing specific keywords. - **limit** (integer) - Optional - Number of results per page. Default: 25, Max: 100. - **offset** (integer) - Optional - Pagination offset value. Default: 0. - **sort** (string) - Optional - Sorting order. Possible values: `relevancy`, `popularity`, `timestamp`. - **published_after** (string) - Optional - Filter articles published after a specific date (YYYY-MM-DD). - **published_before** (string) - Optional - Filter articles published before a specific date (YYYY-MM-DD). ### Request Example ``` GET https://api.mediastack.com/v1/news?access_key=YOUR_ACCESS_KEY&sources=cnn,-bbc&categories=health,-sports ``` ### Response #### Success Response (200) (The structure of the success response is similar to the `/sources` endpoint, but the `data` array will contain news article objects with fields like `title`, `description`, `url`, `published_at`, etc.) #### Response Example (Refer to the example response for the `/sources` endpoint for the general structure. The `data` array will contain article-specific details.) ``` -------------------------------- ### Filter News by Country - API Request Source: https://mediastack.com/documentation/index This example shows how to filter news articles by specifying one or more comma-separated 2-letter country codes using the `countries` parameter. Exclusion of countries is possible by prepending a '-' symbol. This parameter is available on all plans. ```api https://api.mediastack.com/v1/news ? access_key = YOUR_ACCESS_KEY & countries = au,-us ``` -------------------------------- ### Filter News by Language - API Request Source: https://mediastack.com/documentation/index This example demonstrates filtering news articles by language using the `languages` parameter, which accepts one or more comma-separated 2-letter language codes. Similar to the `countries` parameter, languages can be excluded by prefixing with '-'. This feature is available on all plans. ```api https://api.mediastack.com/v1/news ? access_key = YOUR_ACCESS_KEY & languages = en,-de ``` -------------------------------- ### Fetch News Sources with Search Filter Source: https://mediastack.com/documentation/index This snippet demonstrates how to fetch news sources supported by the MediaStack API. It utilizes the 'sources' endpoint with required 'access_key' and 'search' parameters. Optional parameters like 'countries', 'languages', 'categories', 'limit', and 'offset' can be used for further filtering and pagination. ```http GET https://api.mediastack.com/v1/sources?access_key=YOUR_ACCESS_KEY&search=abc ``` -------------------------------- ### Search News by Keywords Source: https://mediastack.com/documentation/index This endpoint allows you to search for news articles containing specific keywords. You can specify multiple keywords and also exclude certain keywords using a '-' prefix. ```APIDOC ## GET /v1/news ### Description Retrieves news articles, with the option to search by keywords. ### Method GET ### Endpoint https://api.mediastack.com/v1/news ### Query Parameters - **access_key** (string) - Required - Your unique API access key. - **keywords** (string) - Optional - Comma-separated keywords to search for. Prepend with `-` to exclude. ### Request Example ``` https://api.mediastack.com/v1/news?access_key=YOUR_ACCESS_KEY&keywords=virus,-corona ``` ### Response #### Success Response (200) - **data** (array) - Array of news articles matching the criteria. #### Response Example ```json { "data": [ { "title": "Example News Title", "source": "Example Source", "url": "http://example.com/news", "image": null, "published_at": "2023-10-27T10:00:00+00:00" } ] } ``` ``` -------------------------------- ### News API Endpoint Source: https://mediastack.com/documentation/index Retrieve news articles using the primary news endpoint. Supports filtering by date, country, language, source, and keywords. ```APIDOC ## GET /v1/news ### Description This endpoint retrieves news articles based on specified filters. You can narrow down results by dates, timeframes, countries, languages, sources, and search keywords. ### Method GET ### Endpoint `https://api.mediastack.com/v1/news` ### Parameters #### Query Parameters - **access_key** (string) - Required - Your unique API access key. - **date** (string) - Optional - Filter by a specific date (YYYY-MM-DD) or a date range (YYYY-MM-DD,YYYY-MM-DD). - **countries** (string) - Optional - Filter by country codes (e.g., US,GB,FR). - **languages** (string) - Optional - Filter by language codes (e.g., en,fr,de). - **sources** (string) - Optional - Filter by news source IDs (e.g., bbc-news,cnn). - **keywords** (string) - Optional - Search for news articles containing specific keywords. ### Request Example ``` https://api.mediastack.com/v1/news?access_key=YOUR_ACCESS_KEY&countries=us,gb&keywords=technology ``` ### Response #### Success Response (200) - **data** (array) - An array of news article objects. - **author** (string) - The author of the article. - **title** (string) - The title of the article. - **description** (string) - A brief description of the article. - **url** (string) - The URL of the article. - **source** (string) - The news source. - **image** (string) - URL of the article's image. - **category** (string) - The category of the article. - **published_at** (string) - The publication date and time. #### Response Example ```json { "data": [ { "author": "John Doe", "title": "New Tech Breakthrough Announced", "description": "A significant advancement in AI technology.", "url": "https://example.com/news/tech-breakthrough", "source": "Tech Times", "image": "https://example.com/images/tech.jpg", "category": "technology", "published_at": "2023-10-27T10:00:00Z" } ] } ``` ### Error Handling If the API request is unsuccessful, a JSON error object will be returned with `code`, `message`, and `context` fields. **Example Error:** ```json { "error": { "code": "validation_error", "message": "Validation error", "context": { "date": [ "NO_SUCH_CHOICE_ERROR" ] } } } ``` **Common API Errors:** Type | Description ---|--- `invalid_access_key` | An invalid API access key was supplied. `missing_access_key` | No API access key was supplied. `usage_limit_reached` | The given user account has reached its monthly allowed request volume. `rate_limit_reached` | The given user account has reached the rate limit. `internal_error` | An internal error occurred. ``` -------------------------------- ### Filter News Articles by Categories Source: https://mediastack.com/documentation/index This snippet demonstrates how to filter news articles by category using the 'categories' parameter. You can specify one or multiple categories separated by commas and also exclude categories by prepending them with a '-' symbol. The 'access_key' is a required parameter. ```http GET https://api.mediastack.com/v1/news?access_key=YOUR_ACCESS_KEY&categories=health,-sports ``` -------------------------------- ### Filter News Articles by Specific Sources Source: https://mediastack.com/documentation/index This snippet shows how to filter news articles by specifying desired news sources using the 'sources' parameter in the API request. You can include multiple sources separated by commas or exclude sources by prepending them with a '-' symbol. The 'access_key' is also required. ```http GET https://api.mediastack.com/v1/news?access_key=YOUR_ACCESS_KEY&sources=cnn,-bbc ``` -------------------------------- ### Filter News by Language Source: https://mediastack.com/documentation/index This endpoint allows you to filter news articles by specifying one or more languages using their 2-letter codes. You can include or exclude languages by using a '+' or '-' prefix respectively. ```APIDOC ## GET /v1/news ### Description Retrieves news articles, with the option to filter by language. ### Method GET ### Endpoint https://api.mediastack.com/v1/news ### Query Parameters - **access_key** (string) - Required - Your unique API access key. - **languages** (string) - Optional - Comma-separated 2-letter language codes. Prepend with `-` to exclude. ### Request Example ``` https://api.mediastack.com/v1/news?access_key=YOUR_ACCESS_KEY&languages=en,-de ``` ### Response #### Success Response (200) - **data** (array) - Array of news articles matching the criteria. #### Response Example ```json { "data": [ { "title": "Example News Title", "source": "Example Source", "url": "http://example.com/news", "image": null, "published_at": "2023-10-27T10:00:00+00:00" } ] } ``` ``` -------------------------------- ### Filter News by Country Source: https://mediastack.com/documentation/index This endpoint allows you to filter news articles by specifying one or more countries using their 2-letter codes. You can include or exclude countries by using a '+' or '-' prefix respectively. ```APIDOC ## GET /v1/news ### Description Retrieves news articles, with the option to filter by country. ### Method GET ### Endpoint https://api.mediastack.com/v1/news ### Query Parameters - **access_key** (string) - Required - Your unique API access key. - **countries** (string) - Optional - Comma-separated 2-letter country codes. Prepend with `-` to exclude. ### Request Example ``` https://api.mediastack.com/v1/news?access_key=YOUR_ACCESS_KEY&countries=au,-us ``` ### Response #### Success Response (200) - **data** (array) - Array of news articles matching the criteria. #### Response Example ```json { "data": [ { "title": "Example News Title", "source": "Example Source", "url": "http://example.com/news", "image": null, "published_at": "2023-10-27T10:00:00+00:00" } ] } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.