Started documenting OctoPrint's REST API
This commit is contained in:
1 parent
7a8e71b837
commit
09bed4e74f
6 files changed
+338
-20
No files matched your search
@@ -0,0 +1,264 @@
|
||||
.. _sec-api-fileops:
|
||||
|
||||
***************
|
||||
File operations
|
||||
***************
|
||||
|
||||
.. _sec-api-fileops-retrieveall:
|
||||
|
||||
Retrieve all files
|
||||
==================
|
||||
|
||||
.. http:get:: /api/gcodefiles
|
||||
|
||||
Retrieve information regarding all GCODE files currently available and regarding the disk space still available
|
||||
locally in the system.
|
||||
|
||||
Returns a :ref:`Retrieve response <sec-api-fileops-datamodel-retrieveresponse>`.
|
||||
|
||||
**Example request**:
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
GET /api/gcodefiles?apikey=abcdef HTTP/1.1
|
||||
Host: example.com
|
||||
|
||||
**Example response**:
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"files": [
|
||||
{
|
||||
"name": "whistle_v2.gcode",
|
||||
"bytes": 1468987,
|
||||
"size": "1.4MB"
|
||||
"date": "2013-05-21 23:15",
|
||||
"origin": "local"
|
||||
"gcodeAnalysis": {
|
||||
"estimatedPrintTime": "00:31:40",
|
||||
"filament": "0.79m"
|
||||
},
|
||||
"print": {
|
||||
"failure": 4,
|
||||
"success": 23,
|
||||
"last": {
|
||||
"date": "2013-11-18 18:00",
|
||||
"success": true
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "whistle_.gco",
|
||||
"bytes": 0,
|
||||
"size": "n/a",
|
||||
"date": "n/a",
|
||||
"origin": "sdcard"
|
||||
}
|
||||
],
|
||||
"free": "3.2GB"
|
||||
}
|
||||
|
||||
:query apikey: The API key to use for the request, either the global one or a user specific one (see
|
||||
:ref:`Authorization <sec-api-general-authorization>` for more details)
|
||||
:statuscode 200: No error
|
||||
:statuscode 401: If the API key is missing
|
||||
:statuscode 403: If the API key is invalid
|
||||
|
||||
.. _sec-api-fileops-retrievetarget:
|
||||
|
||||
Retrieve files from specific origin
|
||||
===================================
|
||||
|
||||
.. http:get:: /api/gcodefiles/(string:origin)
|
||||
|
||||
Retrieve information regarding the GCODE files currently available on the selected `origin` and regarding the
|
||||
disk space still available locally in the system.
|
||||
|
||||
Returns a :ref:`Retrieve response <sec-api-fileops-datamodel-retrieveresponse>`.
|
||||
|
||||
**Example request**:
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
GET /api/gcodefiles/local?apikey=abcdef HTTP/1.1
|
||||
Host: example.com
|
||||
|
||||
**Example response**:
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"files": [
|
||||
{
|
||||
"name": "whistle_v2.gcode",
|
||||
"bytes": 1468987,
|
||||
"size": "1.4MB"
|
||||
"date": "2013-05-21 23:15",
|
||||
"origin": "local"
|
||||
"gcodeAnalysis": {
|
||||
"estimatedPrintTime": "00:31:40",
|
||||
"filament": "0.79m"
|
||||
},
|
||||
"print": {
|
||||
"failure": 4,
|
||||
"success": 23,
|
||||
"last": {
|
||||
"date": "2013-11-18 18:00",
|
||||
"success": true
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"free": "3.2GB"
|
||||
}
|
||||
|
||||
:param target: The target location from which to retrieve the files. Currently only ``local`` and ``sdcard`` are
|
||||
supported, with ``local`` referring to files stored in OctoPrint's ``uploads`` folder and ``sdcard``
|
||||
referring to files stored on the printer's SD card (if available).
|
||||
:query apikey: The API key to use for the request, either the global one or a user specific one (see
|
||||
:ref:`Authorization <sec-api-general-authorization>` for more details)
|
||||
:statuscode 200: No error
|
||||
:statuscode 400: If `origin` is neither ``local`` nor ``sdcard``
|
||||
:statuscode 401: If the API key is missing
|
||||
:statuscode 403: If the API key is invalid
|
||||
|
||||
.. _sec-api-fileops-datamodel:
|
||||
|
||||
Datamodel
|
||||
=========
|
||||
|
||||
.. _sec-api-fileops-datamodel-retrieveresponse:
|
||||
|
||||
Retrieve response
|
||||
-----------------
|
||||
|
||||
.. list-table::
|
||||
:widths: 15 5 10 30
|
||||
:header-rows: 1
|
||||
|
||||
* - Name
|
||||
- Multiplicity
|
||||
- Type
|
||||
- Description
|
||||
* - ``files``
|
||||
- 0..*
|
||||
- Array of :ref:`File information items <sec-api-fileops-datamodel-fileinfo>`
|
||||
- The list of requested files. Might be an empty list if no files are available
|
||||
* - ``free``
|
||||
- 1
|
||||
- String
|
||||
- The amount of disk space available in the local disk space (refers to OctoPrint's ``uploads`` folder)
|
||||
|
||||
.. _sec-api-fileops-datamodel-fileinfo:
|
||||
|
||||
File information
|
||||
----------------
|
||||
|
||||
.. list-table::
|
||||
:widths: 15 5 10 30
|
||||
:header-rows: 1
|
||||
|
||||
* - Name
|
||||
- Multiplicity
|
||||
- Type
|
||||
- Description
|
||||
* - ``name``
|
||||
- 1
|
||||
- String
|
||||
- The name of the file
|
||||
* - ``bytes``
|
||||
- 1
|
||||
- Number
|
||||
- The size of the file in bytes. Only available for ``local`` files, always ``0`` for files stored on ``sdcard``.
|
||||
* - ``size``
|
||||
- 1
|
||||
- String
|
||||
- The size of the file in a human readable format. Only available for ``local`` files, set to ``n/a`` for files
|
||||
stored on ``sdcard``.
|
||||
* - ``date``
|
||||
- 1
|
||||
- String representing a date and time in the format ``YYYY-MM-DD HH:mm``
|
||||
- The date and time this files was uploaded. Only available for ``local`` files,
|
||||
set to ``n/a`` for files stored on ``sdcard``.
|
||||
* - ``origin``
|
||||
- 0..1
|
||||
- String, either ``local`` or ``sdcard``
|
||||
- The origin of the file, ``local`` when stored in OctoPrint's ``uploads`` folder, ``sdcard`` when stored on the
|
||||
printer's SD card (if available)
|
||||
* - ``gcodeAnalysis``
|
||||
- 0..1
|
||||
- :ref:`GCODE analysis information <sec-api-fileops-datamodel-gcodeanalysis>`
|
||||
- Information from the analysis of the GCODE file, if available.
|
||||
* - ``prints``
|
||||
- 0..1
|
||||
- :ref:`Print information <sec-api-fileops-datamodel-prints>`
|
||||
- Information regarding prints of this file, if available.
|
||||
|
||||
.. todo::
|
||||
Make fields which are not available for ``sdcard`` (``bytes``, ``size``, ``date``) optional and don't include them
|
||||
in the output if not available. Clients should be able to decide on their own what to display in such a case.
|
||||
|
||||
.. _sec-api-fileops-datamodel-gcodeanalysis:
|
||||
|
||||
GCODE analysis information
|
||||
--------------------------
|
||||
|
||||
.. list-table::
|
||||
:widths: 15 5 10 30
|
||||
:header-rows: 1
|
||||
|
||||
* - Name
|
||||
- Multiplicity
|
||||
- Type
|
||||
- Description
|
||||
* - ``estimatedPrintTime``
|
||||
- 1
|
||||
- String representing a duration in the format ``HH:mm:ss``
|
||||
- The estimated print time of the file
|
||||
* - ``filament``
|
||||
- 1
|
||||
- String
|
||||
- The estimated usage of filament (length in meters and volume in cubic centimeters) in a human readable format.
|
||||
Example: ``1.89m / 11.90cm³``
|
||||
|
||||
|
||||
.. _sec-api-fileops-datamodel-prints:
|
||||
|
||||
Print information
|
||||
-----------------
|
||||
|
||||
.. list-table::
|
||||
:widths: 15 5 10 30
|
||||
:header-rows: 1
|
||||
|
||||
* - Name
|
||||
- Multiplicity
|
||||
- Type
|
||||
- Description
|
||||
* - ``failure``
|
||||
- 1
|
||||
- Number
|
||||
- The number of failed prints on record for the file
|
||||
* - ``success``
|
||||
- 1
|
||||
- Number
|
||||
- The number of successful prints on record for the file
|
||||
* - ``last``
|
||||
- 0..1
|
||||
- Object
|
||||
- Information regarding the last print on record for the file
|
||||
* - ``last.date``
|
||||
- 1
|
||||
- String representing a date and time in the format ``YYYY-MM-DD HH:mm``
|
||||
- Date and time when the file was printed last
|
||||
* - ``last.success``
|
||||
- 1
|
||||
- Boolean
|
||||
- Whether the last print on record was a success (``true``) or not (``false``)
|
||||
@@ -0,0 +1,47 @@
|
||||
.. _sec-api-general:
|
||||
|
||||
*******************
|
||||
General information
|
||||
*******************
|
||||
|
||||
.. _sec-api-general-authorization:
|
||||
|
||||
Authorization
|
||||
=============
|
||||
|
||||
OctoPrint's API expects an API key to be supplied with each request. This API key can be either the globally
|
||||
configured one (compare :ref:`fig-api-general-globalapikey`) or a user specific one if "Access Control" is enabled
|
||||
(compare :ref:`fig-api-general-userapikey`). Users are able to generate and revoke their custom API key via the
|
||||
"Change password" dialog (compare :ref:`fig-api-general-changepassword`).
|
||||
|
||||
The API key must be supplied as query parameter ``apikey`` to each request, e.g.
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
GET /api/gcodefiles/local?apikey=abcdef HTTP/1.1
|
||||
Host: example.com
|
||||
|
||||
.. todo::
|
||||
Look into allowing to supply the API key as a custom ``Authorization`` scheme.
|
||||
|
||||
.. _fig-api-general-globalapikey:
|
||||
.. figure:: ../images/settings-global-api-key.png
|
||||
:align: center
|
||||
:alt: Global API key in the API settings
|
||||
|
||||
The global API key can be found in the "API" settings
|
||||
|
||||
.. _fig-api-general-userapikey:
|
||||
.. figure:: ../images/settings-user-api-key.png
|
||||
:align: center
|
||||
:alt: User specific API key location in user list
|
||||
|
||||
The user list in the "Access Control" settings shows the API key for users (if available)
|
||||
|
||||
.. _fig-api-general-changepassword:
|
||||
.. figure:: ../images/change-password-api-key.png
|
||||
:align: center
|
||||
:alt: API key options in "Change password" dialog
|
||||
|
||||
The API key options in the "Change password" dialog. Users can generate and revoke their custom API key here.
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
.. _sec-api:
|
||||
|
||||
#################
|
||||
API Documentation
|
||||
#################
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
general.rst
|
||||
fileops.rst
|
||||
Reference in new issue
Block a user