Good morning. I am contacting you to see if you can help me with sending data from a dashboard to workflows via webhook (or endpoint).
Specifically, my idea is a Custom HTML block that allows you to download data in CSV from a device through the Losant API node, using the Data:Export option. The part related to the Losant node is solved.
My Custom HTML block looks like this:
I have no problem in selecting start date and end date in relation to when the data should be downloaded, as well as the email where this data should be sent to. My problem comes at the time of indicating the device Id in its corresponding box (Current Device dropdown option should have assigned the value of the deviceID the dashboard is currently showing, due to the deviceID is a ctx variable). I attach a screenshot in relation to the HTML code where I think it will be better understood what my problem is.
I have been playing with the Custom HTML block and the code that comes by default, and the maximum that I have obtained is that the content of the JSON appears on the screen. However, I have been unable to send the id of this JSON content through HTML using:
<option value="EXTRACT IN SOME WAY THE ID OF THE JSON">Current Device</option>.
My problem, in conclusion, is to know how to extract from the dashboard context the id of the current device (the one being queried) and put this value in the “value” field of an HTML element, in order to send it through a webhook.
The code that I’m using right now in the Custom HTML Block is:
<meta charset="UTF-8">
<!--
You can include any external JavaScript or CSS as needed.
This example demonstrates including Bootstrap and JQuery
into your custom HTML page.
-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<style>
body {
padding: 10px;
background: transparent;
}
div{
text-align: center
}
</style>
<script type="text/javascript">
/*
Renders the block input to the page.
This function is simply printing the raw data to the page
for debugging purposes.
*/
function renderBlock(input) {
document.getElementById('blockInput').innerHTML =
JSON.stringify(input.ctx, undefined, 2);
}
/*
Add listeners to your required events. These listeners invoke
the functions above so that your code can handle the event
as needed.
*/
DashboardBlock.on('change', renderBlock);
/*
Render the initial state when the block loads.
*/
$(document).ready(function() {
renderBlock(DashboardBlock.input);
});
</script>
and
<div class="container-fluid">
<div class="row">
<div class="col">
<form action="https://triggers.losant.com/webhooks/xTN5VtSfrjMWM5-YpxHqQ-f69FJFc99eifvbXXFq" method="post">
<div> Select start day:
<input class="input-group date" type="date" id="start" name="date-start">
</div><br>
<div> Select end day:
<input class="input-group date" type="date" id="end" name="date-end">
</div><br>
<label> Select device:</label>
<select class="form-control" name="numberDevices">
<option value = "0">Current Device</option>
<option value="1">All Devices</option>
</select><br>
<label id="blockInput"></label>
<div>
<label for="email">Email address:</label>
<input type="email" class="form-control" name="email" id="email"
placeholder="e.g. test.user@example.com">
</div><br>
<button type="submit" class="btn btn-success pull-right">Download CSV File</button>
</form>
</div>
</div>
</div>
Finally, the idea is sending this data using a Webhook so the received body will be:
where numberDevices would be the ID of the device so you can use it as an input in the Losant API node.
Any help would be greatly appreciated. Thanks in advance, greetings