Hi,
I am currently using openhab 3 and with the help of openhab ui and zigbee bindings, i’m able to add, control and delete the zigbee devices and even REST APIs works well.
I’m using
HARDWARE: raspberry pi board
OS: linux os
visual studio for node js application
instead of login and controlling through openhab UI, i wanted to login it through node js code. Is there any procedure and code flow or APIs related documentation through which i can be able to login to openhab UI through node js application
can i know how the following FORM DATA is generated that i have observed through inspect in web browser while login to openhab
Yes, actually I am doing exactly this. I am using basic authentication to log in, not the token. In order to do so, you need to activate this option in the UI.
However I have to admit that I am just a beginner with node js so there may be probably better coding solutions than that. On node js side I am using the request package to call the OH Rest API.
Here are a few code snippets which work for me in my local LAN, the example shows the basic authentication and reads the list with all things from OH:
var ohserverip = 'http://192.168.1.20:8080';
var ohusername = 'username';
var ohpassword = 'password';
var ohauth = "Basic " + new Buffer((ohusername) + ":" + (ohpassword)).toString("base64");
var options = {
url: ohserverip + '/rest/things',
method: 'GET',
headers: {
'Accept': 'application/json',
'Accept-Charset': 'utf-8',
'User-Agent': 'just a client',
"Authorization" : ohauth
}
};
request(options, function(err, resp, body) {
json = JSON.parse(body);
for(var i=0; i<json.length; i++)
{
//do anything you want with the thing data
}
}