reactjsnext.js

How can I fetch football leagues by date using the football API?


I am trying to use the football API to fetch a list of football leagues based on a specific date. I want to display this information in my Next.js application, but I am not sure how to properly make the API call.

I have tried using the provided endpoint 'https://football.sportdevs.com/leagues-by-date?date=eq.{date}' with the desired date parameter, but I am not getting the expected data back. I expected to receive a list of football leagues for the specified date.

const date = '2022-01-01';
fetch(`https://football.sportdevs.com/leagues-by-date?date=eq.${date}`)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error));

Solution

  • You are missing an API key; without an API key, you can't test api results For this, you should follow these steps:

    1. Go to this URL: https://sportdevs.com/pricing
    2. choose your sports and subscribe to a paid or free option
    3. Sign up with email or gmail account
    4. get api key from dashboard

    If you test the API key with code, it will work perfectly

    var myHeaders = new Headers();
    myHeaders.append("Accept", "application/json");
    myHeaders.append("Authorization", "Bearer your_api_key");
    
    var requestOptions = {
      method: 'GET',
      headers: myHeaders,
      redirect: 'follow'
    };
    
    fetch("https://football.sportdevs.com/leagues-by-date?date=eq.2022-01-01", requestOptions)
      .then(response => response.text())
      .then(result => console.log(result))
      .catch(error => console.log('error', error));