Skip to main content

Overview

The bulk matchups endpoint efficiently fetches head-to-head matchup information for multiple weeks of your Yahoo Fantasy Basketball league in a single API call. This is ideal for displaying season schedules, analyzing strength of schedule, or building matchup calendars.

Authentication

Requires an active user session with a selected league.

Request

weeks
string
default:"1-5"
Specifies which weeks to retrieve matchup data for. Accepts two formats:
  • Range format: "1-5" - Retrieves weeks 1 through 5 (inclusive)
  • Comma-separated: "13,14,15" - Retrieves specific weeks 13, 14, and 15
Defaults to "1-5" if not provided.

Response

fantasy_content
object
The root object containing all matchup data from Yahoo Fantasy API

Error Responses

error
string
Error message describing what went wrong
yahoo_status_code
integer
HTTP status code returned by Yahoo API (included for Yahoo API errors)

Possible Errors

  • 401 Unauthorized - User not authenticated or session expired
    {"error": "User not authenticated or session expired."}
    
  • 400 Bad Request - No league selected
    {"error": "No league selected. Please select a league first."}
    
  • Yahoo API Errors - Passes through Yahoo’s error messages with status code
    {
      "error": "Yahoo error description",
      "yahoo_status_code": 404
    }
    
  • 500 Internal Server Error - Unexpected error
    {"error": "Error details"}
    

Example Requests

curl -X GET "https://your-domain.com/api/bulk_matchups?weeks=1-5" \
  -H "Cookie: session=your-session-cookie"

Example Response

{
  "fantasy_content": {
    "league": [
      {
        "league_key": "423.l.12345",
        "name": "My League",
        "season": "2024"
      },
      {
        "teams": {
          "count": 10,
          "0": {
            "team": [
              [
                {
                  "team_key": "423.l.12345.t.1",
                  "name": "Thunder Squad"
                }
              ],
              {
                "matchups": {
                  "count": 5,
                  "0": {
                    "matchup": {
                      "week": "1",
                      "teams": {
                        "0": {"team": [{"team_key": "423.l.12345.t.1"}]},
                        "1": {"team": [{"team_key": "423.l.12345.t.2"}]}
                      }
                    }
                  }
                }
              }
            ]
          }
        }
      }
    ]
  }
}

Implementation Details

This endpoint is implemented in main.py:934-968 and performs the following:
  1. Validates user authentication (checks for active session token)
  2. Validates league selection (checks for league_key in session)
  3. Retrieves the weeks parameter from query string (defaults to "1-5")
  4. Constructs the Yahoo API path: fantasy/v2/league/{league_key}/teams;out=matchups;weeks={weeks}
  5. Calls the Yahoo Fantasy API via the yahoo_api() helper function
  6. Returns the complete Yahoo API response as JSON
  7. Handles errors with detailed logging and appropriate HTTP status codes

Error Handling

The endpoint includes sophisticated error handling:
  • HTTP errors from Yahoo: Extracts error description from Yahoo’s JSON response when available
  • Network errors: Returns 500 with exception details
  • Logging: All requests and errors are logged with request parameters for debugging

Yahoo API Format

The endpoint passes the weeks parameter directly to Yahoo’s API, which supports:
  • Range syntax: weeks=1-5 fetches weeks 1, 2, 3, 4, 5
  • List syntax: weeks=13,14,15 fetches only weeks 13, 14, 15
  • Mixed syntax: While not tested, Yahoo may support weeks=1-3,5,7-9

Use Cases

  • Build complete season matchup calendars
  • Display remaining schedule for each team
  • Analyze strength of schedule (who plays who when)
  • Identify playoff matchup opponents in advance
  • Calculate potential tiebreaker scenarios
  • Show head-to-head records between specific teams
  • Plan roster moves based on upcoming opponent strength

Performance Considerations

  • This endpoint fetches data for all teams in the league for the specified weeks
  • Requesting many weeks (e.g., 1-24) returns significantly more data than a single week
  • Consider requesting only the weeks you need to minimize response size
  • Yahoo API rate limits apply; avoid excessive requests
  • Response parsing may take longer for large week ranges in large leagues

Notes

  • Week numbers must be valid for the current season (typically 1-24 for NBA fantasy)
  • Invalid week numbers may cause Yahoo API errors
  • Playoff weeks are included in the range if specified
  • Bye weeks (if any) will show no matchup or special matchup status
  • The response structure is complex due to Yahoo’s nested array/object format
  • Scoreboard - Get detailed results for a single week’s matchups
  • Season Averages - Compare team performance across the season

Build docs developers (and LLMs) love