Count grouped results with multiple filters

Count articles by field and apply multiple filters for analytics dashboards

Input parameters

ParameterDescriptionTypeDefaultRequired
titleSearch query.stringYes
facetCount articles by field.booleantrueYes
facet.fieldFields to count articles by, separated by commas.stringYes
facet.limitMaximum number of grouped values per fieldinteger10Yes
published_at.startStart date filter.stringYes
source.rank.opr.minMinimum source quality.stringYes
api_keyYour API keystringYes
per_pageMaximum number of articles to retrieveinteger20No

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

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();
		
  • CNN
  • Techcrunch
  • Vox
  • Apple
  • Microsoft
  • IBM
  • Bloomberg
  • Spotify
We use cookies

By clicking "Accept", you agree to cookies on your device for the site to work and for analytics.