bttmly / nba

Node.js client for nba.com API endpoints

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting 400 Bad Request despite supplying required parameters

Quas94 opened this issue · comments

Hi, I just discovered this package and am trying to use it without much success:

My short script:

const NBA = require('nba');

NBA.stats.scoreboard({GameDate: '03/19/2017'}).then((data) => {
  console.log('data = ' + JSON.stringify(data));
}).catch((err) => {
  console.log('Error: ' + err);
});

Produces the following error:

$ npm start

> nba-test@1.0.0 start c:\Users\Quasar\Desktop\nba-test
> node index.js

Error: Error: 400 Bad Request - GameDate is required

I looked in the tests and made sure that I was inputting the GameDate parameter correctly, and am still receiving this error. Please help!

Thanks

Change GameDate (capitalized first character) to gameDate (lowercase first character) and it should work. Nearly all the parameters have a capitalized first letter but gameDate is an exception. There is a note next to the test case for stats.scoreboard pointing this out: https://github.com/nickb1080/nba/blob/master/test/integration/stats.js#L59

that's an unfortunate error message 😞

Yeah agreed... but I'm hesitant to special-case that one error message. The documentation for that method has the correct parameters FWIW.

it's just so strange that it's seemingly the only parameter that doesn't start with a capital letter. (i know it's not you - it's this unofficial API)

what if there were a special case to accept GameDate in NBA.stats.scoreboard?

Well, the issue is that the NBA.stats namespace methods are generated dynamically from a JSON template. I'd like to keep this a thin-as-possible wrapper over the bare HTTP API -- which is exactly why I dropped translating request parameters from javascriptStyle to NbaStyle.