User avatar
zag
Site Admin
Posts: 130
Joined: Tue Oct 11, 2016 9:43 am

API Tutorial

Mon Jan 23, 2017 3:02 pm

Below find complete instructions for using our JSON API. All example links use the test key which should only be used during development or for personal apps. You can request a production API key by clicking this link and following the instructions in this thread. Our API is free but please consider an appropriate yearly donation if your app is commercial. If you create something cool, post it in our Add-on section for a bit of publicity.

API v1 status = STABLE

Search

Search for team by name

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/searchteams.php?t={TeamName}

http://www.thesportsdb.com/api/v1/json/ ... ?t=Arsenal

Search for all players from team

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/searchplayers.php?t={TeamName}

http://www.thesportsdb.com/api/v1/json/ ... ?t=Arsenal

Search for players by name

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/searchplayers.php?p={PlayerName}

http://www.thesportsdb.com/api/v1/json/ ... %20Welbeck

Search for player by team and name

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/searchplayers.php?t={TeamName}&p={Playername}

http://www.thesportsdb.com/api/v1/json/ ... %20Welbeck

Search for event by event name

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/searchevents.php?e={teamname}

http://www.thesportsdb.com/api/v1/json/ ... vs_Chelsea

Search for event by event file name

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/searchfilename.php?e={league}{date}{hometeam} vs {awayteam}

http://www.thesportsdb.com/api/v1/json/ ... vs_Chelsea

Search for event by event name and season

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/searchevents.php?e={eventname}&s={seasonstring}

http://www.thesportsdb.com/api/v1/json/ ... sea&s=1415

Search for all Leagues in a country

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/search_all_leagues.php?c={countryname}

http://www.thesportsdb.com/api/v1/json/ ... ?c=England

Search for all Leagues in a country and by sport

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/search_all_leagues.php?c={countryname}&s={sportname}

http://www.thesportsdb.com/api/v1/json/ ... d&s=Soccer

Search for all Leagues by sport

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/search_all_leagues.php?s={sportname}

http://www.thesportsdb.com/api/v1/json/ ... p?s=soccer

Search for all Teams in a League

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/search_all_teams.php?l={leaguename}

http://www.thesportsdb.com/api/v1/json/ ... r%20League

Search for all Teams in a sport by country

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/search_all_teams.php?s={sportname}&c={countryname}

http://www.thesportsdb.com/api/v1/json/ ... er&c=Spain

Search for all the users loved items

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/searchloves.php?u={username}

http://www.thesportsdb.com/api/v1/json/ ... .php?u=zag

Search for all Seasons in a League

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/search_all_seasons.php?id={leagueid}

http://www.thesportsdb.com/api/v1/json/ ... hp?id=4328

List all leagues and sports

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/all_leagues.php

http://www.thesportsdb.com/api/v1/json/ ... eagues.php

NOTE: You can replace spaces "%20" with underscores if you want, when requesting multi word strings.

User avatar
zag
Site Admin
Posts: 130
Joined: Tue Oct 11, 2016 9:43 am

Re: API Tutorial

Fri Feb 03, 2017 12:28 pm

Lookups

League Details by Id

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/lookupleague.php?id={leagueid}

http://www.thesportsdb.com/api/v1/json/ ... hp?id=4346

League seasons by league Id

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/lookupleague.php?id={leagueid}&s=all

http://www.thesportsdb.com/api/v1/json/ ... 4346&s=all

Team Details by Id

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/lookupteam.php?id={teamid}

http://www.thesportsdb.com/api/v1/json/ ... ?id=133604

Player Details by Id

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/lookuplayer.php?id={playerid}

http://www.thesportsdb.com/api/v1/json/ ... d=34145937

Event Details by Id

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/lookuevent.php?id={eventid}

http://www.thesportsdb.com/api/v1/json/ ... ?id=441613

All teams in a league by League Id

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/lookup_all_teams.php?id={leagueid}

http://www.thesportsdb.com/api/v1/json/ ... hp?id=4328

All players in a team by Team Id

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/lookup_all_players.php?id={teamid}

http://www.thesportsdb.com/api/v1/json/ ... ?id=133604

Lookup Table by League ID and Season

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/lookuptable.php?l={leagueid}&s={season}

http://www.thesportsdb.com/api/v1/json/ ... 328&s=1213

User avatar
zag
Site Admin
Posts: 130
Joined: Tue Oct 11, 2016 9:43 am

Re: API Tutorial

Fri Feb 03, 2017 12:29 pm

Schedules

Next 5 Events by Team Id

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/eventsnext.php?id={teamid}

http://www.thesportsdb.com/api/v1/json/ ... ?id=133602

Next 15 Events by League Id

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/eventsnextleague.php?id={leagueid}

http://www.thesportsdb.com/api/v1/json/ ... hp?id=4328

Next 15 Events by League Id and Round

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/eventsnextleague.php?id={leagueid}&r={round}

http://www.thesportsdb.com/api/v1/json/ ... =4328&r=38

Last 5 Events by Team Id

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/eventslast.php?id={teamid}

http://www.thesportsdb.com/api/v1/json/ ... ?id=133602

Last 15 Events by League Id

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/eventspastleague.php?id={leagueid}

http://www.thesportsdb.com/api/v1/json/ ... hp?id=4328

Events on a specific day

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/eventspastleague.php?d={YYYY-MM-DD}&s={sport_string}&l={league_string}

http://www.thesportsdb.com/api/v1/json/ ... 2014-10-10
http://www.thesportsdb.com/api/v1/json/ ... 0&s=Soccer
http://www.thesportsdb.com/api/v1/json/ ... n_A-League

Events in specific round by season

Code: Select all

thesportsdb.com/api/v1/json/1/eventsround.php?id={leagueid}8&r={round}&s={season}

http://www.thesportsdb.com/api/v1/json/ ... =38&s=1415

All events in specific league by season

Code: Select all

thesportsdb.com/api/v1/json/1/eventsseason.php?id={leagueid}8s={season}

http://www.thesportsdb.com/api/v1/json/ ... 328&s=1415

User avatar
zag
Site Admin
Posts: 130
Joined: Tue Oct 11, 2016 9:43 am

Re: API Tutorial

Fri Feb 03, 2017 12:29 pm

Images

Preview Images
Most of the time you won't want to download the original large image, just get a small preview. This is possible simple by adding "/preview" onto the end URL. This will give you a small 200px version. This will work with JPG images only.

Original Image - http://www.thesportsdb.com/images/media ... 853005.jpg
Small Image - http://www.thesportsdb.com/images/media ... pg/preview

User avatar
zag
Site Admin
Posts: 130
Joined: Tue Oct 11, 2016 9:43 am

Re: API Tutorial

Fri Feb 03, 2017 12:29 pm

Livescores

Soccer Livescores

Code: Select all

thesportsdb.com/api/v1/json/{APIKEY}/latestsoccer.php

http://www.thesportsdb.com/api/v1/json/ ... soccer.php

NOTE: Updated every 2mins (Don't abuse please)

Return to “Developers”