# Load and unload

> Open the door, confirm the load, and finish one prep station at a time.

At each stop there are two calls: `start` opens the door, `finish` confirms. Only `finish` moves the delivery on.

| Stop | Open the door | Confirm | Then |
| --- | --- | --- | --- |
| Pickup (`at_pickup`) | `POST /delivery/{id}/load/start` | `POST /delivery/{id}/load/finish` | `going_to_dropoff` |
| Dropoff (`at_dropoff`) | `POST /delivery/{id}/unload/start` | `POST /delivery/{id}/unload/finish` | `delivered` |

- `finish` closes the door and sends the bot on.
- `finish` in any other state is a `400`, also right after a successful `finish`. Do not retry it blindly: read the delivery.

## Several prep stations

An order can come from several stations, like counters in a food hall. Create one package per station:

```json
"packages": [
  { "reference": "burger-pkg", "station": "Burger Shop" },
  { "reference": "pizza-pkg", "station": "Neapolitan" }
]
```

Each station then finishes its own part with [`POST /delivery/{id}/load/finish/target`](https://docs.remi.robot.com/delivery/reference#finishLoadTarget):

```json
{ "station": "Burger Shop" }
```

Or one package with `{ "package": "burger-pkg" }`. Each package reports `loaded`, and the bot leaves when every package is loaded. Repeating a target is safe.

> After a `409` on the targeted route, do not fall back to the plain `load/finish`: it loads everything and sends the bot off.

## Bots whose lid a person closes

On bots with `manual_close_door: true` (see [Get a bot](https://docs.remi.robot.com/delivery/reference#getBot)), `finish` does nothing: the load or unload completes a few seconds after the lid reports closed. Calling `finish` anyway is harmless.

## Dropoff auto-close

At locations where Robot.com turned it on, `unload/start` starts a timer. When it runs out, the bot closes its lid, checks the compartment is empty, and completes the delivery as `unload/finish` would. A later `unload/finish` answers `200`.

## The door on its own

The Engine API can open or close a bot's door outside this flow: [Open or close a bot door](https://docs.remi.robot.com/engine/reference#setDoorByBot). It needs a key with the `engine` scope.
