Problem with opening URL using dzvents

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
doh
Posts: 82
Joined: Monday 01 December 2014 13:28
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: London, UK
Contact:

Problem with opening URL using dzvents

Post 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
doh
Posts: 82
Joined: Monday 01 December 2014 13:28
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: London, UK
Contact:

Re: Problem with opening URL using dzvents

Post 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..."
Thorgal789
Posts: 882
Joined: Wednesday 15 August 2018 14:38
Target OS: -
Domoticz version:
Contact:

Re: Problem with opening URL using dzvents

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest