Why NASA APOD Api stopped to work suddenly?

444 views Asked by At

Since some days ago NASA APOD API (https://api.nasa.gov/) stopped to work suddenly.

Here is a sample link (with demo key): https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY

Some questions for who is using this API:

  • Do you know the reason why this API doesn't work?
  • Is there an alternative URL (or way) for getting this data?

Please give me an answer, because I need this data for my projects.

Thank you

I don't know how to solve; I thought an html parser for the original site, but it looks so complicated (and I don't want to have dirty data in my projects).

1

There are 1 answers

1
LarryTLlama On

Perhaps the API has simply just gone down? It appears the same here, with a HTTP 504 Gateway Timeout error. There isn't a lot you can do until it comes back online, which it should hopefully in a few days.

The non-developer page still is working at the APOD website, with the archive found here. A HTML Parser would work, however I would highly recommend against requesting to these pages as they haven't been designed for doing so. They can change without notice which may render your HTML Parser useless when they do change. As a temporary fix, this may be possible, but not a good idea.

If you wish to create an HTML parser with that website, you could use something like this, using the fetch api. This may conflict with other img elements, but since you haven't provided any code, here would be my implementation of it

// Use promises with async 
async function getAPOD() {
    // Fetch and convert to text
    let res = await fetch("https://apod.nasa.gov/apod/astropix.html");
    let html = await res.text();
    console.log(html)
    // Set the text as HTML.
    document.getElementById("hidden").innerHTML = html;
    // Grab the <img>'s src from the HTML
    let img = document.querySelector("img").src;
    console.log(src)
    // Create a new IMG element in the container
    document.getElementById("container").createElement("img").src = img;
}

getAPOD();
#hidden {
  display: none;
}
<div id="container">

</div>

<div id="hidden">

</div>
Again, would definitely not use this in production code.

A good option may be hosting your own. You can use the tutorial on the apod-api Github site.

If you're unable to host your own, unfortunately the best thing to do is just to wait it out. Sorry!