Problem with fetching data from API?

javascript

#1

Hello,
So, I’m having a problem with using this npm package on glitch. It doesn’t seem to be fetching the data from the API? Not really sure. I’ve tried so many different things to get this working. The frustrating thing is that this exact package/code runs perfectly on my local machine. Does Glitch allow fetching data from an API? I’ve been stuck on this for a good while.

My error:
SyntaxError: Unexpected token Y in JSON at position 0 at JSON.parse (<anonymous>) at module.exports (/rbd/pnpm-volume/eedb8dbd-5572-4b54-b9a9-37f61d7f583c/node_modules/.registry.npmjs.org/skiplagged-api-wrapper/1.0.0/node_modules/skiplagged-api-wrapper/index.js:30:27) at process._tickCallback (internal/process/next_tick.js:68:7)

The code at index.js:30:27 of the skiplagged-api-wrapper:
const flightData = JSON.parse(await get({ host, path: flightUrl }));

Glitch Project


#2

Hi @bryceremick, welcome to the Glitch forum!

There shouldn’t be any reason you would have difficulty retrieving data from an external API, so I’m not sure what the difference is, but when I load https://skiplagged.com/api/search.php?from=LAX&to=JFK&depart=2019-03-25&sort=cost in my browser I get what seems to be a sane result set, but when I run curl https://skiplagged.com/api/search.php?from=LAX&to=JFK&depart=2019-03-25&sort=cost from a Glitch console I get a different, suspect result.I’m going to have to take a closer look at this.


#3

Thank you! This has been baffling me for a while now!


#5

Hey @bryceremick, I think what’s happening here is that your project on Glitch is being rate-limited by skiplagged.com; after a few repeated calls I see this in the output from curl: You are being watched. This is illegal behavior and will not be tolerated. We keep detailed logs of everything and will be reporting this to the FBI. If you would like mercy, email support@skiplagged.com and apologize asap. If you note, that output begins with the letter “Y” as noted in your error message. It seems like the wrapper you’re using is a little fragile around assuming that the output from the API will always be JSON.

I’m reaching out to their support with respect to Glitch generally, but it might be worth you asking them if there’s something your project should be doing specifically to avoid this result.


#6

This post was flagged by the community and is temporarily hidden.