Script Step
Last update: 28.04.2022
Script step gives you the ability to run your own Node.Js code within the workflow. Following Node.js modules are loaded into script step by default.
You can directly use these modules.
Buffer
crypto
URLSearchParams
http
https
url
util
If you need additional Node.js Module or NPM modules you can reach out to integrations@apifuse.io. We will evaluate and include it in the script step.
Follow the below step to configure Script Step.
1. Define your input fields using schema builder
– You may want to use the output from previous action steps and use it in your script.
2. Define your output fields using Schema builder
– You may want to send output from your script to other action steps.
3. Code your script. Below node.js code gets the weather information from an external API for a given city. the line async function execute(input, context) is the entry point for your script.
you need to return the object with fields you defined in the output schema. the first parameter in the execute function contains all the input you defined in the input schema. if you notice in the below script
we get the city information from input and finally return outputs (temperature, wind_speed, etc..)
function getWeatherData(input){
return new Promise((resolve,reject)=>{
const options = {
hostname: 'api.weatherapi.com',
port: 443,
path: '/v1/current.json?key=6453994143738212211&q=input.city&aqi=no',
method: 'GET'
}
let req = https.request(options,res=>{
let data=''
res.on('data',d=>{data +=d})
res.on('end',d=>{
if(d){data +=d}
resolve(data)
})
})
req.on('error',err=>{
reject(err);
})
req.end()
})
}
async function execute(input,context){
let data = await getWeatherData(input);
let weather = JSON.parse(data);
return {
temperature:weather.current.temp_f,
wind_speed:weather.current.wind_mph,
humidity:weather.current.humidity,
feels_like:weather.current.feelslike_f
}
}