What is the problem?
I'm connecting to octoprint from my HA system (fibaro)
I have it working for most commands pause, resume, etc.
I can also retrieve information successfully
Ideally provide exact steps to follow in order to reproduce your problem:
-->
For cancel the following is working.
`body = '{"command":"cancel"}'
url = "http://192.168.1.145/api/job?apikey="..apikey
local http = net.HTTPClient()
http:request(url, {
options = {
method = 'POST',
headers = {['Content-Type'] = 'application/json'},
data = body
},})`
For connect I am using the User api key but the following is not working
`body = '{"command":"connect",}'
url = "http://192.168.1.145/api/connection?apikey="..Uapikey
local http = net.HTTPClient()
http:request(url, {
options = {
method = 'POST',
headers = {['Content-Type'] = 'application/json'},
data = body
},})`
Do I have the syntax correct
Any help appreciated
What did you already try to solve it?
I also tried the following
Working perfectly
`body = '{"source":"core","action":"shutdown",}'
url = "http://192.168.1.145/api/system/commands/core/shutdown?apikey="..apikey
local http = net.HTTPClient()
http:request(url, {
options = {
method = 'POST',
headers = {['Content-Type'] = 'application/json'},
data = body
},})
end`
Not working - returning a 403
`body = '{"command":"connect",}'
url = "http://192.168.1.145/api/connection"
local http = net.HTTPClient()
http:request(url, {
options = {
method = 'POST',
headers = {['apikey'] = '6E6D1D77F8A7450BA876973E9B6B0A84', ['Content-Type'] = 'application/json; charset=UTF-8'},
data = body
},
success = function(resp)
if (resp.status == 200) or (resp.status == 201) then
local data = json.decode(resp.data);
fibaro:debug(resp.data);
else
fibaro:debug(resp.status);
fibaro:debug("ERR");
end
end,
error = function(error)
fibaro:debug"ERROR"
fibaro:debug(error)
end
})`
Also not working and returning a 400
`body = '{"command":"disconnect",}'
url = "http://192.168.1.145/api/connection?apikey="..Uapikey
local http = net.HTTPClient()
http:request(url, {
options = {
method = 'POST',
headers = {['Content-Type'] = 'application/json; charset=UTF-8'},
data = body
},
success = function(resp)
if (resp.status == 200) or (resp.status == 201) then
local data = json.decode(resp.data);
fibaro:debug(resp.data);
else
fibaro:debug(resp.status);
fibaro:debug("ERR");
end
end,
error = function(error)
fibaro:debug"ERROR"
fibaro:debug(error)
end
})`
I'm think it's syntax issue
Additional information about your setup (OctoPrint version, OctoPi version, printer, firmware, octoprint.log
, serial.log
or output on terminal tab, ...)
Latest octoprint version.