Rest Api?
Posted: Fri Mar 05, 2021 5:26 pm
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
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