Page 1 of 1

Rest Api?

Posted: Fri Mar 05, 2021 5:26 pm
by Dm86
I amt trying to learn how to use the rest API. I can not change a value of an attribute (I want to turn off and on lamps). Can some one please help me?

My example in python, If I change the name of "C2 Sovrumslampa" then it is changed. But I can not change value of attribute State.

import requests
import json

url = "http://222.100.10.222:8020/rest/items/106"

headers = {"Content-Type": "application/json"}

body = {
}

response = requests.request("GET", url, data=body, headers= headers)

response_data = response.json()

print (response_data) # Gives me a result

print (" ")

body = {
"name": "C2 Sovrumslampa",
"attributes": [
{
"name": "State",
"value": "Off"
}
]
}

response = requests.put(url, data=json.dumps(body), headers=headers)
print (response) # Result 200

Re: Rest Api?

Posted: Fri Mar 05, 2021 6:07 pm
by Dm86
I realized that I probably should use action/invoke. But it gives me error 404.Problem with url?

url = "http://222.100.10.222:2222/rest/items/106/action/invoke"

body = "off"

response = requests.put(url, data=body, headers=headers)
print (response) # Result 404

Re: Rest Api?

Posted: Wed Mar 10, 2021 7:30 pm
by Dm86
I solved it. Correct syntax for url is.

http://222.100.17.222::8080/rest/items/102/actions/On/invoke