(Tutorial) NASA Solar Flare Data Automation Workflow ๐Ÿ›ฐ๏ธ(โญโญ)

Date of creation
Name
(Tutorial) NASA Solar Flare Data Automation Workflow ๐Ÿ›ฐ๏ธ(โญโญ)
Created by
  • data_popcorn

Download Workflow

1. Workflow Overview

This n8n workflow is an automated process that periodically fetches solar flare data from NASA's DONKI (Dataset Of Notifications, Knowledge, Information) system, filters it based on specific conditions, and stores the results via PostBin.

Key Features:

โ€ข
Get solar flare data for the last 7 days using the NASA DONKI API.
โ€ข
Filters data based on a specific condition (whether ClassType contains "C").
โ€ข
Save the filtered data to the PostBin service.

Problem being solved:

Reduce the hassle of manually retrieving data each time you monitor solar activity, and automatically filter and save only data that meets specific conditions.

User Benefits:

โ€ข
Easily collect and manage NASA data
โ€ข
Filter and organize only data that meets specific conditions
โ€ข
Real-time monitoring through automated processes

2. Pre-work โœ…

To run this workflow, you will need the following preparations:
โ€ข
Issue NASA API Key:
โ—ฆ
Create an API key in the NASA API Portal and add credentials in n8n
โ€ข
Create a PostBin account and Bin:
โ—ฆ
Since data is stored using PostBin, account creation and Bin ID verification are required.

3. Main functions and roles โš™๏ธ

This workflow consists of several nodes, each with its own role:

1๏ธโƒฃ Schedule Trigger

โ€ข
Automatically run the workflow every Monday at 9:00 AM.

2๏ธโƒฃ NASA Data Collection (NASA Node)

โ€ข
Get solar flare data for the last 7 days from the DONKI API.
โ€ข
Request parameter: startDate (7 days ago from today)
โ€ข
API Credentials: NASA API Key required
โ€ข
Click the Settings ( ... ) option in the upper right corner and change the Timezone to Asia/Seoul.

Add NASA Nodes and Set Credentials

1.
After the Trigger node, press the + button to add a node, then search & select NASA . Select Get DONKI Solar Flares . This operation returns a report on recent solar flares. When you select the operation, n8n adds the node to the canvas and opens it.
2.
You will need to set up credentials to access the NASA API:
a.
Select the Credentials dropdown for NASA API .
b.
Select [Create New ] . The n8n Credentials view opens.
c.
Go to NASA API and fill out the form to generate an API key . NASA will generate a key for you. (It will look like this: VG7azJnxdf6sPXgdKuPGplbGjZD3RSY9nAoWfNPf )
d.
Copy the key and paste it into n8n's API Key .
e.
Select Save .
f.
Close the credentials screen. n8n returns to the node. The new credentials should be automatically picked up from the credentials for NASA API .
3.
By default, DONKI Solar Flare provides data for the last 30 days. To limit it to the last week only, use the additional fields :
a.
Select additional fields.
b.
Select a start date .
c.
To get reports from a week in advance, you can use a formula: Select the Formula tab next to the start date , then select the expand button to open the full formula editor.
d.
Enter the following formula in the Formula field:
{{$today.minus({days: 7}).toFormat('yyyy-MM-dd')}}
๐Ÿ’ก
โ€ข
N8n uses luxon to handle dates and times, providing two variables for convenience: $now and $today . See Expressions > Luxon for more information .
4.
When you close the food edit mode, you will return to the NASA node.
5.
Now you can verify that the node is working and return the expected date: Select Test Step to manually run the node. n8n will call the NASA API and display details about solar flares for the last 7 days in the OUPTURE section.
6.
Close the NASA node to return to the workflow canvas.

Add logic with If nodes

3๏ธโƒฃ Data Filtering (If Node)

โ€ข
Filters out imported solar flare data whose classType value contains "C".
โ€ข
Only filtered data is passed on to further processing.
โ€ข
N8n supports complex logic in workflows. In this tutorial, we will use the If node to create two branches, each generating a report from NASA data.
โ€ข
There are five categories of solar flares. You can create logic to send reports with lower categories to one output and reports with higher categories to another output.
Add an If node:
1.
Select the Add Node connector from the NASA node .
2.
If . n8n search returns a list of nodes that match the search.
3.
Select If to add a node to the canvas .
N8n opens the node.
4.
You need to check the value of the classType property of NASA data. To do this:
a.
Enter the drag class value 1 .
Make sure you have the NASA node running in the previous section.
If you did not run the NASA node following the steps in the previous section, you will not see any data to work with in this step.
b.
Change the compare operation to include .
c.
Enter X in Value 2 .
This is the highest classification of solar flare.
The next step is to create two reports, one for X class solar flares and one for all small solar flares.
d.
Now you can check if the node is working and return the expected date: Select Test Step to manually run the node. n8n will test the data against the condition and display the results matching True or False in the Output panel.
๐Ÿ’ก
In this tutorial, we are working with real-time dates. When we run the workflow, if we find that there is no solar flare of class X, the valueย 2 of __T90940_____ A, B, Cย orย Try replacing it with M.

3๏ธโƒฃ Data Filtering (If Node)

โ€ข
Filters out imported solar flare data whose classType value contains "C".
โ€ข
Only filtered data is passed on to further processing.

Outputting data from a workflow

โ€ข
The final step in the workflow is to send two reports about solar flares. In this example, we send the data to PostBean , a service that receives the data and displays it in a temporary web page.
1.
In the If node, select Add node connector marked as true .
2.
Search for PostBin . n8n shows a list of nodes that match the search.
3.
Select PostBin .
4.
Select Send Request . n8n adds the node to the canvas and opens it.
5.
Go to PostBin and select Create Bin .
Keep the tab open so you can return to it as you test your workflow.
6.
Copy the trash can ID. It should look something like this: 1651063625300-2016451240051
7.
In n8n, paste the postbin ID into the bin ID .
8.
Now we configure the data to be sent to Postbin.
Select the Expression tab next to the blank content , then select the Expand button to open the full expression editor.
9.
Select Current Node > Input Data > JSON > classType . n8n adds the expression to the expression editor and displays sample output.
10.
The expression is: {{$json["classType"]}} .
Add a message to make it a full expression:
There was a solar flare of class {{$json["classType"]}}
11.
Close the formula editor and return to the node.
12.
Close the postbean node and return to the canvas.
13.
Add another postbean node to handle the incorrect output path of the If node:
a.
Duplicate the first postbean node by hovering over it and selecting Node context menu > Duplicate Node .
b.
Drag a false connector from the If node to the left of the new PostBean node.

5๏ธโƒฃ Handling additional data requests (PostBin2, PostBin3 nodes)

โ€ข
Additional processing is possible based on the requestId of the saved data.

Workflow Testing

1.
Now you can test the entire workflow. Select Test Workflow . n8n will run the workflow, showing each step in progress.
2.
Go back to PostiBin. Refresh the page to see the output.
3.
If you want to use this workflow (i.e. run it automatically once a week), you need to activate it by checking the Activate toggle.
๐Ÿ’ก
( Timeout) The postbin's trashcan exists for 30 minutes after it is created. If this timeout is exceeded, you may need to create a new bin and update the ID of the postbin node.

4. How it works (step-by-step explanation) ๐Ÿ”„

1๏ธโƒฃ Schedule Trigger โ†’ Run workflow every Monday at 9 AM
2๏ธโƒฃ
NASA node โ†’ Get solar flare data from DONKI API
3๏ธโƒฃ
If node โ†’ Filter only if classType contains "C"
4๏ธโƒฃ
PostBin/PostBin1 node โ†’ Save filtered data to PostBin
5๏ธโƒฃ
PostBin2/PostBin3 node โ†’ Additional processing can be performed based on the saved data request ID.

5. Expected Results and Output ๐Ÿ“Š

Example output:

Data stored in PostBin:
There was a solar flare of class C3.2
โ€ข
Only solar flare data that meets certain conditions are stored.
โ€ข
Users can check the stored data through PostBin.
Running this workflow will automatically retrieve, filter, and store real-time solar flare data from the NASA DONKI API. ๐Ÿš€