0

I'm using requests to pull in NBA player stats from the ESPN Fantasy API. Downstream I'm building a pandas df. One thing I'm having trouble with is filtering the request for fields that are deeper in the JSON nesting. I'm able to filter status and sort by PercOwned in my header, but I can't seem to filter for items like statSplitTypeId or auctionValue. Any thoughts?

url: https://fantasy.espn.com/apis/v3/games/fba/seasons/2022/segments/0/leagues/1747675438?view=kona_player_info

current headers:

headers = {
  'X-Fantasy-Filter': '{"players":\
      {"filterStatus":{"value":["FREEAGENT","WAIVERS","ONTEAM"]},\
          "sortPercOwned":{"sortAsc":false,"sortPriority":1}}}'
}

Example JSON response

{
    "players": [
        {
            "draftAuctionValue": 0,
            "id": 3032977,
            "keeperValue": 1,
            "keeperValueFuture": 1,
            "lineupLocked": false,
            "onTeamId": 4,
            "player": {
                "active": true,
                "defaultPositionId": 4,
                "draftRanksByRankType": {
                    "STANDARD": {
                        "auctionValue": 64,
                        "published": false,
                        "rank": 2,
                        "rankSourceId": 0,
                        "rankType": "STANDARD",
                        "slotId": 0
                    }
                },
                "droppable": false,
                "eligibleSlots": [
                    3,
                    6,
                    8,
                    9,
                    10,
                    11,
                    12,
                    13
                ],
                "firstName": "Giannis",
                "fullName": "Giannis Antetokounmpo",
                "ownership": {
                    "activityLevel": null,
                    "auctionValueAverage": 64.22289156626506,
                    "auctionValueAverageChange": -2.9199655765920767,
                    "averageDraftPosition": 2.6674573758339513,
                    "averageDraftPositionPercentChange": -0.6431361088656256,
                    "date": 1637244022069,
                    "leagueType": 0,
                    "percentChange": -0.006086844650013745,
                    "percentOwned": 99.95081910133877,
                    "percentStarted": 85.24790654758796
                },
            },
            "rosterLocked": true,
            "status": "ONTEAM",
            "tradeLocked": false```

1 Answers1

0

You can filter on statSplits with "filterStatsForSplitTypeIds":{"value":[1]} and just add in the id into the value list. I couldn't work out though what id corresponds to what split.

As far as the auctionValue, I couldn't find that being implimented in any of the requests to the api.

import requests


headers = {
  'X-Fantasy-Filter': '{"players":\
      {"filterStatus":{"value":["FREEAGENT","WAIVERS","ONTEAM"]},\
       "filterStatsForSplitTypeIds":{"value":[0,1,2]},\
          "sortPercOwned":{"sortAsc":false,"sortPriority":1}}}'
}

url = 'https://fantasy.espn.com/apis/v3/games/fba/seasons/2022/segments/0/leagues/1747675438?view=kona_player_info'
jsonData = requests.get(url, headers=headers).json()
chitown88
  • 27,527
  • 4
  • 30
  • 59