Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using getSchedule() function will get problem #19

Open
j28302830 opened this issue May 4, 2023 · 3 comments
Open

Using getSchedule() function will get problem #19

j28302830 opened this issue May 4, 2023 · 3 comments

Comments

@j28302830
Copy link

j28302830 commented May 4, 2023

My code:
'''
const MLBStatsAPI = require('mlb-stats-api');
const mlbStats = new MLBStatsAPI();

async function data() {
const response = await mlbStats.getSchedule({});
const data = await response.json();
return data;
}

async function main() {
try {
const scores = await data();
console.log(scores);
} catch (error) {
console.error(error + "error");
}
}

main();
'''
will get the result below:
{
messageNumber: 7,
message: 'Missing required parameter sportId or gamePk',
timestamp: '2023-05-04T08:02:25.845395735Z',
traceId: null
}

@Iliannnn
Copy link
Contributor

To resolve the issue, you should use either the sportId or gamePk parameter in the getSchedule() function. Here's how you can do it:

  1. Using sportId:
const MLBStatsAPI = require('mlb-stats-api');
const mlbStats = new MLBStatsAPI();

async function data() {
  const response = await mlbStats.getSchedule({ params: { sportId: <your_sportId_here> }});
  const data = await response.json();
  return data;
}

async function main() {
  try {
    const scores = await data();
    console.log(scores);
  } catch (error) {
    console.error(error + "error");
  }
}

main();

Use 1 as sportId to get the schedule for MLB.

  1. Using gamePk:
const MLBStatsAPI = require('mlb-stats-api');
const mlbStats = new MLBStatsAPI();

async function data() {
  const response = await mlbStats.getSchedule({ params: { gamePk: <your_gamePk_here> }});
  const data = await response.json();
  return data;
}

async function main() {
  try {
    const scores = await data();
    console.log(scores);
  } catch (error) {
    console.error(error + "error");
  }
}

main();

The gamePk refers to a specific game's unique identifier.

Please note that you need to replace <your_sportId_here> and <your_gamePk_here> with the desired sportId or gamePk you want to retrieve the schedule for.

@j28302830
Copy link
Author

j28302830 commented Aug 14, 2023

To resolve the issue, you should use either the sportId or gamePk parameter in the getSchedule() function. Here's how you can do it:

1. Using sportId:
const MLBStatsAPI = require('mlb-stats-api');
const mlbStats = new MLBStatsAPI();

async function data() {
  const response = await mlbStats.getSchedule({ params: { sportId: <your_sportId_here> }});
  const data = await response.json();
  return data;
}

async function main() {
  try {
    const scores = await data();
    console.log(scores);
  } catch (error) {
    console.error(error + "error");
  }
}

main();

Use 1 as sportId to get the schedule for MLB.

2. Using gamePk:
const MLBStatsAPI = require('mlb-stats-api');
const mlbStats = new MLBStatsAPI();

async function data() {
  const response = await mlbStats.getSchedule({ params: { gamePk: <your_gamePk_here> }});
  const data = await response.json();
  return data;
}

async function main() {
  try {
    const scores = await data();
    console.log(scores);
  } catch (error) {
    console.error(error + "error");
  }
}

main();

The gamePk refers to a specific game's unique identifier.

Please note that you need to replace <your_sportId_here> and <your_gamePk_here> with the desired sportId or gamePk you want to retrieve the schedule for.

I change my code to the below
but still have same problem

const MLBStatsAPI = require('./mlb-stats-api');
const mlbStats = new MLBStatsAPI();

async function data() {
  const response = await mlbStats.getSchedule({ params: { sportId: 1 }});
  const data = await response.json();
  return data;
}

async function main() {
  try {
    const scores = await data();
    console.log(scores);
  } catch (error) {
    console.error(error + "error");
  }
}

main();

@struckm
Copy link

struckm commented Sep 1, 2023

There is a flaw in some of the functions in how they extract the params to add them to the URL, some of the functions do work, but the construction of the URL's is not consistent. I forked the repo and I'm in the process of cleaning up the functions to use the URL object and the searchParams property to dynamically construct the querystring passed to the fetch call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants