How to call an API using the Power Automate HTTP action
Updated: Apr 1
In this blog post I will access NASA's Astronomy Picture of the Day (APOD) API using Power Automate. The plan is to retrieve the picture of the day using the API and store it in a SharePoint document library.
NASA API Website https://api.nasa.gov/
API Method: https://api.nasa.gov/planetary/apod. Below are the related query parameters for the APOD API Get method.
To generate an API Key you can follow the instructions on the website (https://api.nasa.gov/). Once we have the key we can start to build the Flow. Here I am using a scheduled trigger which will run every day.
Next, we use the HTTP flow step. Enter the api_key that you received as part of the NASA API registration process. You can also extend the query using the date and hd parameters (though they are optional).
The API call will return a JSON response, which we can parse using the Parse JSON Results action.
A sample of the JSON schema is as follows:
Inside that JSON is an hdurl attribute that contains a URL of another endpoint that we can call.
To get the image content I now use another HTTP flow method and pass in the hdurl property.
Now I can use a Compose action to grab the filename of the image from the JSON. The expression to use is:
Finally, we have all the necessary attributes to create the file in SharePoint.
Here is the final preview of the flow.