Rest Api?

Functionality and usage of the OpenNethome Server
Post Reply
Dm86
Posts: 6
Joined: Sat Dec 30, 2017 9:27 am

Rest Api?

Post 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
Dm86
Posts: 6
Joined: Sat Dec 30, 2017 9:27 am

Re: Rest Api?

Post 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
Dm86
Posts: 6
Joined: Sat Dec 30, 2017 9:27 am

Re: Rest Api?

Post by Dm86 »

I solved it. Correct syntax for url is.

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