NASA API Integration using Microsoft Flow
In this blog, I will explain how to call an API (Application Programming Interface) using Microsoft Flow.
Here I am using NASA API Astronomy picture of the day (APOD). The plan is to retrieve the picture of the day using the API and store 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.
Above date and hd parameters are optional. To generate an API Key you need to register your name, email and follow the instructions from the website (https://api.nasa.gov/).
Now we can start building the Flow. Here I am using a scheduled trigger which triggers every day.
Next, we need to use the HTTP flow step. Here copy the api_key which you received as part of the registration process. You can also extend the query parameters using date and hd which are optional.
The response from the above step HTTP request will be in JSON format.
JSON schema is as follows:
{
"type": "object",
"properties": {
"date": {
"type": "string"
},
"explanation": {
"type": "string"
},
"hdurl": {
"type": "string"
},
"media_type": {
"type": "string"
},
"service_version": {
"type": "string"
},
"title": {
"type": "string"
},
"url": {
"type": "string"
}
}
}
Next, we need to get the image and store in SharePoint. To get the image content I am using another HTTP flow method and passing the image hdurl. For the API call we are using the GET method.
Next I am using a compose flow step to get the filename of the image using JSON response url property.
Above expression is as follows:
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.
Thank you for reading!
Comments
-
NASA API Integration using Microsoft Flow
I made a video on this same topic some time back.
youtu.be/-GVu1EsKfvo
*This post is locked for comments