OH3 API (at lease latest snapshots) requires wither Basic Authentication, if enabled, or an API Token.I do not recall when Basic Auth was introduced. I am testing HABApp with an API Token.
A Token can be created from your Admin page. More information here.
Getting a token is not the problem, however how to use it in the HTTP requests.
I wasn’t able to find any information about changed syntax (not even for the moved time setting) in any documentaion (especially on the next.openhab… site).
I tried it with replacing user and password with my credentials, but failed with Unauthorized API request: Invalid Basic authentication credentials.
Should I use something like user=myUserName?
Fatal transport error: java.util.concurrent.TimeoutException: Total timeout 5000 ms elapsed
BTW : A new used for each device? I’m trying to get data to and from the REST API, so it is the device which runs openHAB which tries to get something from itself.
It is a service on the device ( & executed by a user) trying to get information from the openHAB service, outside of openHAB. The fact it is running on the same device does not matter to OH.
val systemstatus_thing =sendHttpGetRequest("http://opus:******@127.0.0.1:8080/rest/things/systeminfo%3Acomputer%3Aopuspi", 10000)
val returnvalue = sendHttpPutRequest("http://opus:*****@127.0.0.1:8080/rest/things/systeminfo%3Acomputer%3Aopuspi","application/json",systemstatus_thing.replaceAll('"pid":([0-9]+)','"pid":' + openHAB_PID), 15000)
Can’t say if it would work with smaller timeouts. My testing-system got a bit unresponsive yesterday, that caused the problems. Now it is working, THANKS!
i have a related problem with an thing i want to disable / enable per rule.
The url i got from API explorer, basic auth is enabled and added to url
var String url = "restuser:restpass@https://openhab.srv.local/rest/things/onkyo%3ATX-NR636%3A18b0a1bd-65a1-bdb9-70a8-bd0965b96cd5/enable"
var put = sendHttpPutRequest(url, "application/json", 'enabled', 5000)
failed: Invalid URI host: null (authority: null)
this is the original thing id onkyo:TX-NR636:18b0a1bd-65a1-bdb9-70a8-bd0965b96cd5
the user created via Karaf is common user (not admin) … is the normal user able to send a Put Request? to me, it sounds like a “write” permission, and it should be an admin characteristic
how to modify the user:pass structure with the API token?
btw if I need an admin user to send put requests, also the API token should be generated by an admin account right?