Skip to content

Instantly share code, notes, and snippets.

@Phaeilo
Last active August 24, 2025 22:41
Show Gist options
  • Select an option

  • Save Phaeilo/7017a2f9f58860fa1f001bf74f0f393c to your computer and use it in GitHub Desktop.

Select an option

Save Phaeilo/7017a2f9f58860fa1f001bf74f0f393c to your computer and use it in GitHub Desktop.
Use the PrusaLink API with curl to upload & print a G-Code file
#!/bin/bash
# Use the PrusaLink API with curl to upload & print a G-Code file
# Usage: ./upload_and_print.sh <gcode_file>
# License: CC-0 / Public Domain
PRINTER_URL="${PRUSA_PRINTER_URL:-}" # must not include trailing slash!
PRINTER_API_KEY="${PRUSA_API_KEY:-}"
if [ $# -eq 0 ]; then
echo "Usage: $0 <gcode_file>"
exit 1
fi
GCODE_FILE="$1"
if [ ! -f "$GCODE_FILE" ]; then
echo "Error: File '$GCODE_FILE' not found!"
exit 1
fi
echo "Uploading $GCODE_FILE to $PRINTER_URL..."
# Get filename for the endpoint
FILENAME=$(basename "$GCODE_FILE")
curl -X PUT \
-H "User-Agent: PrusaSlicer/2.9.2" \
-H "Accept: */*" \
-H "X-Api-Key: $PRINTER_API_KEY" \
-H "Print-After-Upload: ?1" \
-H "Content-Type: text/x.gcode" \
-H "Overwrite: ?1" \
--data-binary "@$GCODE_FILE" \
"$PRINTER_URL/api/v1/files/usb//$FILENAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment