• Ajith Madathil

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.


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.



185 views

Recent Posts

See All

The Compose action

Microsoft Power Automate (aka Microsoft Flow) provides lots of action steps out of the box. My favourite one is Compose. What does it do? What is the Compose action? The Compose action is like a stati

Blog Categories
 

Beginner

Intermediate

 

Advanced

Power Automate Essentials

How can I help you?

I am happy to help at any time.  You can contact me via the official PowerAutomate community forum.  Tag me (@abm) on any post you make there if you would like to me take a look at it.

I am always available for both corporate training or 1-2-1 training for individuals. 

© 2023 by Walkaway. Proudly created with Wix.com

  • Twitter Black Round
This site was designed with the
.com
website builder. Create your website today.
Start Now