Page 1 of 1
cURL(ing) using Name vs IDX
Posted: Wednesday 01 February 2017 15:52
by liderbug
I use:
http://sg53:8080/json.htm?type=command& ... itchcmd=On"
in place of "idx=" I would like to use "name=frontdoor" = ERR. I hope I'm just spelling 'name' wrong. If not, -> Suggestion Box
Thanks
Re: cURL(ing) using Name vs IDX
Posted: Wednesday 01 February 2017 17:01
by jvdz
Not sure how you are scripting this, but I assume this all runs outside of the Domoticz events world.
This is a SH script I've played with to retrieve the IDX for a Name:
Code: Select all
#!/bin/bash
#--Get Domotics Device
IDX=`curl -s 'http://127.0.0.1:8080/json.htm?type=devices&order=name' | /usr/local/bin/jq -r '.result[]|select(.Name == "'$1'")|.idx'`
if [ "$IDX" = "" ]; then
echo "Switchname:$1 not found"
else
echo "Switchname:$1 has IDX:$IDX"
fi
It can be run from the prompt like: scriptname.sh SwitchName
It does require jq to be installed.
Jos
Re: cURL(ing) using Name vs IDX
Posted: Thursday 02 February 2017 2:19
by liderbug
Ya, I see what you're doing in your script. I could do the same thing, sans jq (I'm not a json kind of guy), with a bash or php script. Kind of not the point though. Would be nice/cleaner if the internal dom code would accept "idx=" or "name=" or whatever. I'm assuming the internal code uses the database with a "select x from table where idx = 'n'" when a curl http:......idx=n happens.
Hello, code maintainers ....
Thanks
Re: cURL(ing) using Name vs IDX
Posted: Thursday 02 February 2017 8:54
by lost
liderbug wrote:Would be nice/cleaner if the internal dom code would accept "idx=" or "name=" or whatever.
In fact, implementation of JSON API looks sometimes a bit heterogenous!
See user variables related API:
getuservariable -> IDX required,
updateuservariable -> NAME required.
So if you need to read then update a user var from an external script using JSON API, you must know both (so you must at least check idx match name, as this is quite error prone)!
I think get and update were not implemented by the same guy, and they didn't had the same needs...