How to call an API using the Power Automate HTTP action
- Ajith Madathil
- Nov 2, 2019
- 1 min read
Updated: Apr 1, 2020
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.
References:
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:
last(split(body(‘Parse_JSON_Results’)?[‘url’],’/’))

Finally, we have all the necessary attributes to create the file in SharePoint.

Here is the final preview of the flow.

Recent Posts
See AllMicrosoft Power Automate (aka Microsoft Flow) provides lots of action steps out of the box. My favourite one is Compose. What does it do?...
I have a SharePoint document library called aj, and inside of it, three folders (Test1, Test2 & Test3). I am going to build a flow to...
Every flow needs a trigger to start with so here I am using a manual trigger. Next, I am using the action List Folder which returns files...
Comments