Passing Step Function in Node.JS

136 views Asked by At

In Pipedream, I have an OpenWeatherAPI request that successfully retrieves forecast data for temperature on a given day.

My goal is to send this forecast to send a PUT request to a service called Apilio that stores a temperature value for further evaluation.

I’m able to conduct the GET and PUT HTTP requests respectively, but unable to pass the data within Pipedream. In other words, I can manually type in a temperature value in the PUT request, but unable to pass it as a variable.

Here is my script thus far:

import axios from "axios"

export default defineComponent({
  async run({ steps, $ }) {


const feelslikeresponse = 

steps.OpenWeatherAPI.$return_value.daily[7].feels_like.morn;
    return feelslikeresponse;
    const { data } = await axios({
  method: "PUT",
  url: "https://api.apilio.com/api/v1/numeric_variables/(my UUID)",
})
return data.species
  }, })

var data = { "numeric_variable": { "value": feelslikeresponse } };

let config = {



 "method": 'put',
  "url": 'https://api.apilio.com/api/v1/numeric_variables/(my UUID)',
  "headers": { 
    'Content-Type': 'application/json',
    'Authorization': 'Basic (my header code)'
  },
  data : data
};

axios(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});

Within the code preview, I am able to hover over steps.OpenWeatherAPI.$return_value.daily[7].feels_like.morn and see the temperature value, but subsequent references to it are lost.

I am still new to coding and would appreciate any pointers or guidance.

1

There are 1 answers

0
Siberian Husko On

Thanks to Wesley for the lesson and scrutinizing syntax. Between this and some hints from the Pipedream forums, how Axios works, and other documentation, I worked out the solution as follows:

import {axios} from "@pipedream/platform";

export default defineComponent({
  async run({ steps, $ }) {
    const feelslikeresponse =
      steps.OpenWeatherAPI.$return_value.daily[7].feels_like.morn;

let data = JSON.stringify({
  "numeric_variable":{
    "value":feelslikeresponse
  }
})

const { config } = await axios($,{
  method: "put",
  url: "(myUUID)",
  headers: {
    "Content-Type": "application/json",
    Authorization:
      "Basic (headercode)",
  },
  data : data
});
   return feelslikeresponse;

},
});