Request
A summary of how to use the Request Node within a Flow.
Adding a Request Node

Overview

Buildable's Request Nodes are built-in cloud functions that provide a powerful way to add custom asynchronous logic to your Flows. You can use Request functions to perform requests to external API endpoints. Buildable functions support Javascript (ES7) and provide access to select npm modules.
The Request Node is the only type of Node that has access to the external network.
If you know how to write Javascript, you'll know how to build a Request function in Buildable. In this section, we'll go over the following short concepts:

Defining input in a Request Node

When you double click a function node, the code editor will open with 2 tabs. The focused tab is the input tab that allows you to select data that will be passed to your run function. Read more about selecting the input passed into the run function in the "What makes up a node?" section of the "Add Nodes to a Flow" page.

Writing code in a Request Node

Navigate to the run function tab in the code editor to begin writing your code. You can write your custom code in the run function, which accepts any valid Javascript (ES7). The values defined in the input function would be passed as an object named input.
Below is an example function that performs a request to the Coindesk API to get the latest Bitcoin price.
Input
Run
Output
1
/**
2
* Lets you select the input for your node
3
*
4
* @param {Params} params
5
* @param {Object} $trigger - This flow's request object
6
* @param {Object} $nodes - Data from above nodes
7
*/
8
const nodeInput = ({ $trigger, $nodes }) => {
9
return {
10
COINDESK_API_URL: "https://api.coindesk.com/v1/bpi/currentprice.json"
11
}
12
}
Copied!
1
const axios = require("axios");
2
​
3
/**
4
* @param {Run} input
5
*/
6
const run = async (input) => {
7
const { data } = await axios.get(input.COINDESK_API_URL);
8
​
9
return data;
10
}
Copied!
1
{
2
"time": {
3
"updated": "Nov 24, 2021 20:02:00 UTC",
4
"updatedISO": "2021-11-24T20:02:00+00:00",
5
"updateduk": "Nov 24, 2021 at 20:02 GMT"
6
},
7
"disclaimer": "This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org",
8
"chartName": "Bitcoin",
9
"bpi": {
10
"USD": {
11
"code": "USD",
12
"symbol": "$",
13
"rate": "56,805.0801",
14
"description": "United States Dollar",
15
"rate_float": 56805.0801
16
},
17
"GBP": {
18
"code": "GBP",
19
"symbol": "£",
20
"rate": "42,634.5984",
21
"description": "British Pound Sterling",
22
"rate_float": 42634.5984
23
},
24
"EUR": {
25
"code": "EUR",
26
"symbol": "€",
27
"rate": "50,750.9651",
28
"description": "Euro",
29
"rate_float": 50750.9651
30
}
31
}
32
}
Copied!
Request Nodes do not have access to setTimeout, setInterval, setImmediate, queueMicrotask, and eval.

Using NPM Packages in a Request Node

Buildable provides access to certain NPM packages that can be used within functions. Within the Request Node, you also have access to the axios and got NPM packages.
Here's an example of how you can access the got package within your run function to shorten a URL.
Input
Run
Output
1
/**
2
* Lets you select the input for your node
3
*
4
* @param {Params} params
5
* @param {Object} $trigger - This flow's request object
6
* @param {Object} $nodes - Data from above nodes
7
*/
8
const nodeInput = ({ $trigger, $nodes }) => {
9
return {
10
SHRTCO_API_URL: "https://api.shrtco.de/v2/shorten",
11
url: "https://buildable.dev" // Url to shorten
12
}
13
}
Copied!
1
const got = require("got");
2
​
3
/**
4
* @param {Run} input
5
*/
6
const run = async (input) => {
7
const url = `${input.SHRTCO_API_URL}?url=${input.url}`;
8
​
9
const { body } = await got(url, {
10
responseType: "json"
11
});
12
​
13
const shortenedUrl = body.result.short_link;
14
​
15
return shortenedUrl;
16
}
Copied!
1
"shrtco.de/ePrUK"
Copied!
You can see a full list of all the NPM packages in the Javascript Libraries Catalog. If you don't see the module that you're looking for, let us know and we can usually add it for you.

Throwing errors in a Request Node

If your function throws any form of error, whether syntax or otherwise, the error will be caught in the $nodeErrors object. You can read more about that in the Test a Flow page. You can throw errors as expected by using throw new Error().
Last modified 1mo ago