Page 1 of 1

Json call doesnt see admin right

Posted: Friday 21 July 2023 20:40
by desertdog
I want to change switches via a API call, so first of all I tested if I can connect to Domiticz with:

https://USERNAME:[email protected]:4 ... getversion and also tried the variant where USERNAME and PASSWORD are base64 encoded. In both cases I get this result:
{
"HaveUpdate" : false,
"UseUpdate" : false,
"build_time" : "2023-02-14 15:06:40",
"dzvents_version" : "3.1.8",
"hash" : "f9b9ac774",
"python_version" : "3.7.3 (default, Jan 22 2021, 20:04:44) \n[GCC 8.3.0]",
"status" : "OK",
"title" : "GetVersion",
"version" : "2023.1"
}
According to the documentation: https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's, this is the result: When requested by a (non-admin) User (which is the current default response for users)
But the username and password I use are those from an admin, I also tried adding a new admin and tried with these credentials, but this gives the same result. WhenI i try other json parameters I get the Unauthorized page. So something seems the go wrong.

What is the correct way to connect?

Re: Json call doesnt see admin right

Posted: Friday 21 July 2023 21:20
by waltervl
The different versions of result from getversion JSON call is implemented in current 2023.1 beta. You are using 2023.1 stable.

Perhaps use another JSON call.

Re: Json call doesnt see admin right

Posted: Friday 21 July 2023 21:23
by kiddigital
How are you testing the API call? Some browser drop the Username:password part before sending the request for safety reasons.

Maybe use a tool like Postman to test your API call so you can be sure that the request and responses are ok and readable for you as well.

API calls can currently still be made by sending an 'Authorization'-header with base64 encoded 'Basic' authentication (see Wiki).

Better would be to start using the OAuth2/OpenID connect methods ('password' grant-type or even better the 'authorization_code' grant type (with PKCE)), see the SECURITY_SETUP.md for more details.

If you enable the 'webserver,recevied,auth' debug flags (start domoticz with --debugflags ..), you can see what domoticz is receiving and what happens during authentication.

Hope the above helps.

Re: Json call doesnt see admin right

Posted: Friday 21 July 2023 21:23
by kiddigital
waltervl wrote: Friday 21 July 2023 21:20 The different versions of result from getversion JSON call is implemented in current 2023.1 beta. You are using 2023.1 stable.

Perhaps use another JSON call.
And now in 2023.2 Stable as well! :D

Re: Json call doesnt see admin right

Posted: Friday 21 July 2023 21:38
by desertdog
I updated to the latest version, running the same url now results in chrome browser

Code: Select all

{
	"status" : "OK",
	"title" : "GetVersion"
}
when I try to post the same URL in Postman I get 'could not send request', but I don't know Postman that well, so not really sure what's happening there. Also tried them with a curl command (curl full URL), but also nothing there

I need single URLs that have to be pasted into the backend of a supplier's hardware device. so with one url call, I need to update a switch in Domoticz when the hardware device changes. Are there any people that can get a working reponse when they try this on their Domoticz installation? I mean: is this broken in Domoticz maybe?

Re: Json call doesnt see admin right

Posted: Friday 21 July 2023 22:20
by kiddigital
Did you enable the mentioned debug flags?

The result shows (as you are now using 2023.2) that domoticz does either not see the credentials or the credentials are not accepted. The debug information will tell you which one it is.

What curl command did you use? I would expect curl to work fine as well.

The URL is an HTTPS url and not plain HTTP? If so, although not advisable especially when called by some external device, you need to enable Basic-Auth over HTTP first.