Skip to content

Data Types: Attendance

KCNilssen edited this page Dec 13, 2022 · 15 revisions

Usage that returns Attendance objects

get_attendance

Description: Returns attendance data based on teamId, leagueId, or leagueListId. Required Parameters (at least one)

Parameters: At least one is required

Name Type Required Description Default
team_id Int Yes Insert a teamId to return directory of attendnace for a given team None
league_id Int/List[int] Yes Insert leagueId(s) to return a directory of attendanace for a specific league. Format '103,104' None
league_list_id Str Yes Insert a unique League List Identifier to return a directory of attendanace for a specific league listId. List of Options None

Other Parameters:

Name Type Required Description Default
season int No Insert year(s) to return a directory of attendance for a given season. Season year number format yyyy None
date string No Insert date to return information for attendance on a particular date. Format: MM/DD/YYYY None
gametype string No Insert gameType(s) a directory of attendance for a given gameType. For a list of all gameTypes: https://statsapi.mlb.com/api/v1/gameTypes None

Attendance Structure

Objects in description are expandable and collapsable
aggregatetotals : AttendanceTotals
openingstotalaway : int
  • Total amount of opening game attendance number
openingstotalhome : int
  • Total amount of opening home game attendance number
openingstotallost : int
  • Total amount of opening games lost
openingstotalytd : int
  • Total amount of opening games year to date
attendanceaverageaway : int
  • Average away game attendance
attendanceaveragehome : int
  • Average home game attendance
attendanceaverageytd : int
  • Average attendance year to date
attendancehigh : int
  • Attendance high
attendancehighdate : str
  • Attendance high date
attendancetotal : int
  • Attendance total
attendancetotalaway : int
  • Attendace total away
attendancetotalhome : int
  • Attendance total home
records : List[AttendanceRecords]
openingstotal : int
  • Total amount of openings
openingstotalaway : int
  • Total amount of opening away games
openingstotalhome : int
  • Total amount of opening home games
openingstotallost : int
  • Total amount of openings lost
gamestotal : int
  • Total amount of games
gamesawaytotal : int
  • Total amount of away games
gameshometotal : int
  • Total amount of home games
year : str
  • Year as a string
attendanceaverageaway : int
  • Average attendance for away games
attendanceaveragehome : int
  • Average attendance for home games
attendanceaverageytd : int
  • Average attendance year to date
attendancehigh : int
  • Attendance High number
attendancehighdate : str
  • Attendance high date
attendancehighgame : AttendanceHighLowGame
gamepk : int
  • Games Id number
link : str
  • games endpoint link
content : AttendanceHighLowGameContent
link : str
  • games content endpoint link
daynight : str
  • Type of time of day for game
attendancelow : int
  • Attendance low number
attendancelowdate : str
  • Attendance low date
attendancelowgame : AttendanceHighLowGame
gamepk : int
  • Games Id number
link : str
  • games endpoint link
content : AttendanceHighLowGameContent
link : str
  • games content endpoint link
daynight : str
  • Type of time of day for game
attendanceopeningaverage : int
  • Attendance opening average
attendancetotal : int
  • Attendance total
attendancetotalaway : int
  • Attendance total away
attendancetotalhome : int
  • Attendance total home
gametype : AttendenceGameType
id : str
  • Game type id
description : str
  • Game type description
team : Team
  • Team

Example output from MLB stats api endpoint

Mlb stats api Query:

https://statsapi.mlb.com/api/v1/attendance?teamId=110&leagueId=103&season=2014&leagueListId=mlb&gameType=D

Equivelant with python-mlb-statsapi:

import mlbstatsapi

mlb = mlbstatsapi.Mlb()

mlb.get_attendance(team_id = 110, league_id = 103, league_list_id = 'mlb', gameType = 'd', season = 2014)

Json returned from mlb stats api

{
    "copyright": "Copyright 2022 MLB Advanced Media, L.P. Use of any content on this page acknowledges agreement to the
terms posted here http: //gdx.mlb.com/components/copyright.txt",
    "records": [
        {
            "openingsTotal": 3,
            "openingsTotalAway": 1,
            "openingsTotalHome": 2,
            "openingsTotalLost": 0,
            "gamesTotal": 3,
            "gamesAwayTotal": 1,
            "gamesHomeTotal": 2,
            "year": "2014",
            "attendanceAverageAway": 43013,
            "attendanceAverageHome": 47950,
            "attendanceAverageYtd": 46304,
            "attendanceHigh": 48058,
            "attendanceHighDate": "2014-10-03T00:00:00",
            "attendanceHighGame": {
                "gamePk": 416350,
                "link": "/api/v1.1/game/416350/feed/live",
                "content": {
                    "link": "/api/v1/game/416350/content"
                },
                "dayNight": "day"
            },
            "attendanceLow": 47842,
            "attendanceLowDate": "2014-10-02T00:00:00",
            "attendanceLowGame": {
                "gamePk": 416348,
                "link": "/api/v1.1/game/416348/feed/live",
                "content": {
                    "link": "/api/v1/game/416348/content"
                },
                "dayNight": "day"
            },
            "attendanceOpeningAverage": 47950,
            "attendanceTotal": 138913,
            "attendanceTotalAway": 43013,
            "attendanceTotalHome": 95900,
            "gameType": {
                "id": "D",
                "description": "Division Series"
            },
            "team": {
                "id": 110,
                "name": "Baltimore Orioles",
                "link": "/api/v1/teams/110"
            }
        }
    ],
    "aggregateTotals": {
        "openingsTotalAway": 1,
        "openingsTotalHome": 2,
        "openingsTotalLost": 0,
        "openingsTotalYtd": 0,
        "attendanceAverageAway": 43013,
        "attendanceAverageHome": 47950,
        "attendanceAverageYtd": 46304,
        "attendanceHigh": 48058,
        "attendanceHighDate": "2014-10-03T00:00:00",
        "attendanceTotal": 138913,
        "attendanceTotalAway": 43013,
        "attendanceTotalHome": 95900
    }
}
Clone this wiki locally