techenby/octoprint-sdk

A PHP SDK for OctoPrint.

1.2.4 2022-06-24 20:19 UTC

This package is auto-updated.

Last update: 2024-05-25 00:20:38 UTC


README

Build Status Total Downloads Latest Stable Version License

The OctoPrint SDK provides an expressive interface for interacting with OctoPrint's Rest API and managing OctoPrint instances servers. The structure of this repository is based on the Laravel Forge SDK.

Installation

To install the SDK in your project you need to require the package via composer:

composer require techenby/octoprint-sdk

Basic Usage

You can create an instance of the SDK like so:

$pikachu = new TechEnby\OctoPrint(PRINTER_URL, API_TOKEN);

Using the OctoPrint instance you may perform multiple actions as well as retrieve the different resources OctoPrint's API provides:

$files = $pikachu->files();

Rest Endpoints and SDK Methods

Resource Request Method
General Information
Login POST /api/login $octoPrint->login()
Current User GET /api/currentuser $octoPrint->currentUser()
Version Information
Version Information GET /api/version $octoPrint->version()
Server Information
Server information GET /api/server $octoPrint->server()
Connection handling
Get connection settings GET /api/connection $octoPrint->connection()
Get connection state $octoPrint->state()
Issue a connection command POST /api/connection
Connect OctoPrint to printer $octoPrint->connect()
Disconnect OctoPrint from printer $octoPrint->dissconect()
File operations
Retrieve all files GET /api/files $octoPrint->files()
Retrieve files from specific location GET /api/files/{location} $octoPrint->files($location)
Upload file POST /api/files/{location} $octoPrint->uplaodFile($location, $path, $contents)
Retrieve a specific file's or folder's information GET /api/files/{location}/{filename} $octoPrint->file($location, $path)
Issue a file command POST /api/files/{location}/{path}
Select a file $octoPrint->selectFile($location, $path)
Unselect a file $octoPrint->unselectFile($location, $path)
Slice a file $octoPrint->sliceFile($location, $path, $data)
Copy a file $octoPrint->copyFile($location, $path, $destination)
Move a file $octoPrint->moveFile($location, $path, $destination)
Delete file DELETE /api/files/{location}/{path} $octoPrint->deleteFile($location, $path)
Job operations
Issue a job command POST /api/job
Start the print of the currently selected file $octoPrint->start()
Cancel current job $octoPrint->cancel()
Restart job with selected file from beginning $octoPrint->restart()
Pause/Resume/Toggle current job $octoPrint->pause($action)
Retrieve information about the current job GET /api/job $octoPrint->job()
Languages
Retrieve installed language packs GET /api/languages $octoPrint->languages()
Upload a language pack POST /api/languages
Delete a language pack DELETE /api/languages/{locale}/{pack} $octoPrint->deleteLanguage($locale, $pack)
Printer operations
Retrieve the current printer state GET /api/printer $octoPrint->printer()
Issue a print head command POST /api/printer/printhead
Jog the print head $octoPrint->jog($x, $y, $z, $absolute, $speed)
Home the print head $octoPrint->home($axes)
Change the feedrate factor $octoPrint->feedrate($factor)
Issue a tool command POST /api/printer/tool
Set the target tool temperature $octoPrint->targetToolTemps($targets)
Set the offset tool temperature $octoPrint->offsetToolTemps($offsets)
Select printer's current tool $octoPrint->selectTool($tool)
Extrude from current tool $octoPrint->extrude($amount, $speed)
Retract from current tool $octoPrint->retract($amount, $speed)
Set the flow rate $octoPrint->flowrate($factor)
Retrieve the current tool state GET /api/printer/tool $octoPrint->tool()
Issue a bed command POST /api/printer/bed
Set the target bed temperature $octoPrint->targetBedTemps($targets)
Set the offset bed temperature $octoPrint->offsetBedTemp($offsets)
Retrieve the current bed state GET /api/printer/bed $octoPrint->bed()
Issue a chamber command POST /api/printer/chamber
Set the target chamber temperature $octoPrint->targetChamberTemps($targets)
Set the offset chamber temperature $octoPrint->offsetChamberTemp($offsets)
Retrieve the current chamber state GET /api/printer/chamber $octoPrint->chamber()
Issue an SD command POST /api/printer/sd
Initialize the printer’s SD card $octoPrint->initSD()
Refresh the printer’s SD card $octoPrint->refreshSD()
Release the printer’s SD card $octoPrint->releaseSD()
Retrieve the current SD state GET /api/printer/sd $octoPrint->sd()
Send an arbitrary command(s) to the printer POST /api/printer/command $octoPrint->command($command) $octoPrint->commands($commands)
Retrieve custom controls GET /api/printer/command/custom
Printer profile operations
Retrieve all printer profiles GET /api/printerprofiles $octoPrint->profiles()
Retrieve a single printer profile GET /api/printerprofiles/{identifier} $octoPrint->profile($id)
Add a new printer profile POST /api/printerprofiles $octoPrint->createProfile($data, $basedOn)
Update an existing printer profile PATCH /api/printerprofiles/{profile} $octoPrint->updateProfile($id, $data)
Remove an existing printer profile DELETE /api/printerprofiles/{profile} $octoPrint->deleteProfile($id)
Settings
Retireve current settings GET /api/settings $octoPrint->settings()
Save settings POST /api/settings $octoPrint->updateSettings($data)
Regenerate the system wide API key POST /api/settings/apikey $octoPrint->regenerateApiKey()
Fetch template data GET /api/settings/templates Will implement when not in beta
Slicing
List All Slicers and Slicing Profiles GET /api/slicing $octoPrint->slicers()
List Slicing Profiles of a Specific Slicer GET /api/slicing/{slicer}/profiles $octoPrint->slicerProfiles($slicer)
Retrieve Specific Profile GET /api/slicing/{slicer}/profiles/{key} $octoPrint->slicerProfile($slicer, $key)
Add Slicing Profile PUT /api/slicing/{slicer}/profiles/{key} $octoPrint->createSlicerProfile($slicer, $key, $data)
Update Slicing Profile PATCH /api/slicing/{slicer}/profiles/{key} $octoPrint->updateSlicerProfile($slicer, $key, $data)
Delete Slicing Profile DELETE /api/slicing/{slicer}/profiles/{key} $octoPrint->deleteSlicerProfile($slicer, $key)
System
List all registered system commands GET /api/system/commands $octoPrint->systemCommands()
List all registered system commands for a source GET /api/system/commands/{source} $octoPrint->systemCommand($source)
Execute a registered system command POST /api/system/commands/{source}/{action} $octoPrint->runSystemCommand($source, $action)
Timelapse
Retirieve a list of timelapses and the current config GET /api/timelapse $octoPrint->timelapses() $octoPrint->timelapseConfig()
Delete a timelapse DELETE /api/timelapse/{filename} $octoPrint->deleteTimelapse($filename)
Issue a command for an unrendered timelapse POST /api/timelapse/unrendered/{name} $octoPrint->renderTimelapse($name)
Delete an unrendered timelapse DELETE /api/timelapse/unrendered/{name} $octoPrint->deleteTimelapse($filename, true)
Change current timelapse config POST /api/timelapse $octoPrint->updateTimelapseSettings($data)

Contributing

Thank you for considering contributing to OctoPrint SDK! All pull requests are welcome, please follow the conventions set out in existing files.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

OctoPrint SDK is open-sourced software licensed under the MIT license.