Have fun with the Astronomy Picture of the Day API

Have fun with the Astronomy Picture of the Day API

While I think telescopes are awesome, we can’t get as good a photo as NASA can. The really cool thing is that NASA has a photo of the day where each day is a different photo relating to space or something space related on Earth like how they have a great photo of Aurora Borealis.

Image Credit & Copyright: Alexandre Correia

Go to https://api.nasa.gov and enter your first name, last name, and email address and NASA will send you an API key. This is what you can use to interact with NASA’s Astronomy Picture of the Day also abbreviated to apod.

Then click on APOD: Astronomy Picture of the day.

You have different ways of using the API.

Parameter Type Default Description
date YYYY-MM-DD today The date of the APOD image to retrieve
start_date YYYY-MM-DD none The start of a date range, when requesting date for a range of dates. Cannot be used with date.
end_date YYYY-MM-DD today The end of the date range, when used with start_date.
count int none If this is specified then count randomly chosen images will be returned. Cannot be used with date or start_date and end_date.
thumbs bool False Return the URL of video thumbnail. If an APOD is not a video, this parameter is ignored.
api_key string DEMO_KEY api.nasa.gov key for expanded usage

https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY

The key here is used for accessing their api in a secure way because if it was a completely open api, people could abuse it tremendously. Here is where I will show using the parameters of the api so I can choose the image that was shown on 2022-03-18.

https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY&date=2022-03-18

This result is returned from the API. I could do something with the explanation and title if I wanted to, but I only care about the image for now.

{
    "copyright": "Giorgio Ferrari",
    "date": "2022-03-18",
    "explanation": "Bluish reflection nebulae seem to fill this dusty expanse. The sharp telescopic frame spans over 1 degree on the sky toward the faint but fanciful constellation Monoceros, the Unicorn. Seen within the Monoceros R1 cloud complex some 2,500 light-years away, bluish IC 447 is on the left, joined by a long dark filament of dust to IC 446 at lower right. Embedded in IC 447 are young, massive blue stars much hotter than the Sun, whose light is reflected by the cosmic cloud of star stuff. Observations reveal that IC 446 also contains a young stellar object, a massive star still in an early stage of evolution. The dark filament of dust and molecular gas joining the two star-forming regions is over 15 light-years long.",
    "hdurl": "https://apod.nasa.gov/apod/image/2203/IC447_446GiorgioFerrari.jpg",
    "media_type": "image",
    "service_version": "v1",
    "title": "A Filament in Monoceros",
    "url": "https://apod.nasa.gov/apod/image/2203/IC447_446GiorgioFerrari1024.jpg"
}

You can grab the HD image from hdurl or the regular image from url.

The image of the day for March 18th, 2022

Using https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY&date=2022-03-18, where you replace the DEMO_KEY with your actual key, you’ll see this image below when you grab the url png.

Beautiful Space

Space has some amazing things going on. Just remember that if you’re in a ship, try not to press the wrong button.

This is not a sponsored post, but there are affiliate links in this post which will earn me a small percentage of your purchase.