OctoPrint 3D Printer Control
You can monitor and control a user's 3D printer running OctoPrint by calling its REST API with curl and the bash tool. This reads live temperatures and print progress and can start, pause, and cancel prints.
Setup (ask once, then remember for the session)
Ask the user for:
- Base URL of their OctoPrint, e.g.
http://192.168.1.42orhttp://octopi.local - An API key (OctoPrint → Settings → Application Keys, or the global API key under Settings → API)
Store for the session:
OP="http://192.168.1.42"
KEY="ABCDEF0123456789"
Authentication is the header X-Api-Key: $KEY on every request. Never print the key back to the user.
Check it is reachable
curl -s -H "X-Api-Key: $KEY" "$OP/api/version" | jq .
curl -s -H "X-Api-Key: $KEY" "$OP/api/connection" | jq '.current'
Read printer state (temperatures, flags)
curl -s -H "X-Api-Key: $KEY" "$OP/api/printer" | jq '{state: .state.text, tool0: .temperature.tool0, bed: .temperature.bed}'
A 409 here means the printer is not connected — connect it first:
curl -s -X POST -H "X-Api-Key: $KEY" -H "Content-Type: application/json" \
-d '{"command":"connect"}' "$OP/api/connection"
Read current job / progress
curl -s -H "X-Api-Key: $KEY" "$OP/api/job" \
| jq '{file: .job.file.name, completion: .progress.completion, printTimeLeft: .progress.printTimeLeft}'
Control the print job
Start the currently selected file:
curl -s -X POST -H "X-Api-Key: $KEY" -H "Content-Type: application/json" \
-d '{"command":"start"}' "$OP/api/job"
Pause / resume / cancel (each returns 204 No Content on success):
curl -s -X POST -H "X-Api-Key: $KEY" -H "Content-Type: application/json" -d '{"command":"pause","action":"pause"}' "$OP/api/job"
curl -s -X POST -H "X-Api-Key: $KEY" -H "Content-Type: application/json" -d '{"command":"pause","action":"resume"}' "$OP/api/job"
curl -s -X POST -H "X-Api-Key: $KEY" -H "Content-Type: application/json" -d '{"command":"cancel"}' "$OP/api/job"
Temperatures
Set hotend (tool0) and bed targets:
curl -s -X POST -H "X-Api-Key: $KEY" -H "Content-Type: application/json" \
-d '{"command":"target","targets":{"tool0":210}}' "$OP/api/printer/tool"
curl -s -X POST -H "X-Api-Key: $KEY" -H "Content-Type: application/json" \
-d '{"command":"target","target":60}' "$OP/api/printer/bed"
Move the print head / send G-code
Home axes, jog, or send raw G-code:
curl -s -X POST -H "X-Api-Key: $KEY" -H "Content-Type: application/json" \
-d '{"command":"home","axes":["x","y","z"]}' "$OP/api/printer/printhead"
curl -s -X POST -H "X-Api-Key: $KEY" -H "Content-Type: application/json" \
-d '{"command":"jog","x":10,"y":-5,"z":0.1}' "$OP/api/printer/printhead"
curl -s -X POST -H "X-Api-Key: $KEY" -H "Content-Type: application/json" \
-d '{"commands":["G28","M106 S128"]}' "$OP/api/printer/command"
Guidelines
- Cancelling or starting a print is physical and hard to undo — confirm with the user first.
- Do not set temperatures above the printer's safe limits; ask the user for their material's target if unsure (PLA bed ~60, hotend ~200; PETG ~80/240).
- A connection error usually means the bot host cannot reach the user's LAN — their OctoPrint must be reachable from the internet (reverse proxy, Tailscale, or a forwarded port).