VaccineAvailabilityNotifier icon indicating copy to clipboard operation
VaccineAvailabilityNotifier copied to clipboard

Axios(config) is throwing Error.

Open pranshukas opened this issue 3 years ago • 1 comments

the Axios Config is not working it's throwing Error!

function getSlotsForDate(DATE) {
    let config = {
        method: 'get',
        url: 'https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByPin?pincode=' + '201310' +'&date=' + DATE,
        headers: {
            'accept': 'application/json',
        }
    };

    axios(config)
        .then(function (slots) {
            let sessions = slots.data.sessions;
            let validSlots = sessions.filter(slot => slot.min_age_limit <= AGE && slot.available_capacity > 0)
            console.log({ date: DATE, validSlots: validSlots.length })
            if (validSlots.length > 0) {
                notifyMe(validSlots);
            }
        })
        .catch(function (error) {
            console.log(error);
        });
}

I tried running this function but it's throwing an error.

image

Can Anyone please suggest us why this is happening or how else can we implement the same thing. I also tried using the request package which is getting executed perfectly but I am not able to get sessions from it. it's showing .filter is not function.


   var options = {
      'method': 'GET',
      'url': 'https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByPin?pincode=' + '201301' + '&date=' + DATE,
       headers': {
         'Accept-Language': 'en_US'
       }
    };
      request(options, function (error, response) {
      if (error) {
          throw new Error(error);
      }
      let slots = JSON.parse(response.body);
      console.log(slots.centers.length);  
      let sessions = slots.data.sessions;
      let validSlots = sessions.filter(slot => slot.min_age_limit <= AGE && slot.available_capacity > 0)
      console.log({ date: DATE, validSlots: validSlots.length }) 
    });

pranshukas avatar May 14 '21 19:05 pranshukas

Problem is in the api errors 403 means it is not able to authorize I tried displaying api through axios it is showing same error

saymedgm avatar May 22 '21 05:05 saymedgm