sportsapi.dev Get an API key

Code examples

Ready-to-run requests in cURL, JavaScript, Python and PHP. Switch the base URL to match where you subscribed, then replace the key placeholder.

Everything on TV today in the United States

Live matches on UK channels right now

A team's next eight days with broadcasters

One channel's schedule for a day

NBA games shown in Germany this week

Find a team's ID

Keep your key on the server

A small endpoint on your own server calls the API and returns the result to your app, so the key is never sent to browsers. This PHP version caches each response for two minutes.

<?php
// where-to-watch.php  (your server)
$key   = getenv('SPORTS_TV_API_KEY');
$query = http_build_query([
    'channelCountry' => 'GBR',
    'timezone'       => 'Europe/London',
]);
$cache = sys_get_temp_dir() . '/stv_' . md5($query) . '.json';

if (!is_file($cache) || filemtime($cache) < time() - 120) {
    $ch = curl_init('https://sports-tv-guide-api.p.rapidapi.com/sports-tv/matches?' . $query);
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT        => 15,
        CURLOPT_HTTPHEADER     => [
            'X-RapidAPI-Key: ' . $key,
            'X-RapidAPI-Host: sports-tv-guide-api.p.rapidapi.com',
        ],
    ]);
    $body = curl_exec($ch);
    if ($body !== false && curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200) {
        file_put_contents($cache, $body);
    }
    curl_close($ch);
}

header('Content-Type: application/json');
readfile($cache);