Introduction to the the Stats.(W)NBA API
By Ryan Davis
@rd11490
https://github.com/rd11490
http://nbashotcharts.com
Stats API Format - Requests
GET requests
Standard query parameters
Ex. playerId, gameId, teamId, perMode, season, seasonType, etc.
https://stats.wnba.com/stats/teamgamelogs?DateFrom=&DateTo=&GameSegment=&LastNGames=0&LeagueID=10&Location=&MeasureType=Advanced&Month=0&OpponentTeamID=0&Outcome=&PORound=0&PaceAdjust=N&PerMode=Totals&Period=0&PlusMinus=N&Rank=N&Season=2019&SeasonSegment=&SeasonType=Regular+Season&ShotClockRange=&TeamID=1611661330&VsConference=&VsDivision=
https://stats.wnba.com/team/1611661330/boxscores-advanced/
Common Query Parameters
perMode
Totals
Per36, Per40, Per48
PerGame
Per100Possessions, PerPossession
Per100Plays, PerPlay
MeasureType
Base
Advanced
Misc
Scoring
Usage
Opponent
Defense
LeagueID
NBA: 00
WNBA: 10
Season
NBA - Years over which the season spans
2019-20
WNBA - Year of league season
2019
Headers
Required Headers:
User-Agent
Any value works here
X-nba-stats-origin
‘stats’
Referer
‘https://stats.nba.com’
Stats API Format - Response
{
resource: “RESOURCE_NAME”,
parameters: {
param1: value,
...
},
resultSets: [
{
name : “RESULT_NAME”,
headers: [“TABLE”, “COLUMN”, “HEADERS”],
rowSet: [
[ARRAY, OF, TABLE, ROW, VALUES],
[ARRAY, OF, TABLE, ROW, VALUES]
]
}
}
{
"resource": "gamelogs",
"parameters": {
"MeasureType": "Advanced",
"PerMode": "Totals",
….
},
"resultSets": [{
"name": "TeamGameLogs",
"headers": ["TEAM_ID", "OFF_RATING","DEF_RATING", ...],
"rowSet": [[1611661330, 75.9, 85.5, ...],
[1611661330,96.3,92.5, ...],
[….]]
} ]
}
Format
Example
https://stats.wnba.com/team/1611661330/boxscores-advanced/
Rate Limits and Timeouts
Rate Limit: 1 Request per 1 -1.5 seconds
The API does not throw errors when you do not supply the correct headers or exceed the rate limit. Instead your requests will hang until they timeout as per your api client’s settings.
If you exceed the rate limit for an extended period of time, your requests will start to be timed out and will continue to be for the next approximately 15 minutes
Finding And Extracting Data
https://github.com/rd11490/NBA_Tutorials/tree/master/finding_endpoints
Resources
NBASense - Jason Roman
User generated documentation for the stats.nba api.
http://nbasense.com/
nba_scraper - Matthew Barlowe
Python API client for the stats.nba api
https://github.com/mcbarlowe/nba_scraper
nbastatR - Alex Bresler
R API client for the stats.nba api
https://github.com/abresler/nbastatR
https://curl.trillworks.com/
Paste in a cURL and it auto-generates code to make the api call