Page 1 of 1

Problem with opening URL using dzvents

Posted: Saturday 06 April 2019 16:54
by doh
I'm trying to move a script from old LUA to dzvents.

The script basically calls on the Tado API to get temperature from my heating control.

On the old LUA script it calls curl to do this, like this:

Code: Select all

os.execute('curl -s "https://auth.tado.com/oauth/token" -d client_id=public-api-preview -d client_secret=4HJGRffVR8xb3XdEUQpjgZ1VplJi6Xgw -d grant_type=password -d password=' .. tado_pwd .. ' -d scope=home.user -d username=' .. tado_user)
Using dzVents I'm trying this:

Code: Select all

domoticz.openURL({
	url = 'https://auth.tado.com/oauth/token',
	method = 'POST',
	callback = 'tadoauthcallback',
	postData = {
		client_id = "public-api-preview", 
		client_secret = "4HJGRffVR8xb3XdEUQpjgZ1VplJi6Xgw", 
		grant_type = "password", 
		password = tado_pwd, 
		scope  = "home.user", 
		username  = tado_user
	}
})
With the old approach, it works fine, but with the dzvents approach I'm getting an unauthorised response back from the tado web site.

Any ideas why? They look equivalent to me.

Thanks

Re: Problem with opening URL using dzvents

Posted: Saturday 06 April 2019 22:07
by doh
Found it!
The tado website doesn't like the content-type of application/json and was expecting a content type of application/x-www-form-urlencoded
By forcing the content type to application/x-www-form-urlencoded and setting the postData to be of the format below, it now works.

Code: Select all

postData="field1=value1&field2=value2..."

Re: Problem with opening URL using dzvents

Posted: Sunday 07 April 2019 13:46
by Thorgal789
Good to know, thx.
I want to do same on my scripts, but there is an advantage to use dz-event instead of os.execute and curl ? If it's local command no prb with asynchronous request.