If you create a new DZvents script and choose the template for http request, you can then fill in your api call and modify the assignment of someValue slightly and you will get the example below.
I guess your problem was how to get a certain value out of the long string and I have included in the example the extraction of the postal code. Documentation on this is indeed very poor and in previous scripts I developed I have spent days of trial and error.
In this case the following works:
local someValue = item.json[1].postcode
The important thing is to look closely to the buildup of your response, i.e. the square brackets, the curled brackets, the field identifiers etc.
Code: Select all
return {
on = {
timer = {
'every 1 minutes' -- just an example to trigger the request
},
httpResponses = {
'trigger' -- must match with the callback passed to the openURL command
}
},
logging = {
level = domoticz.LOG_INFO,
marker = 'template',
},
execute = function(domoticz, item)
if (item.isTimer) then
domoticz.openURL({
url = 'https://apps.hvcgroep.nl/rest/adressen/1562BP-1',
method = 'GET',
callback = 'trigger', -- see httpResponses above.
})
end
if (item.isHTTPResponse) then
if (item.ok) then
if (item.isJSON) then
local someValue = item.json[1].postcode -- just an example
-- update some device in Domoticz
domoticz.log('myTextDevice '.. someValue, domoticz.LOG_INFO)
end
else
domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
domoticz.log(item, domoticz.LOG_ERROR)
end
end
end
}