Luup code question about tonumber(code)

I’m trying to use someone else’s code: [code]local http=require(“socket.http”)
local auroraToken = “xxxxxxxxxxxxxxxxxxxxxxx”;
local siteurl = “http://192.168.x.xx:16021/api/v1/“..auroraToken..”/state/on/
local siteurl1 = “http://192.168.x.xx:16021/api/v1/“..auroraToken..”/state/
local respback = { }
local res, code, response_headers, status = http.request
{
url = siteurl,
method = “GET”,
headers =
{
[“Content-Type”] = “application/json”
},
sink = ltn12.sink.table(respback)
}

if tonumber(code) == 200
then
for key,value in pairs(respback) do
auroraOn = string.match(value, “%a+”, 8)
end
end

if auroraOn == ‘false’
then auroraOn = ‘true’
else
auroraOn = ‘false’
end

local payload = ‘{“on” : {“value”:’…auroraOn…‘}}’
print(payload)

local respback = { }
local res, code, response_headers, status = http.request
{
url = siteurl1,
method = “PUT”,
headers =
{
[“Content-Type”] = “application/json”,
[“Content-Length”] = payload:len()
},
source = ltn12.source.string(payload),
sink = ltn12.sink.table(respback)
}[/code]

It runs fine in the developer mode (in that it says it runs), but it doesn’t do anything. I believe the line “if tonumber(code) == 200” means that if the response code is 200 do what is next. Running the code in another language I get a 202 return code. Should I change the 200 to 202, or is there something I can put in runs the if statement no matter the code returned?

You probably want to check the documentation of the API you are trying to talk to. Each code means something. 200 typically means success. I am not sure what 202 means.

202 Accepted. The request has been accepted for processing, but the processing has not been completed. The request might or might not eventually be acted upon, as it might be disallowed when processing actually takes place.

It’s probably worth a punt setting it to 202, but the point of a 202 is that it may, or may no be the result you expect, and you can’t check.

I’d not be at all surprised if it gives you an inconsistent result.
As suggested, what’s the API documentation suggest for a 202 return (although it really shouldn’t be different, there may be some additional context) also, what’s the other language? (and code?)
Finally, what’s the API you’re trying to use?

C