I have a need to output information coming from a HTTP api request to a read only text box type in dashboard. Not sure is there a way to do this. Appreciate a sample workflow that can be shared
I’m unclear on if the HTTP request is triggering the workflow (via a webhook or an experience endpoint) or if you are making the request within the workflow using an HTTP node. Either way, here’s what I would do to solve your use case …
- Create a new device (or use an existing device) and add an attribute of type “string”; we’ll call it “httpResponse” for our purposes.
- Use a Device State node to store the value you want to display on the dashboard on the device’s “httpResponse” attribute.
- In your dashboard, you can use an indicator block or a textarea within an input controls block to display the most recent value of that attribute on that device.
Let us know if you have any other questions!
Thanks Dylan, this will work. However, if I use a String node to manipulate the data, assign to device state and then want to output to Indicator block, how do I add a new line char in string node?
I cannot put \n char in the String node for cancatenation
I see what you mean; we’ll make a change to allow new line characters in the String Node. It should go out with our next release.
In the meantime, you can use a Function Node to accomplish what you’re looking to do. Assuming your current string is stored at the payload path of data.myString
, you can concatenate a new line with this code in the Function Node:
payload.data.myString += '\nThe String to Concatenate';
The problem is in the function node. I get an error in the following code - unexpected number - 0
var httpResponse = ‘Nearby Gas Stations:\n\n’;
httpResponse += 'Gas Station: ’ + data.body.results.0.name;
httpResponse += '\n\nAddress: ’ + data.body.results.0.vicinity;
httpResponse += '\n\nOpen ’ + data.body.results.0.opening_hours.open_now;
payload.data.httpResponse = httpResponse;
My Http response that came from an API is as follows
data
body
result
0: {} // some keys like name, vicinity etc
1: {} // some keys like name, vicinity etc
The Function Node is pure JavaScript, so it doesn’t follow the payload path / Handlebars syntax you’re using here. Also, you’ll need to put payload
at the front of your variables. So, taking the code above, it should actually read as follows:
var httpResponse = 'Nearby Gas Stations:\n\n';
httpResponse += 'Gas Station: ' + payload.data.body.results[0].name;
httpResponse += '\n\nAddress: ' + payload.data.body.results[0].vicinity;
httpResponse += '\n\nOpen ' + payload.data.body.results[0].opening_hours.open_now;
payload.data.httpResponse = httpResponse;