Good morning,
even though I read the documentation and everything works with GET/POST/DELETE, I can't understand what I have to do to modify a room that exists (id=279); I always receive return code 400:
[DEBUG] 09:01:40: response.status 400
[DEBUG] 09:01:40: failed
[DEBUG] 09:01:40: response.data {"type": "ERROR", "reason": "id", "message": "no id"}
[DEBUG] 09:01:40: type ERROR
[DEBUG] 09:01:40: message no id
[DEBUG] 09:01:40: reason id
Here are the instructions:
--[[
--%% autostart
%% properties
%% globals
--]]
print('crearoom')
created = false
stanzaID = 0
stanzaid=279;
nameRoom="newstanza";
sectionIDRoom=219;
print('chiamataPUT')
date = os.date();
requestBody = {body = {name = nameRoom, sectionID=sectionIDRoom}}
httpClient = net.HTTPClient()
httpClient:request("http://127.0.0.1/api/rooms?id="..stanzaid, {
options = {
data = json.encode(requestBody),
method = "PUT",
headers = {
["Content-Type"] = "application/json",
["Accept"] = "application/json",
["Authorization"] = "Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
}
},
success = function(response)
print('response.status '..response.status)
if response.status ~= 200 and response.status ~= 201 then print("failed"); end
created = true
print('response.data '..response.data)
results = json.decode(response.data)
for k,v in pairs(results) do
print(k, v)
if k == "id" then
stanzaID = v
print ('stanzaID 1 '..stanzaID)
end
end
end,
error = function(message)
print("error:", message)
end
});
Thanks in advance.
Lorenzo