This example uses HTML Canvas newest feature "Preload dashboard data" to easily implement navigation through dashboards.
A drop-down menu will display all of the Dashboards present in the Ubidots account, upon selecting one, said dashboard will be opened in a new browser tab.
HTML:
<div> <h1>Navigate through your Dashboards</h1> <selectid="dashboardsList"></select></div>
Javascript:
var token =ubidots.token;constdashboardsDropdown=document.getElementById('dashboardsList');dashboardsDropdown.addEventListener('change', handleSelectionChange);getAllDashboards(token).then((data) =>{// Iterate over the data and create optionsconstdropdown=document.getElementById('dashboardsList');data.results.forEach(item => {constoption=document.createElement('option');option.value =item.id; // Adjust the value according to your dataoption.text =item.label; // Adjust the displayed text according to your dataoption.label =item.label;dropdown.appendChild(option); });});functionhandleSelectionChange() {constdashboardID=this.value; // Get the selected valueconsturl=`https://industrial.ubidots.com/app/dashboards/${dashboardID}`;window.open(url,'_blank');}asyncfunctiongetAllDashboards(ubidotsToken){consturl="https://industrial.api.ubidots.com/api/v2.0/dashboards/";constmethod="GET";constreq=awaitfetchWrapper(url, method, ubidotsToken);return req;}asyncfunctionfetchWrapper(url, method, token =null, payload =null){constoptions= { method: method, headers: {'Content-Type':'application/json'} };if (payload) {options.body =JSON.stringify(payload); }if (token) {options.headers['X-Auth-Token'] = token; }constresponse=awaitfetch(url, options);constjsonData=awaitresponse.json();return jsonData;}