-
Notifications
You must be signed in to change notification settings - Fork 0
Misc Snippets
Questions I answered on ESPN API Cheatsheet for NFL
Build Code
curl -o comments.json 'https://api.github.com/gists/ee26cb2a0716de0947a0a4e9a157bc1c/comments?per_page=100'
jq -r --arg gist_url 'https://gist.github.com/nntrn/ee26cb2a0716de0947a0a4e9a157bc1c' 'map(
select((.author_association=="OWNER") and (.body|contains("http")))
| [
"\(.body | gsub("@[^\\s]+[\\s:-]?";"";"x") | gsub("[\\r]";"";"x"))",
"\n ",
"\n<sub>*Answered on \(.created_at|strptime("%Y-%m-%dT%H:%M:%SZ")|strflocaltime("%c"))* — [#\(.id)](\($gist_url)?permalink_comment_id=\(.id)#gistcomment-\(.id))</sub>"
] | join("")
) | join("\n\n\("-"*80)\n\n")|gsub("\n[\n]{2,}";"\n\n")' comments.json | pbcopy
- Team specific - look under newsFeed
- Tweets and news articles by ESPN staff writers - look under nowFeed
Updating my gist shortly to include those - let me know if that helps!!
Answered on Mon Sep 13 01:02:31 2021 — #3890847
cdn.espn.com/core/nfl/scoreboard?xhr=1 - get current games from .content.sbData.events[]
then fillter status to get current games
fetch('https://cdn.espn.com/core/nfl/scoreboard?xhr=1')
.then(res => res.json())
.then(dat => dat.content.sbData.events)
// .then(events => events.filter(e => e.status.type.description !== 'Final'))
.then(e => console.log(e))
Answered on Wed Sep 15 04:45:41 2021 — #3893509
Here's the url for nccaf - https://sports.core.api.espn.com/v2/sports/football/leagues/college-football
For future reference, you can find all football leagues here: https://sports.core.api.espn.com/v2/sports/football/leagues
{
"count": 4,
"pageIndex": 1,
"pageSize": 25,
"pageCount": 1,
"items": [
{
"$ref": "http://sports.core.api.espn.com/v2/sports/football/leagues/college-football?lang=en®ion=us"
},
{
"$ref": "http://sports.core.api.espn.com/v2/sports/football/leagues/nfl?lang=en®ion=us"
},
{
"$ref": "http://sports.core.api.espn.com/v2/sports/football/leagues/xfl?lang=en®ion=us"
},
{
"$ref": "http://sports.core.api.espn.com/v2/sports/football/leagues/cfl?lang=en®ion=us"
}
]
}
Answered on Wed Nov 24 22:00:16 2021 — #3973705
I don't think you can get historical team roster for a season/year (can you imagine what a nightmare it would be keeping track of players being traded)
BUT - and hopefully this helps - you can get team roster for every game in a season
Example:
Roster for JAX on 2001-10-19 from BUF @ JAX https://sports.core.api.espn.com/v2/sports/football/leagues/nfl/events/211018030/competitions/211018030/competitors/30/roster
^^^ that's just for one game, I suppose if you wanted the whole season, you could do the nightmare thing and comb through every game played by JAX in 2001 and stitch together the rosters that way
Answered on Fri Dec 3 18:37:45 2021 — #3983232
you can get news like data from videos https://site.web.api.espn.com/apis/common/v3/sports/football/nfl/athletes/<ATHLETE_ID>
here's an example using brady
$ URL=https://site.web.api.espn.com/apis/common/v3/sports/football/nfl/athletes/2330
$ curl -s $URL | jq '.videos[]|{date:.originalPublishDate,headline,caption}'
{
"date": "2022-08-18T15:53:53.000+0000",
"headline": "Is waiting for a QB the smartest move this season?",
"caption": "Mike Clay discusses why waiting to pick up a quarterback in the later rounds worked for him."
}
{
"date": "2022-08-18T12:40:23.000+0000",
"headline": "Why Saturday is hitting the panic button for the Bucs",
"caption": "Jeff Saturday is worried about the absence of Tom Brady and the lack of firepower on the Buccaneers' O-line."
}
{
"date": "2022-08-15T16:30:37.000+0000",
"headline": "Can Tom Brady continue to dominate going into his 23rd season?",
"caption": "Liz Loza is worried Tom Brady won't be able to play all 17 games due to age and lack of elusiveness."
}
{
"date": "2022-08-12T12:49:59.000+0000",
"headline": "Will Tom Brady's absence impact the Bucs' offensive chemistry?",
"caption": "Tim Hasselbeck and Chris Canty consider the effect Tom Brady's absence will have leading up to Week 1."
}
{
"date": "2022-08-12T01:38:20.000+0000",
"headline": "Can Tom Brady pick up where he left off last season?",
"caption": "Adam Schefter has no doubts that Tom Brady can still perform at a high level this season."
}
{
"date": "2022-08-03T13:22:18.000+0000",
"headline": "Why Tom Brady needs to have his best season yet with the Bucs",
"caption": "Dianna Russini and Dan Orlovsky explain why the missing pieces to the Bucs' offensive line mean Tom Brady will have to produce his best season yet."
}
{
"date": "2022-06-22T14:42:49.000+0000",
"headline": "RG III, Stephen A. get heated debating Gronk's effect on Brady's legacy",
"caption": "Stephen A. Smith and Robert Griffin III go back and forth on if Tom Brady is still the GOAT if he didn't play with Rob Gronkowski."
}
...
Answered on Sun Aug 21 02:22:52 2022 — #4273843
Anyone know an alternative for the old API to get the scores for a particular week? The new api here (v2) is crap because you need to go to so many nested links. There's even a separate link to get the score for a particular team, it isn't included in the event page directly. The old URL (for example, below) doesn't seem to return a JSON anymore :(
//www.espn.com/nfl/schedule/_/year/2022/week/1/?xhr=1
SCOREBOARD: https://site.api.espn.com/apis/site/v2/sports/football/nfl/scoreboard
Extracting team scores using jq:
curl -s 'https://site.api.espn.com/apis/site/v2/sports/football/nfl/scoreboard?dates=20200914-20200915' |
jq '[.events[]| {
id: .id, date: .date, game: .shortName,
scores: (.competitions[].competitors|map({key:.team.abbreviation,value:(.linescores|map(.value)|add)})|from_entries)
}]'
Output:
[
{
"id": "401220256",
"date": "2020-09-14T23:15Z",
"game": "PIT @ NYG",
"scores": {
"NYG": 16,
"PIT": 26
}
},
{
"id": "401220217",
"date": "2020-09-15T02:10Z",
"game": "TEN @ DEN",
"scores": {
"DEN": 14,
"TEN": 16
}
}
]
Answered on Tue Sep 20 15:53:32 2022 — #4309379
Can anyone tell me how to get the current year projections? When I use the link https://sports.core.api.espn.com/v2/sports/football/leagues/nfl/seasons/2021/types/2/athletes/14876/projections and change the year to 2022, I get the error {"error":{"message":"No stats found.","code":404}}
Might be a redirection issue. Try /nfl/seasons/2022/types/2/athletes/14876/statistics/0
FYI: here's the jq command to pretty print projections
curl -s 'https://sports.core.api.espn.com/v2/sports/football/leagues/nfl/seasons/2022/types/2/athletes/14876/statistics/0' |
jq '.splits.categories[] | { (.name): (.stats|map({name,value})|from_entries) }'
{
"general": {
"fumbles": 0,
"fumblesLost": 0,
"fumblesTouchdowns": 0,
"gamesPlayed": 2,
"offensiveTwoPtReturns": 0,
"offensiveFumblesTouchdowns": 0,
"defensiveFumblesTouchdowns": 0
}
}
{
"passing": {
"avgGain": 367.1610107421875,
"completionPct": 58.49100112915039,
"completions": 31,
"ESPNQBRating": 463,
"interceptionPct": 3.7739999294281006,
"interceptions": 2,
"longPassing": 31,
"netPassingYards": 367,
"netPassingYardsPerGame": 183.5,
"netTotalYards": 376,
"netYardsPerGame": 188,
"passingAttempts": 53,
"passingBigPlays": 7,
"passingFirstDowns": 19,
"passingFumbles": 0,
"passingFumblesLost": 0,
"passingTouchdownPct": 3.7739999294281006,
"passingTouchdowns": 2,
"passingYards": 383,
"passingYardsAfterCatch": 146,
"passingYardsAtCatch": 237,
"passingYardsPerGame": 191.5,
"QBRating": 77.7891616821289,
"sacks": 3,
"sackYardsLost": 16,
"teamGamesPlayed": 2,
"totalOffensivePlays": 59,
"totalPointsPerGame": 0,
"totalTouchdowns": 2,
"totalYards": 392,
"totalYardsFromScrimmage": 9,
"twoPointPassConvs": -1,
"twoPtPass": 0,
"twoPtPassAttempts": 0,
"yardsFromScrimmagePerGame": 4.5,
"yardsPerCompletion": 12.354999542236328,
"yardsPerGame": 196,
"yardsPerPassAttempt": 7.22599983215332,
"netYardsPerPassAttempt": 6.553571428571429,
"QBR": 43.27,
"adjQBR": 48.28,
"quarterbackRating": 77.7891616821289
}
}
{
"rushing": {
"avgGain": 367.1610107421875,
"ESPNRBRating": 9,
"longRushing": 9,
"netTotalYards": 376,
"netYardsPerGame": 188,
"rushingAttempts": 3,
"rushingBigPlays": 0,
"rushingFirstDowns": 2,
"rushingFumbles": 0,
"rushingFumblesLost": 0,
"rushingTouchdowns": 0,
"rushingYards": 9,
"rushingYardsPerGame": 4.5,
"stuffs": 1,
"stuffYardsLost": 2,
"teamGamesPlayed": 2,
"totalOffensivePlays": 59,
"totalPointsPerGame": 0,
"totalTouchdowns": 2,
"totalYards": 392,
"totalYardsFromScrimmage": 9,
"twoPointRushConvs": -1,
"twoPtRush": 0,
"twoPtRushAttempts": 0,
"yardsFromScrimmagePerGame": 4.5,
"yardsPerGame": 196,
"yardsPerRushAttempt": 3
}
}
{
"receiving": {
"avgGain": 367.1610107421875,
"ESPNWRRating": 0,
"longReception": 0,
"netTotalYards": 376,
"netYardsPerGame": 188,
"receivingBigPlays": 0,
"receivingFirstDowns": 0,
"receivingFumbles": 0,
"receivingFumblesLost": 0,
"receivingTargets": 0,
"receivingTouchdowns": 0,
"receivingYards": 0,
"receivingYardsAfterCatch": 0,
"receivingYardsAtCatch": 0,
"receivingYardsPerGame": 0,
"receptions": 0,
"teamGamesPlayed": 2,
"totalOffensivePlays": 59,
"totalPointsPerGame": 0,
"totalTouchdowns": 2,
"totalYards": 392,
"totalYardsFromScrimmage": 9,
"twoPointRecConvs": -1,
"twoPtReception": 0,
"twoPtReceptionAttempts": 0,
"yardsFromScrimmagePerGame": 4.5,
"yardsPerGame": 196,
"yardsPerReception": 0
}
}
{
"scoring": {
"defensivePoints": 0,
"fieldGoals": 0,
"kickExtraPoints": 0,
"miscPoints": 0,
"passingTouchdowns": 2,
"receivingTouchdowns": 0,
"returnTouchdowns": 0,
"rushingTouchdowns": 0,
"totalPoints": 0,
"totalPointsPerGame": 0,
"totalTouchdowns": 0,
"totalTwoPointConvs": 0,
"twoPointPassConvs": 0,
"twoPointRecConvs": 0,
"twoPointRushConvs": 0,
"onePtSafetiesMade": 0
}
}
Answered on Tue Sep 20 17:03:04 2022 — #4309442
a bit tedious but you can always get a team's defensive.yardsAllowed for every event and add it up yourself. (divide by number of games for perGameValue)
Answered on Tue Oct 4 21:24:39 2022 — #4324460
Answered on Tue Nov 15 15:24:37 2022 — #4370181
add active=true
to cut down the amount of atheltes
Answered on Tue Dec 20 07:13:52 2022 — #4408189
Anyone know how to get a team's schedule by teamId for regular season? The example below doesn't contain any events (games) because we are now in the offseason for some teams.
Example: https://site.api.espn.com/apis/site/v2/sports/football/nfl/teams/10/schedule
Change 2020 to the year you want https://sports.core.api.espn.com/v2/sports/football/leagues/nfl/seasons/2020/teams/2/events?lang=en®ion=us
Answered on Thu Jan 19 18:09:31 2023 — #4442752
https://sports.core.api.espn.com/v2/sports/football/leagues/nfl/seasons/2016/types/2/leaders
Replace 2016 with the year you want
Answered on Tue Feb 28 17:42:10 2023 — #4487163
API to get rating used in espn.com/nfl/fpi
- https://site.web.api.espn.com/apis/fitt/v3/sports/football/nfl/powerindex
- https://site.api.espn.com/apis/fitt/v3/sports/football/nfl/powerindex
Projected results are based on 10,000 simulations of the rest of the season using FPI, results to date, and the remaining schedule. Ratings and projections update daily.
curl -s 'https://site.web.api.espn.com/apis/fitt/v3/sports/football/nfl/powerindex' |
jq -r '.teams
| map({team:.team.name} + (.categories
| map({name,value:(if (.name == "projections") then .values[0:2] else .values[0] end)})
| from_entries))'
[
{ "team": "KC", "fpi": 13.587, "projections": [14, 3], "efficiencies": 68.068 },
{ "team": "PHI", "fpi": 12.731, "projections": [14, 3], "efficiencies": 70.515 },
{ "team": "CIN", "fpi": 11.106, "projections": [12, 4], "efficiencies": 67.391 },
{ "team": "BUF", "fpi": 9.139, "projections": [13, 3], "efficiencies": 73.166 },
{ "team": "DAL", "fpi": 8.367, "projections": [12, 5], "efficiencies": 63.21 },
{ "team": "SF", "fpi": 6.539, "projections": [13, 4], "efficiencies": 71.704 },
{ "team": "GB", "fpi": 6.304, "projections": [8, 9], "efficiencies": 46.629 },
{ "team": "JAX", "fpi": 6.083, "projections": [9, 8], "efficiencies": 52.63 },
{ "team": "MIA", "fpi": 5.246, "projections": [9, 8], "efficiencies": 50.027 },
{ "team": "LAC", "fpi": 3.24, "projections": [10, 7], "efficiencies": 51.099 },
{ "team": "BAL", "fpi": 2.927, "projections": [10, 7], "efficiencies": 56.388 },
{ "team": "PIT", "fpi": 2.234, "projections": [9, 8], "efficiencies": 46.937 },
{ "team": "NYG", "fpi": 2.052, "projections": [9, 7], "efficiencies": 49.769 },
{ "team": "DET", "fpi": 2.043, "projections": [9, 8], "efficiencies": 51.872 },
{ "team": "NE", "fpi": 1.964, "projections": [8, 9], "efficiencies": 50.247 },
{ "team": "MIN", "fpi": 1.65, "projections": [13, 4], "efficiencies": 50.247 },
{ "team": "NO", "fpi": 1.57, "projections": [7, 10], "efficiencies": 45.563 },
{ "team": "CAR", "fpi": 0.564, "projections": [7, 10], "efficiencies": 48.055 },
{ "team": "TEN", "fpi": -0.978, "projections": [7, 10], "efficiencies": 46.538 },
{ "team": "SEA", "fpi": -1.128, "projections": [9, 8], "efficiencies": 50.068 },
{ "team": "ATL", "fpi": -2.285, "projections": [7, 10], "efficiencies": 44.537 },
{ "team": "CLE", "fpi": -2.481, "projections": [7, 10], "efficiencies": 48.043 },
{ "team": "NYJ", "fpi": -3.169, "projections": [7, 10], "efficiencies": 43.457 },
{ "team": "WSH", "fpi": -4.748, "projections": [8, 8], "efficiencies": 45.71 },
{ "team": "DEN", "fpi": -5.155, "projections": [5, 12], "efficiencies": 42.459 },
{ "team": "HOU", "fpi": -5.5, "projections": [3, 13], "efficiencies": 32.317 },
{ "team": "LAR", "fpi": -6.479, "projections": [5, 12], "efficiencies": 37.693 },
{ "team": "TB", "fpi": -8.726, "projections": [8, 9], "efficiencies": 45.692 },
{ "team": "LV", "fpi": -9.59, "projections": [6, 11], "efficiencies": 46.569 },
{ "team": "ARI", "fpi": -15.1, "projections": [4, 13], "efficiencies": 37.772 },
{ "team": "IND", "fpi": -15.128, "projections": [4, 12], "efficiencies": 36.272 },
{ "team": "CHI", "fpi": -16.881, "projections": [3, 14], "efficiencies": 32.191 }
]
Answered on Wed May 10 07:04:09 2023 — #4563476
https://site.api.espn.com/apis/site/v2/sports/football/nfl/scoreboard?limit=300&dates=<YEAR1>0901-<YEAR2>0101
Try refreshing or changing the limit if you get a gateway error
Answered on Tue May 16 01:39:45 2023 — #4569221
Probably not what you're looking for but closer: http://sports.core.api.espn.com/v2/sports/football/leagues/nfl/calendar/whitelist
Answered on Tue May 23 18:36:44 2023 — #4577273
https://site.api.espn.com/apis/site/v2/sports/football/nfl/scoreboard?limit=1000&dates=2023
curl -o scoreboard.json 'https://site.api.espn.com/apis/site/v2/sports/football/nfl/scoreboard?limit=1000&dates=2023'
jq -r '.events
| map(. as $item
| .competitions[0].competitors
| map([
$item.id,$item.status.type.name,$item.date, $item.shortName,
.team.abbreviation,.homeAway,.score,.winner,
(((.linescores[]?).value) // ["--","--","--","--","--"] )
] | flatten | join(","))
)
| flatten
| join("\n")' scoreboard.json
401437933,STATUS_FINAL,2023-01-01T18:00Z,ARI @ ATL,ATL,home,20,true,0,14,0,6
401437933,STATUS_FINAL,2023-01-01T18:00Z,ARI @ ATL,ARI,away,19,false,3,10,3,3
401437935,STATUS_FINAL,2023-01-01T18:00Z,CHI @ DET,DET,home,41,true,7,17,14,3
401437935,STATUS_FINAL,2023-01-01T18:00Z,CHI @ DET,CHI,away,10,false,10,0,0,0
401437937,STATUS_FINAL,2023-01-01T18:00Z,DEN @ KC,KC,home,27,true,6,7,0,14
401437937,STATUS_FINAL,2023-01-01T18:00Z,DEN @ KC,DEN,away,24,false,0,10,7,7
401437938,STATUS_FINAL,2023-01-01T18:00Z,MIA @ NE,NE,home,23,true,7,0,9,7
401437938,STATUS_FINAL,2023-01-01T18:00Z,MIA @ NE,MIA,away,21,false,0,7,7,7
401437939,STATUS_FINAL,2023-01-01T18:00Z,IND @ NYG,NYG,home,38,true,0,24,7,7
401437939,STATUS_FINAL,2023-01-01T18:00Z,IND @ NYG,IND,away,10,false,3,0,7,0
401437940,STATUS_FINAL,2023-01-01T18:00Z,NO @ PHI,PHI,home,10,false,0,0,10,0
401437940,STATUS_FINAL,2023-01-01T18:00Z,NO @ PHI,NO,away,20,true,7,6,0,7
401437941,STATUS_FINAL,2023-01-01T18:00Z,CAR @ TB,TB,home,30,true,0,10,0,20
...
Answered on Tue Jun 13 04:58:04 2023 — #4597758