File operations¶
Retrieve all files¶
- GET /api/files¶
 Retrieve information regarding all files currently available and regarding the disk space still available locally in the system. The results are cached for performance reasons. If you want to override the cache, supply the query parameter
forceand set it totrue. Note that while printing a refresh/override of the cache for files stored on the printer’s SD card is disabled due to bandwidth restrictions on the serial interface.By default only returns the files and folders in the root directory. If the query parameter
recursiveis provided and set totrue, returns all files and folders.Returns a Retrieve response.
Requires the
FILES_LISTpermission.Example 1:
Fetch only the files and folders from the root folder.
GET /api/files HTTP/1.1 Host: example.com X-Api-Key: abcdef...HTTP/1.1 200 OK Content-Type: application/json { "files": [ { "name": "whistle_v2.gcode", "path": "whistle_v2.gcode", "type": "machinecode", "typePath": ["machinecode", "gcode"], "hash": "...", "size": 1468987, "date": 1378847754, "origin": "local", "refs": { "resource": "http://example.com/api/files/local/whistle_v2.gcode", "download": "http://example.com/downloads/files/local/whistle_v2.gcode" }, "gcodeAnalysis": { "estimatedPrintTime": 1188, "filament": { "length": 810, "volume": 5.36 } }, "print": { "failure": 4, "success": 23, "last": { "date": 1387144346, "success": true } } }, { "name": "whistle_.gco", "path": "whistle_.gco", "type": "machinecode", "typePath": ["machinecode", "gcode"], "origin": "sdcard", "refs": { "resource": "http://example.com/api/files/sdcard/whistle_.gco" } }, { "name": "folderA", "path": "folderA", "type": "folder", "typePath": ["folder"], "children": [ { "name": "whistle_v2_copy.gcode", "path": "whistle_v2_copy.gcode", "type": "machinecode", "typePath": ["machinecode", "gcode"], "hash": "...", "size": 1468987, "date": 1378847754, "origin": "local", "refs": { "resource": "http://example.com/api/files/local/folderA/whistle_v2_copy.gcode", "download": "http://example.com/downloads/files/local/folderA/whistle_v2_copy.gcode" }, "gcodeAnalysis": { "estimatedPrintTime": 1188, "filament": { "length": 810, "volume": 5.36 } }, "print": { "failure": 4, "success": 23, "last": { "date": 1387144346, "success": true } } } ] } ], "free": "3.2GB" }Example 2
Recursively fetch all files and folders.
Fetch only the files and folders from the root folder.
GET /api/files?recursive=true HTTP/1.1 Host: example.com X-Api-Key: abcdef...HTTP/1.1 200 OK Content-Type: application/json { "files": [ { "name": "whistle_v2.gcode", "path": "whistle_v2.gcode", "type": "machinecode", "typePath": ["machinecode", "gcode"], "hash": "...", "size": 1468987, "date": 1378847754, "origin": "local", "refs": { "resource": "http://example.com/api/files/local/whistle_v2.gcode", "download": "http://example.com/downloads/files/local/whistle_v2.gcode" }, "gcodeAnalysis": { "estimatedPrintTime": 1188, "filament": { "length": 810, "volume": 5.36 } }, "print": { "failure": 4, "success": 23, "last": { "date": 1387144346, "success": true } } }, { "name": "whistle_.gco", "path": "whistle_.gco", "type": "machinecode", "typePath": ["machinecode", "gcode"], "origin": "sdcard", "refs": { "resource": "http://example.com/api/files/sdcard/whistle_.gco" } }, { "name": "folderA", "path": "folderA", "type": "folder", "typePath": ["folder"], "children": [ { "name": "test.gcode", "path": "folderA/test.gcode", "type": "machinecode", "typePath": ["machinecode", "gcode"], "hash": "...", "size": 1234, "date": 1378847754, "origin": "local", "refs": { "resource": "http://example.com/api/files/local/folderA/test.gcode", "download": "http://example.com/downloads/files/local/folderA/test.gcode" } }, { "name": "subfolder", "path": "folderA/subfolder", "type": "folder", "typePath": ["folder"], "children": [ { "name": "test.gcode", "path": "folderA/subfolder/test2.gcode", "type": "machinecode", "typePath": ["machinecode", "gcode"], "hash": "...", "size": 100, "date": 1378847754, "origin": "local", "refs": { "resource": "http://example.com/api/files/local/folderA/subfolder/test2.gcode", "download": "http://example.com/downloads/files/local/folderA/subfolder/test2.gcode" } }, ], "size": 100, "refs": { "resource": "http://example.com/api/files/local/folderA/subfolder", } } ], "size": 1334, "refs": { "resource": "http://example.com/api/files/local/folderA", } } ], "free": "3.2GB" }
Retrieve files from specific location¶
- GET /api/files/(string: location)¶
 Retrieve information regarding the files currently available on the selected location and – if targeting the
locallocation – regarding the disk space still available locally in the system. The results are cached for performance reasons. If you want to override the cache, supply the query parameterforceand set it totrue. Note that while printing a refresh/override of the cache for files stored on the printer’s SD card is disabled due to bandwidth restrictions on the serial interface.By default only returns the files and folders in the root directory. If the query parameter
recursiveis provided and set totrue, returns all files and folders.Returns a Retrieve response.
Requires the
FILES_LISTpermission.Example:
GET /api/files/local HTTP/1.1 Host: example.com X-Api-Key: abcdef...HTTP/1.1 200 OK Content-Type: application/json { "files": [ { "name": "whistle_v2.gcode", "path": "whistle_v2.gcode", "type": "machinecode", "typePath": ["machinecode", "gcode"], "hash": "...", "size": 1468987, "date": 1378847754, "origin": "local", "refs": { "resource": "http://example.com/api/files/local/whistle_v2.gcode", "download": "http://example.com/downloads/files/local/whistle_v2.gcode" }, "gcodeAnalysis": { "estimatedPrintTime": 1188, "filament": { "length": 810, "volume": 5.36 } }, "print": { "failure": 4, "success": 23, "last": { "date": 1387144346, "success": true } } } ], "free": "3.2GB" }- Parameters:¶
 location – The origin location from which to retrieve the files. Currently only
localandsdcardare supported, withlocalreferring to files stored in OctoPrint’suploadsfolder andsdcardreferring to files stored on the printer’s SD card (if available).force – If set to
true, forces a refresh, overriding the cache.recursive – If set to
true, return all files and folders recursively. Otherwise only return items on same level.
- Status Codes:¶
 200 OK – No error
404 Not Found – If location is neither
localnorsdcard
Upload file or create folder¶
- POST /api/files/(string: location)¶
 Upload a file to the selected
locationor create a new empty folder on it.Other than most of the other requests on OctoPrint’s API which are expected as JSON, this request is expected as
Content-Type: multipart/form-datadue to the included file upload. AContent-Lengthheader specifying the full length of the request body is required as well.To upload a file, the request body must at least contain the
fileform field with the contents and file name of the file to upload.To create a new folder, the request body must at least contain the
foldernameform field, specifying the name of the new folder. Note that folder creation is currently only supported on thelocalfile system.Returns a 201 Created response with a
Locationheader set to the management URL of the uploaded file and an Upload Response as the body upon successful completion.Requires the
FILES_UPLOADpermission.Example for uploading a file
POST /api/files/sdcard HTTP/1.1 Host: example.com X-Api-Key: abcdef... Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryDeC2E3iWbTv1PwMC Content-Length: 430 ------WebKitFormBoundaryDeC2E3iWbTv1PwMC Content-Disposition: form-data; name="file"; filename="whistle_v2.gcode" Content-Type: application/octet-stream M109 T0 S220.000000 T0 G21 G90 ------WebKitFormBoundaryDeC2E3iWbTv1PwMC Content-Disposition: form-data; name="select" true ------WebKitFormBoundaryDeC2E3iWbTv1PwMC Content-Disposition: form-data; name="print" true ------WebKitFormBoundaryDeC2E3iWbTv1PwMC--HTTP/1.1 200 OK Content-Type: application/json Location: http://example.com/api/files/sdcard/whistle_v2.gcode { "files": { "local": { "name": "whistle_v2.gcode", "path": "whistle_v2.gcode", "type": "machinecode", "typePath": ["machinecode", "gcode"], "origin": "local", "refs": { "resource": "http://example.com/api/files/local/whistle_v2.gcode", "download": "http://example.com/downloads/files/local/whistle_v2.gcode" } }, "sdcard": { "name": "whistle_.gco", "path": "whistle_.gco", "origin": "sdcard", "refs": { "resource": "http://example.com/api/files/sdcard/whistle_.gco" } } }, "done": false, "effectiveSelect": true, "effectivePrint": true }Example with UTF-8 encoded filename following RFC 5987
POST /api/files/local HTTP/1.1 Host: example.com X-Api-Key: abcdef... Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryDeC2E3iWbTv1PwMC Content-Length: 263 ------WebKitFormBoundaryDeC2E3iWbTv1PwMC Content-Disposition: form-data; name="file"; filename*=utf-8''20mm-%C3%BCml%C3%A4ut-b%C3%B6x.gcode Content-Type: application/octet-stream M109 T0 S220.000000 T0 G21 G90 ------WebKitFormBoundaryDeC2E3iWbTv1PwMC--HTTP/1.1 200 OK Content-Type: application/json Location: http://example.com/api/files/local/20mm-umlaut-box.gcode { "files": { "local": { "name": "20mm-umlaut-box", "origin": "local", "refs": { "resource": "http://example.com/api/files/local/whistle_v2.gcode", "download": "http://example.com/downloads/files/local/whistle_v2.gcode" } } }, "done": true, "effectiveSelect": false, "effectivePrint": false }Example for creating a folder
POST /api/files/local HTTP/1.1 Host: example.com X-Api-Key: abcdef... Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryDeC2E3iWbTv1PwMD Content-Length: 246 ------WebKitFormBoundaryDeC2E3iWbTv1PwMD Content-Disposition: form-data; name="foldername" subfolder ------WebKitFormBoundaryDeC2E3iWbTv1PwMD Content-Disposition: form-data; name="path" folder/ ------WebKitFormBoundaryDeC2E3iWbTv1PwMD--HTTP/1.1 200 OK Content-Type: application/json Location: http://example.com/api/files/local/folder/subfolder { "folder": { "name": "subfolder", "path": "folder/subfolder", "origin": "local" }, "done": true }- Parameters:¶
 location – The target location to which to upload the file. Currently only
localandsdcardare supported here, withlocalreferring to OctoPrint’suploadsfolder andsdcardreferring to the printer’s SD card. If an upload targets the SD card, it will also be stored locally first.
- Form Parameters:¶
 file – The file to upload, including a valid
filename.path – The path within the
locationto upload the file to or create the folder in (without the future filename orfoldername- basically the parent folder). If unset will be taken from the providedfile’s name orfoldernameand default to the root folder of thelocation.select – Whether to select the file directly after upload (
true) or not (false). Optional, defaults tofalse. If the printer is not operational, this will have no effect and theeffectiveSelectfield in the response will be set tofalse. Ignored when creating a folder.print – Whether to start printing the file directly after upload (
true) or not (false). If set,selectis implicitlytrueas well. Optional, defaults tofalse. If the printer is not operational, this will have no effect and theeffectivePrintfield in the response will be set tofalse. Ignored when creating a folder.userdata – [Optional] An optional string that if specified will be interpreted as JSON and then saved along with the file as metadata (metadata key
userdata). Ignored when creating a folder.foldername – The name of the folder to create. Ignored when uploading a file.
- Status Codes:¶
 201 Created – No error
400 Bad Request – If no
fileorfoldernameare included in the request,userdatawas provided but could not be parsed as JSON or the request is otherwise invalid.404 Not Found – If
locationis neitherlocalnorsdcardor trying to upload to SD card and SD card support is disabled409 Conflict – If the upload of the file would override the file that is currently being printed or if an upload to SD card was requested and the printer is either not operational or currently busy with a print job.
415 Unsupported Media Type – If the file is neither a
gcodenor anstlfile (or it is anstlfile but slicing support is disabled)500 Internal Server Error – If the upload failed internally
Retrieve a specific file’s or folder’s information¶
- GET /api/files/(string: location)/(path: filename)¶
 Retrieves the selected file’s or folder’s information.
If the file is unknown, a 404 Not Found is returned.
If the targeted path is a folder, by default only its direct children will be returned. If
recursiveis provided and set totrue, all sub folders and their children will be returned too.On success, a 200 OK is returned, with a file information item as the response body.
Requires the
FILES_LISTpermission.Example
GET /api/files/local/whistle_v2.gcode HTTP/1.1 Host: example.com X-Api-Key: abcdef...HTTP/1.1 200 OK Content-Type: application/json { "name": "whistle_v2.gcode", "size": 1468987, "date": 1378847754, "origin": "local", "refs": { "resource": "http://example.com/api/files/local/whistle_v2.gcode", "download": "http://example.com/downloads/files/local/whistle_v2.gcode" }, "gcodeAnalysis": { "estimatedPrintTime": 1188, "filament": { "length": 810, "volume": 5.36 } }, "print": { "failure": 4, "success": 23, "last": { "date": 1387144346, "success": true } } }- Parameters:¶
 location – The location of the file for which to retrieve the information, either
localorsdcard.filename – The filename of the file for which to retrieve the information
recursive – If set to
true, return all files and folders recursively. Otherwise only return items on same level.
- Status Codes:¶
 200 OK – No error
404 Not Found – If
targetis neitherlocalnorsdcard,sdcardbut SD card support is disabled or the requested file was not found
Issue a file command¶
- POST /api/files/(string: location)/(path: path)¶
 Issue a file command to an existing file. Currently supported commands are:
- select
 Selects a file for printing. Additional parameters are:
print: Optional, if set totruethe file will start printing directly after selection. If the printer is not operational when this parameter is present and set totrue, the request will fail with a response of409 Conflict.
Upon success, a status code of 204 No Content and an empty body is returned. If there already is an active print job, a 409 Conflict is returned.
Requires the
FILES_SELECTpermission.- unselect
 Unselects the currently selected file for printing.
Upon success, a status code of 204 No Content and an empty body is returned. If no file is selected or there already is an active print job, a 409 Conflict is returned. If path isn’t
current`or the filename of the current selection, a 400 Bad Request is returnedRequires the
FILES_SELECTpermission.- slice
 Slices an STL file into GCODE. Note that this is an asynchronous operation that will take place in the background after the response has been sent back to the client. Additional parameters are:
slicer: The slicing engine to use, defaults tocuraif not set, which is also the only supported slicer right now.gcode: Name of the GCODE file to generated, in the same location as the STL file. Defaults to the STL file name with extension.gcoif not set.position: Position of the object-to-slice’s center on the print bed. A dictionary containing bothxandycoordinate in mm is expectedprinterProfile: Name of the printer profile to use, if not set the default printer profile will be used.profile: Name of the slicing profile to use, if not set the default slicing profile of the slicer will be used.profile.*: Override parameters, theprofile.prefix will be stripped and the matching profile key will be overridden with the supplied value. Use this if you want to specify things that change often like a different temperature, filament diameter or infill percentage. Profile keys are slicer specific.select: Optional, if set totruethe file be selected for printing right after the slicing has finished. If the printer is not operational or already printing when this parameter is present and set totrue, the request will fail with a response of409 Conflictprint: Optional, if set totruethe file be selected and start printing right after the slicing has finished. If the printer is not operational or already printing when this parameter is present and set totrue, the request will fail with a response of409 Conflict. Note that if this parameter is set, the parameterselectdoes not need to be set, it is automatically assumed to betruetoo, otherwise no printing would be possible.
If consecutive slicing calls are made targeting the same GCODE filename (that also holds true if the default is used), the slicing job already running in the background will be cancelled before the new one is started. Note that this will also mean that if it was supposed to be directly selected and start printing after the slicing finished, this will not take place anymore and whether this will happen with the new sliced file depends entirely on the new request!
Upon success, a status code of 202 Accepted and a Abridged file or folder information in the response body will be returned.
Requires the
SLICEpermission.- copy
 Copies the file or folder to a new
destinationon the samelocation. Additional parameters are:destination: The path of the parent folder to which to copy the file or folder. It must already exist.
If there already exists a file or folder of the same name at
destination, the request will return a 409 Conflict. If thedestinationfolder does not exist, a 404 Not Found will be returned.Upon success, a status code of 201 Created and a Abridged file or folder information in the response body will be returned.
Requires the
FILES_UPLOADpermission.- move
 Moves the file or folder to a new
destinationon the samelocation. Additional parameters are:destination: The path of the parent folder to which to move the file or folder.
If there already exists a file or folder of the same name at
destination, the request will return a 409 Conflict. If thedestinationfolder does not exist, a 404 Not Found will be returned. If thepathis currently in use by OctoPrint (e.g. it is a GCODE file that’s currently being printed) a 409 Conflict will be returned.Upon success, a status code of 201 Created and a Abridged file or folder information in the response body will be returned.
Requires the
FILES_UPLOADpermission.
Example Select Request
POST /api/files/local/whistle_v2.gcode HTTP/1.1 Host: example.com Content-Type: application/json X-Api-Key: abcdef... { "command": "select", "print": true }HTTP/1.1 204 No ContentExample Slice Request
POST /api/files/local/some_folder/some_model.stl HTTP/1.1 Host: example.com Content-Type: application/json X-Api-Key: abcdef... { "command": "slice", "slicer": "cura", "gcode": "some_model.first_try.gcode", "printerProfile": "my_custom_reprap", "profile": "high_quality", "profile.infill": 75, "profile.fill_density": 15, "position": {"x": 100, "y": 100}, "print": true }HTTP/1.1 202 Accepted Content-Type: application/json { "origin": "local", "name": "some_model.first_try.gcode", "path": "some_folder/some_model.first_try.gcode", "refs": { "download": "http://example.com/downloads/files/local/some_folder/some_model.first_try.gcode", "resource": "http://example.com/api/files/local/some_folder/some_model.first_try.gcode" } }Example Copy Request
POST /api/files/local/some_folder/some_model.gcode HTTP/1.1 Host: example.com Content-Type: application/json X-Api-Key: abcdef... { "command": "copy", "destination": "some_other_folder/subfolder" }HTTP/1.1 201 Created Content-Type: application/json { "origin": "local", "name": "some_model.gcode", "path": "some_other_folder/subfolder/some_model.gcode", "refs": { "download": "http://example.com/downloads/files/local/some_other_folder/subfolder/some_model.gcode", "resource": "http://example.com/api/files/local/some_other_folder/subfolder/some_model.gcode" } }Example Move Request
POST /api/files/local/some_folder/and_a_subfolder HTTP/1.1 Host: example.com Content-Type: application/json X-Api-Key: abcdef... { "command": "move", "destination": "some_other_folder" }HTTP/1.1 201 Created Content-Type: application/json { "origin": "local", "name": "and_a_subfolder", "path": "some_other_folder/and_a_subfolder", "refs": { "resource": "http://example.com/api/files/local/some_other_folder/and_a_subfolder" } }- Parameters:¶
 location – The target location on which to send the command for is located, either
local(for OctoPrint’suploadsfolder) orsdcardfor the printer’s SD card (if available)path – The path of the file for which to issue the command
- JSON Parameters:¶
 command (string) – The command to issue for the file, currently only
selectis supportedprint (boolean) –
selectandslicecommand: Optional, whether to start printing the file directly after selection or slicing, defaults tofalse.slicer (string) –
slicecommand: The slicer to use, defaults to the default slicer.gcode (string) –
slicecommand: The name of the gcode file to create, defaults to the targeted stl’s file name with its extension changed to.gco(e.g. “test.stl” will be sliced to “test.gco” if not specified otherwise)profile (string) –
slicecommand: The slicing profile to use, defaults to the selected slicer’s default profile.profile.* (string) –
slicecommand: Overrides for the selected slicing profile, e.g. to specify a different temperature or filament diameter.printerProfile (string) –
slicecommand: The printer profile to use, defaults to the default printer profile.select (boolean) –
slicecommand: Optional, whether to select the file for printing directly after slicing, defaults tofalse
- Status Codes:¶
 200 OK – No error for a
selectcommand.202 Accepted – No error for a
slicecommand.400 Bad Request – If the
commandis unknown or the request is otherwise invalid415 Unsupported Media Type – If a
slicecommand was issued against something other than an STL file.404 Not Found – If
locationis neitherlocalnorsdcardor the requested file was not found409 Conflict – If a selected file is supposed to start printing directly but the printer is not operational or if a file is to be selected but the printer is already printing or if a file to be sliced is supposed to be selected or start printing directly but the printer is not operational or already printing.
Delete file¶
- DELETE /api/files/(string: location)/(path: path)¶
 Delete the selected
pathon the selectedlocation.If the file to be deleted is currently being printed, a 409 Conflict will be returned.
Returns a 204 No Content after successful deletion.
Requires the
FILES_DELETEpermission.Example Request
DELETE /api/files/local/whistle_v2.gcode HTTP/1.1 Host: example.com X-Api-Key: abcdef...- Parameters:¶
 location – The target location on which to delete the file, either
local(for OctoPrint’suploadsfolder) orsdcardfor the printer’s SD card (if available)path – The path of the file to delete
- Status Codes:¶
 204 No Content – No error
404 Not Found – If
locationis neitherlocalnorsdcardor the requested file was not found409 Conflict – If the file to be deleted is currently being printed
Data model¶
Retrieve response¶
Name  | 
Multiplicity  | 
Type  | 
Description  | 
|---|---|---|---|
  | 
0..*  | 
Array of File information items  | 
The list of requested files. Might be an empty list if no files are available  | 
  | 
0..1  | 
String  | 
The amount of disk space in bytes available in the local disk space (refers to OctoPrint’s   | 
Upload response¶
Name  | 
Multiplicity  | 
Type  | 
Description  | 
|---|---|---|---|
  | 
0..1  | 
Object  | 
(File only) Abridged information regarding the file that was just uploaded. If only uploaded to   | 
  | 
1  | 
The information regarding the file that was just uploaded to the local storage.  | 
|
  | 
0..1  | 
The information regarding the file that was just uploaded to the printer’s SD card.  | 
|
  | 
0..1  | 
(Folder only) Abridged information regarding the folder that was just created.  | 
|
  | 
1  | 
Boolean  | 
Whether any file processing after upload has already finished (  | 
  | 
0..1  | 
Boolean  | 
(File only) Whether the file that was just uploaded was selected for printing (  | 
  | 
0..1  | 
Boolean  | 
(File only) Whether the file that was just uploaded was started to print (  |