API Tutorial and Examples

Intro

Our free sports API has been designed to be easy to use and quick to get working.
All our API methods should work in a standard browser with the jsonview extension or something like postman
Lets take a look at a few specific examples of looking up a team.

PHP

Simple example here to show the teams badge after a name search for "Arsenal".
$json = file_get_contents("https://www.thesportsdb.com/api/v1/json/3/searchteams.php?t=Arsenal");
$json_decoded = (json_decode($json));
echo 'Team Badge = ' . ($json_decoded->teams[0]->strTeamBadge);

Python

Here we are looking up certain events by ID and printing the output to the console.
import requests

def lookup_events(event_ids):
    for event_id in event_ids:
        api_call = requests.get(f"https://www.thesportsdb.com/api/v1/json/3/lookupevent.php?id={event_id}")
        storage = api_call.json()
        for event in storage["events"]:
            date_event = event["dateEvent"]
            home_team = event["strHomeTeam"]
            away_team = event["strAwayTeam"]

        print(f"{date_event}: {home_team} vs {away_team}")

event_ids = [2052711, 2052712, 2052713, 2052714]

lookup_events(event_ids)

Javascript

Just reading the JSON file here and outputting the entire payload to the console
function fetchJSONData() {
            fetch("https://www.thesportsdb.com/api/v1/json/3/searchteams.php?t=Arsenal")
                .then((res) => {
                    if (!res.ok) {
                        throw new Error
                            (`HTTP error! Status: ${res.status}`);
                    }
                    return res.json();
                })
                .then((data) => 
                      console.log(data))
                .catch((error) => 
                       console.error("Unable to fetch data:", error));
        }
        fetchJSONData();