๐Ÿ“
How to Ping an API
This can be done in a Computed Field if you want to fetch from the API when the Flow gets loaded or you can do it as a Data Output if you want to trigger the fetch at some specific point or points of the Flow.

As a Computed Field:

Step 1: Create a Computed Field

  • Go to the "All" Tab on the Left Sidebar
  • Scroll to the bottom where you can find the Computed Fields area, and click on "Create New"

Step 2: Write your Code

  • Click on "Generate Sample Code" below the code editor, on the Options Tab of the Right Sidebar
  • Write your code inside the created function. It should look something like this:
1
return fetch('https://example.com/api', {
2
method: 'POST', // or 'GET'
3
headers: {
4
'Content-Type': 'application/json' // Common example of a header
5
},
6
body: JSON.stringify({ key: 'value' }), // For sending some data
7
})
8
.then(response => response.json()) // This just turns the response into JSON data
9
.then(data => { /* Do something with data */ })
Copied!

As a Data Output:

Step 1: Create the Data Output

  • Go to the "All" Tab on the Left Sidebar
  • Scroll to the bottom where you can find the Data Outputs area, and click on "Create New"
  • On the Options Tab of the Right Sidebar select "Custom" as an output
  • Check the "Manual Trigger Only" box

Step 2: Write your Code

  • Click on "Generate Sample Code" below the code editor, on the Options Tab of the Right Sidebar
  • Write your code inside the created function. It should look something like this:
1
fetch('https://example.com/api', {
2
method: 'POST', // or 'GET'
3
headers: {
4
'Content-Type': 'application/json' // Common example of a header
5
},
6
body: JSON.stringify({ key: 'value' }), // For sending some data
7
})
8
.then(response => response.json()) // This just turns the response into JSON data
9
.then(data => { /* Do something with data */ })
Copied!

Step 3: Trigger it!

  • Select the page or component where you want to ping the API
  • Go to the Triggers Tab on the Right Sidebar
  • Choose to trigger on page load, on page complete, on click, on success, etc.
  • Select the Data Output you want to trigger
  • Done!