title: Scraping NBA data in R with rjson
body: <p>I have been spending a long time using R to try to scrape NBA data, so far I was doing it a little by trial and error, but finally I found this <a href="https://github.com/seemethere/nba_py/wiki/stats.nba.com-Endpoint-Documentation" rel="noreferrer">documentation</a>. Some time ago I had some problems scraping the <em>shotchartdetail</em>, and I figured out the problem when I found <a href="https://www.reddit.com/r/nba/comments/5iu7jb/did_statsnbacoms_shotchartdetail_json_no_longer/" rel="noreferrer">this</a></p>
  
  <h2>This works</h2>
  
  <p>For that this is what I did:</p>
  
  <pre><code>shotURLtotal &lt;- paste0("http://stats.nba.com/stats/shotchartdetail?CFID=33&amp;CFPARAMS=2016-17&amp;ContextFilter=&amp;ContextMeasure=FGA&amp;DateFrom=&amp;DateTo=&amp;GameID=&amp;GameSegment=&amp;LastNGames=0&amp;LeagueID=00&amp;Location=&amp;MeasureType=Base&amp;Month=0&amp;OpponentTeamID=0&amp;Outcome=&amp;PaceAdjust=N&amp;PerMode=PerGame&amp;Period=0&amp;PlayerID=0&amp;PlusMinus=N&amp;Position=&amp;Rank=N&amp;RookieYear=&amp;Season=2016-17&amp;SeasonSegment=&amp;SeasonType=Regular+Season&amp;TeamID=0&amp;VsConference=&amp;VsDivision=&amp;mode=Advanced&amp;showDetails=0&amp;showShots=1&amp;showZones=0&amp;PlayerPosition=")
  
  Season &lt;- rjson::fromJSON(file = shotURLtotal, method="C")
  Names &lt;- Season$resultSets[[1]][[2]]
  
  Season &lt;- data.frame(matrix(unlist(Season$resultSets[[1]][[3]]), ncol = length(Names), byrow = TRUE))
  
  colnames(Season) &lt;- Names
  </code></pre>
  
  <h2>But this does not</h2>
  
  <p>but when I try to do the same with the <em>shotchartlineupdetail</em>, and it does not work, I suspect it has to do with the <strong>CFID</strong>, which I don't know what it means, this is what I tried.</p>
  
  <pre><code>shoturl &lt;- "http://stats.nba.com/stats/shotchartlineupdetail/?leagueId=00&amp;season=2016-17&amp;seasonType=Regular+Season&amp;teamId=0&amp;outcome=&amp;location=&amp;month=0&amp;seasonSegment=&amp;dateFrom=&amp;dateTo=&amp;opponentTeamId=0&amp;vsConference=&amp;vsDivision=&amp;gameSegment=&amp;period=0&amp;lastNGames=0&amp;gameId=&amp;group_id=0&amp;contextFilter=&amp;contextMeasure=FGA"
  
  
  Season &lt;- rjson::fromJSON(file = shoturl, method="C")
  Names &lt;- Season$resultSets[[1]][[2]]
  
  Season &lt;- data.frame(matrix(unlist(Season$resultSets[[1]][[3]]), ncol = length(Names), byrow = TRUE))
  
  colnames(Season) &lt;- Names
  </code></pre>
  
  <h2>Expected Results</h2>
  
  <p>The expected result should be a dataframe with the following columns:</p>
  
  <pre><code>c("GRID_TYPE", "GAME_ID", "GAME_EVENT_ID", "GROUP_ID", "GROUP_NAME", "PLAYER_ID", "PLAYER_NAME", "TEAM_ID", "TEAM_NAME", "PERIOD", "MINUTES_REMAINING", "SECONDS_REMAINING", "EVENT_TYPE", "ACTION_TYPE", "SHOT_TYPE", "SHOT_ZONE_BASIC", "SHOT_ZONE_AREA", "SHOT_ZONE_RANGE", "SHOT_DISTANCE", "LOC_X", "LOC_Y", "SHOT_ATTEMPTED_FLAG", "SHOT_MADE_FLAG", "GAME_DATE", "HTM", "VTM")
  </code></pre>
  
  <p>which you can get by doing:</p>
  
  <pre><code>shoturl &lt;- "http://stats.nba.com/stats/shotchartlineupdetail/?leagueId=00&amp;season=2016-17&amp;seasonType=Regular+Season&amp;teamId=0&amp;outcome=&amp;location=&amp;month=0&amp;seasonSegment=&amp;dateFrom=&amp;dateTo=&amp;opponentTeamId=0&amp;vsConference=&amp;vsDivision=&amp;gameSegment=&amp;period=0&amp;lastNGames=0&amp;gameId=&amp;group_id=0&amp;contextFilter=&amp;contextMeasure=FGA"
  
  
  Season &lt;- rjson::fromJSON(file = shoturl, method="C")
  Names &lt;- Season$resultSets[[1]][[2]]
  </code></pre>
  
  <p>So Names would be the columns of the dataframe, the problem is that by not using the <strong>CFID</strong> you get that the list where the data for those columns should be are empty, the answer that @be_green gives are the league average, and I need the team specific data</p>