Skip to content
Nikhil Prasad edited this page May 25, 2024 · 3 revisions

Instructions for Using the NBA GraphQL API

  1. Access the GraphiQL Interface:

    • Open your web browser and go to https://nbaapi.com/graphql/.
    • This interface allows you to write and execute GraphQL queries against the NBA database.
  2. Basic Query Structure:

    • A GraphQL query consists of a query keyword followed by the specific data request enclosed in curly braces {}.

    • Example:

      query {
        playerTotals(name: "LeBron James") {
          playerName
          position
          season
          team
          games
          id
        }
      }
  3. Querying Player Totals:

    • To fetch player totals for a specific player:

      query {
        playerTotals(name: "LeBron James") {
          playerName
          position
          season
          team
          games
          id
        }
      }
    • This query returns the player name, position, season, team, games played, and database ID for every entry matching "LeBron James".

  4. Querying Players by Position and Ordering:

    • To fetch players by position and order them by a specific stat:

      query {
        playerTotals(position: "C", ordering: "-total_rb") {
          playerName
          totalRb
          team
          season
        }
      }
    • This returns players in the Center position, ordered by total rebounds in descending order.

  5. Advanced Player Stats:

    • To fetch advanced stats for players from a specific team and season:

      query {
        playerAdvanced(team: "HOU", season: 2019, position: "PG", ordering: "-win_shares") {
          playerName
          position
          team
          season
          winShares
        }
      }
    • This returns Point Guards from the Houston Rockets in the 2019 season, ordered by win shares in descending order.

  6. Querying Specific Player's Advanced Stats:

    • For detailed advanced stats for a specific player:

      query {
        playerAdvanced(name: "Kobe Bryant") {
          playerName
          age
          assistPercent
          blockPercent
          defensiveWs
          offensiveWs
          winShares
          per
          vorp
        }
      }
    • This returns all available advanced stats for Kobe Bryant.

  7. Using Filters and Ordering:

    • Filters: You can filter data by name, season, team, position, playerID, and id.

    • Ordering: Use the ordering parameter to sort results. Prefix the category with a - for descending order.

    • Example:

      query {
        playerTotals(team: "LAL", ordering: "-points") {
          playerName
          points
        }
      }
  8. Explore the Schema:

    • Use the GraphiQL interface's built-in documentation explorer to understand the available types, queries, and fields.
    • This helps in constructing more complex and precise queries.

By following these steps, you can effectively use the NBA GraphQL API to retrieve various player statistics and perform data analysis.

Clone this wiki locally