Count grouped results with multiple filters
Count articles by field and apply multiple filters for analytics dashboards
Input parameters
| Parameter | Description | Type | Default | Required |
|---|---|---|---|---|
| title | Search query. | string | Yes | |
| facet | Count articles by field. | boolean | true | Yes |
| facet.field | Fields to count articles by, separated by commas. | string | Yes | |
| facet.limit | Maximum number of grouped values per field | integer | 10 | Yes |
| published_at.start | Start date filter. | string | Yes | |
| source.rank.opr.min | Minimum source quality. | string | Yes | |
| api_key | Your API key | string | Yes | |
| per_page | Maximum number of articles to retrieve | integer | 20 | No |
Workflow examples
Group results by a field and count them, with filters applied:
curl -X GET "https://api.apitube.io/v1/news/everything?title=AI&facet=true&facet.field=source.id,category.id,language.id,sentiment.overall.polarity&facet.limit=10&published_at.start=2024-01-01&published_at.end=2024-01-31&source.rank.opr.min=5&api_key=YOUR_API_KEY"
Language distribution analysis:
curl -X GET "https://api.apitube.io/v1/news/everything?organization.name=Tesla&facet=true&facet.field=language.id,source.country.id&facet.limit=15&api_key=YOUR_API_KEY"
Media bias distribution:
curl -X GET "https://api.apitube.io/v1/news/everything?topic.id=industry.green_energy_news&facet=true&facet.field=source.bias,source.country.id&api_key=YOUR_API_KEY"
Count articles by hour:
curl -X GET "https://api.apitube.io/v1/news/everything?facet=true&facet.field=published.hour&published_at.start=2024-01-01&api_key=YOUR_API_KEY"
Related examples
- Get article counts by field for analysis
- Count articles by range
- Count articles by field values and ranges
- Select specific fields
- Sort by engagement score
Recipe for cURL
curl --location --globoff --request POST 'https://api.apitube.io/v1/news/everything?title=AI&facet=1&facet.field=source.id%2Ccategory.id%2Clanguage.id%2Csentiment.overall.polarity&facet.limit=10&published_at.start=2024-01-01&source.rank.opr.min=5&api_key=YOUR_API_KEY&per_page=20' \
--header 'Content-Type: application/json'
Recipe for Python
import requests
url = "https://api.apitube.io/v1/news/everything"
querystring = {
"title": "AI",
"facet": true,
"facet.field": "source.id,category.id,language.id,sentiment.overall.polarity",
"facet.limit": 10,
"published_at.start": "2024-01-01",
"source.rank.opr.min": 5,
"api_key": "YOUR_API_KEY",
"per_page": 20
}
response = requests.request("GET", url, params=querystring)
print(response.text)
Recipe for Javascript
import axios from "axios"
const options = {
method: 'GET',
url: 'https://api.apitube.io/v1/news/everything',
params: {
"title": "AI",
"facet": true,
"facet.field": "source.id,category.id,language.id,sentiment.overall.polarity",
"facet.limit": 10,
"published_at.start": "2024-01-01",
"source.rank.opr.min": 5,
"api_key": "YOUR_API_KEY",
"per_page": 20
}};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
Recipe for PHP
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client();
$response = $client->request('GET', 'https://api.apitube.io/v1/news/everything', [
'query' => [
'title' => 'AI',
'facet' => 1,
'facet.field' => 'source.id,category.id,language.id,sentiment.overall.polarity',
'facet.limit' => 10,
'published_at.start' => '2024-01-01',
'source.rank.opr.min' => 5,
'api_key' => 'YOUR_API_KEY',
'per_page' => 20,
],
]);
echo $response->getBody();
Recipe for Java
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "");
Request request = new Request.Builder()
.url("https://api.apitube.io/v1/news/everything?title=AI&facet=1&facet.field=source.id%2Ccategory.id%2Clanguage.id%2Csentiment.overall.polarity&facet.limit=10&published_at.start=2024-01-01&source.rank.opr.min=5&api_key=YOUR_API_KEY&per_page=20")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();