Want to send gcode to the printer before shutdown. Using 'curl' I send the data to api/printer/command and getting the error:
"error": "You don't have the permission to access the requested resource. It is either read-protected or not readable by the server."
What did you already try to solve it?
In octoprint, Settings, Access Control, gave me access to everything.
Have you tried running in safe mode?
Yes, to no avail.
Did running in safe mode solve the problem?
No.
Whether I use command line or send json file, says the same thing.
First - you’ve got a json file that doesn’t contain json. If it’s got those headers & stuff in it, it’s not json. JSON would be just the bit in curly brackets at the bottom.
-d is for sending data, not a file that curl will read and send. You’ve literally sent OctoPrint “@/etc/prntoff.json”, not the content of the file. The reason you get a “not authorised” error is that you never actually sent an API key. You can see it’s not there in the verbose output - everything with a > is being sent to the server.
I would refer to this post for an example - as it says, OctoPrint’s API is nothing special and any resource on how to use curl would help you.
The information I am using is an example from the documentation. That is why I am using it.
Sending data from a file is '-d @[filename]. It is sending more than just the file name;
upload completely sent off: 191 out of 191 bytes
The API key I blanked out. Didn't want to give it out. That is correct.
The error of '403 forbidden' is what I cannot get passed.
I am pretty sure it's an authentication thing and I have tried user Id and password with the same results.
Was just wondering if there is something locked/disabled on the octoprint side.
None of that changes the fact that you can't send the headers with the data. It's clear from your output that the headers did not include the authentication information from the file.
The short version is: you need to include the authentication as either a header or a URL query parameter. The data param is data only.
Longer, technical detail: Curl sends the headers separated by newlines followed by 2 new lines (ie. a blank line) and then the data. So even though your data does technically include the header information first, the server is already done processing headers by the time it sees that.
Your verbose output also shows that you didn't set the content type to application/json, so once you the authentication working, you need to supply that header as well, as I showed in my example that Charlie linked.
Also, even if the above were not true, the Curl man page states:
Posting data from a file named 'foobar' would thus be done with -d, --data@foobar. When -d, --data is told to read from a file like that, carriage returns, newlines and null bytes are stripped out.
Which would cause headers to not be parsed properly since a server is expecting new lines between each.
You know, to keep this 'mostly' inside OctoPrint, I would use Custom Control Editor and GCode Systems Commands plugins.
Using CCE, put a button in the Control Tab called "Shutdown" that runs the
M140 S0 ; shut off the bed
M106 S255 ; turn on the part cooler fan - really helps move the air near the hotend
M109 R50 ; set min temp of hotend
M106 S0 ; after cool kill the fan
OCTO100 ; call the 'replacemen' shutdown thru GCode System Command plugin
and in GCode System Command
OCTO100 set to "sudo shutdown -h now" or whatever...