Hi Guys
Not a JavaScript person...
I am trying to add geofence data as well as the device data to an embedded webpage.
Does anybody know if you can get the geofences(for a device) using the embedded webpage. I tried to get geofences but all I keep getting is device info.
In other words does the authentication via the token expose the geofence data or just device data
var ajax = function (method, url, callback) {
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open(method, url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
callback(JSON.parse(xhr.responseText));
}
};
if (method == 'POST') {
xhr.setRequestHeader('Content-type', 'application/json');
}
xhr.send()
};
ajax('GET', url + '/api/server', function(server) {
ajax('GET', url + '/api/session?token=' + token, function(user) {
ajax('GET', url + '/api/geofences', function(devices) {
var socket = new WebSocket('ws' + url.substring(4) + '/api/socket');
socket.onclose = function (event) {
console.log('Socket has been closed for geofences');
};
socket.onmessage = function (event) {
var data = JSON.parse(event.data);
console.log(event.data);
};
});
});
});
Thanks in advance
Robby
Endpoint /api/geofences
should give you geofences. It's not possible for it to return devices.
Thank you
As I thought the token will not allow you to get the geofences... I will have to do a correct authentication
Hi Guys
Not a JavaScript person...
I am trying to add geofence data as well as the device data to an embedded webpage.
Does anybody know if you can get the geofences(for a device) using the embedded webpage. I tried to get geofences but all I keep getting is device info.
In other words does the authentication via the token expose the geofence data or just device data
var ajax = function (method, url, callback) { var xhr = new XMLHttpRequest(); xhr.withCredentials = true; xhr.open(method, url, true); xhr.onreadystatechange = function () { if (xhr.readyState == 4) { callback(JSON.parse(xhr.responseText)); } }; if (method == 'POST') { xhr.setRequestHeader('Content-type', 'application/json'); } xhr.send() }; ajax('GET', url + '/api/server', function(server) { ajax('GET', url + '/api/session?token=' + token, function(user) { ajax('GET', url + '/api/geofences', function(devices) { var socket = new WebSocket('ws' + url.substring(4) + '/api/socket'); socket.onclose = function (event) { console.log('Socket has been closed for geofences'); }; socket.onmessage = function (event) { var data = JSON.parse(event.data); console.log(event.data); }; }); }); });
Thanks in advance
Robby