I am learning how to use the fetch() API in JavaScript. Right now i am trying to convert some code i have that is using curl to request data from an external API (aviationstack.com) in my php, and replace it by AJAX calls. I am using their free plan, which doesn't support https, and hence i am trying to fetch from their API using a http URL :
fetch('http://api.aviationstack.com/v1/flights?access_key=myaccesskey').then(function(response)
{
//some stuff here
});
This same url works fine with curl in my php code. Issue is the API seems to receive this call as https, since it returns me this json :
{"error":{"code":"https_access_restricted","message":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."}}
Does anyone know what could cause this ? I'm scratching my head over it, and i can't get it to work. Any help would be greatly appreciated, as i don't fully understand this process and i would be glad to get a better understanding of it.
EDIT : It seems i am truly an idiot. This was a network issue all along... Thanks for the answers, much appreciated
Tried the same using my API key (on my local machine) :
fetch('http://api.aviationstack.com/v1/flights?access_key=<MY API KEY>').then(function(response)
{
console.log(response);
});
The console gives the desired response and I get 200 as status. Maybe you should check the API key.
Can you check/provide the Request URL?