# keco factory

Send a sliced plate to one of keco's printers, and watch it print: https://factory.kecorobotics.com

Every call takes an API key as a Bearer token. Make one on the page (https://factory.kecorobotics.com, API keys), and keep it in an
environment variable, never in a file you commit:

    export KECO_FACTORY_KEY=kf_…

## The printers

    curl -s -H "Authorization: Bearer $KECO_FACTORY_KEY" https://factory.kecorobotics.com/api/printers

Each printer has an `id`, a `name`, its `model` (as Bambu Studio names it: "Bambu Lab A1"), the `filaments`
loaded, its `state` (IDLE, RUNNING, PAUSE, FINISH, FAILED…), `progress` (0–100) and `remaining_s` while it prints,
and `ready`: whether it would take a print now. When it would not, `why_not` says why (busy, offline, its bed not cleared since the last print…).

## Printing

A print is a sliced Bambu 3MF (`.gcode.3mf`, exported from Bambu Studio, or `keco slice`), sliced for that
printer's model. It goes to one printer, now: factory is not a queue, and a printer that is not `ready` refuses it
(409, saying why).

    curl -s -H "Authorization: Bearer $KECO_FACTORY_KEY" \
      -F file=@part.gcode.3mf -F printer="A1 by the door" -F plate=1 https://factory.kecorobotics.com/api/jobs

`printer` is its id or its name; `plate` is which plate of the file (default 1). The answer is the job: its `id`
and `state`.

## Watching a job

    curl -s -H "Authorization: Bearer $KECO_FACTORY_KEY" https://factory.kecorobotics.com/api/jobs/<id>

`state` goes `sent` (the printer's hub has not taken it yet) → `pending` (queued on the printer) → `printing` →
`done`, `failed` (with `error`) or `cancelled`. The printer's own `progress` and `remaining_s` are on
`/api/printers`. Ask every 30 s or so; there is no need to ask faster.

    curl -s -H "Authorization: Bearer $KECO_FACTORY_KEY" https://factory.kecorobotics.com/api/jobs              # the latest, newest first

## Stopping, pausing, the bed

    curl -s -X POST -H "Authorization: Bearer $KECO_FACTORY_KEY" https://factory.kecorobotics.com/api/jobs/<id>/cancel
    curl -s -X POST -H "Authorization: Bearer $KECO_FACTORY_KEY" https://factory.kecorobotics.com/api/printers/<id>/pause     # and /resume
    curl -s -X POST -H "Authorization: Bearer $KECO_FACTORY_KEY" https://factory.kecorobotics.com/api/printers/<id>/clear-plate

After a print, a printer takes nothing until someone says its bed is clear. Only say so when a person has taken
the print off: a printer that starts on a full bed crashes into it.

Every route and shape: https://factory.kecorobotics.com/api/docs
