> For the complete documentation index, see [llms.txt](https://docs.theseus.us/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.theseus.us/cyclops/developers/edge-api/maps-port-5000.md).

# Maps (port 5000)

{% hint style="warning" %}
These endpoints belong to the legacy API on port `5000`, not the v2 API on port `5050`. Use them only for map management, which v2 does not support yet. They may be replaced by v2 endpoints in a later release.
{% endhint %}

Use these endpoints to install maps on the Cyclops computer and choose which one Cyclops uses.

| Method | Path                     | Purpose                              |
| ------ | ------------------------ | ------------------------------------ |
| `GET`  | `/api/maps`              | List installed maps                  |
| `GET`  | `/api/maps/current`      | Read the active map                  |
| `POST` | `/api/upload/maps`       | Upload and install a map             |
| `GET`  | `/api/extraction/status` | Follow the progress of a map install |
| `POST` | `/api/maps/set`          | Choose the active map                |
| `POST` | `/api/maps/delete`       | Delete an installed map              |

The base URL is `http://192.168.218.100:5000`.

## Responses

This API uses a different response format from v2. Every JSON response has a `code` field set to `SUCCESS` or `ERROR`. On error, `message` explains why:

```json
{
  "code": "ERROR",
  "message": "Map 'a1b2c3d4_my_area' not found"
}
```

Always check `code`, not only the HTTP status.

## Installing a map

A complete install takes four steps:

1. Upload the map archive with `POST /api/upload/maps`.
2. Poll `GET /api/extraction/status` until `phase` is `complete`.
3. Make it the active map with `POST /api/maps/set`.
4. Set a home position inside the new map with [`POST /api/v2/system/home-position`](https://docs.theseus.us/cyclops/developers/edge-api/home-position.md#set-the-home-position). This restarts Cyclops so it loads the new map.

{% hint style="warning" %}
Choosing a map does not restart Cyclops. Cyclops keeps using the previous map until it restarts, so always finish with step 4. Only change maps on the ground.
{% endhint %}

## List installed maps

`GET /api/maps`

Maps are sorted newest first.

```bash
curl http://192.168.218.100:5000/api/maps
```

```json
{
  "code": "SUCCESS",
  "data": [
    {
      "name": "a1b2c3d4_my_area",
      "size": 2147483648,
      "size_human": "2.0 GB",
      "modified": 1759415460.5,
      "completed": true,
      "checksum": "9f2c...e41a",
      "format_version": "1.2.0",
      "min_firmware_version": "1.3.0"
    }
  ]
}
```

| Field                  | Description                                                                   |
| ---------------------- | ----------------------------------------------------------------------------- |
| `name`                 | Map name. Use it to select or delete the map.                                 |
| `size`                 | Installed size, in bytes.                                                     |
| `modified`             | Last time the map was changed on the device, in seconds since the Unix epoch. |
| `completed`            | `false` if the install did not finish. Delete the map and upload it again.    |
| `checksum`             | SHA-256 of the uploaded archive. `null` if unknown.                           |
| `format_version`       | Map format version.                                                           |
| `min_firmware_version` | Oldest Cyclops software version that can use this map.                        |

## Read the active map

`GET /api/maps/current`

```bash
curl http://192.168.218.100:5000/api/maps/current
```

```json
{
  "code": "SUCCESS",
  "data": {
    "active_map": "a1b2c3d4_my_area"
  }
}
```

`active_map` is `null` when no map is selected.

## Upload a map

`POST /api/upload/maps`

Uploads a map archive and installs it. The request body is the raw `.tar.gz` file, not a form upload. Get the archive from Vozilla. See [Uploading maps](https://docs.theseus.us/vozilla-gcs-software/vozilla-app/maps/uploading-maps.md).

### Headers

| Header           | Description                                                                                      |
| ---------------- | ------------------------------------------------------------------------------------------------ |
| `filename`       | Archive file name, URL-encoded. Required. Must end in `.tar.gz`.                                 |
| `checksum`       | SHA-256 of the archive, as hex. Optional. If set, the upload fails when the data does not match. |
| `Content-Length` | Archive size, in bytes. The device uses it to check that it has enough free space.               |
| `Content-Type`   | `application/octet-stream`                                                                       |

The map name is the file name without `.tar.gz`. Keep the original file name: the archive contains a folder with that name, and the install fails if they do not match.

### Example

```bash
curl -X POST http://192.168.218.100:5000/api/upload/maps \
  -H "filename: a1b2c3d4_my_area.tar.gz" \
  -H "checksum: $(sha256sum a1b2c3d4_my_area.tar.gz | cut -d' ' -f1)" \
  -H "Content-Type: application/octet-stream" \
  --upload-file a1b2c3d4_my_area.tar.gz
```

`--upload-file` streams the file and sets `Content-Length`. Do not use `--data-binary @file` for large maps, because curl then loads the whole file into memory.

The device unpacks the archive while it receives it. The response arrives once all data is received. The device then validates the map in the background.

```json
{
  "code": "SUCCESS",
  "message": "Upload received, extraction started for a1b2c3d4_my_area.tar.gz",
  "map_name": "a1b2c3d4_my_area",
  "size": 2147483648,
  "checksum": "9f2c...e41a",
  "extraction_queued": true
}
```

Large maps can take a long time to upload. Do not set a short timeout on this request.

### Errors

| Status | Cause                                                                                                                          |
| ------ | ------------------------------------------------------------------------------------------------------------------------------ |
| `400`  | The `filename` header is missing or does not end in `.tar.gz`.                                                                 |
| `500`  | The upload failed, for example a checksum mismatch or an archive without a folder named after the map. `message` explains why. |
| `507`  | Not enough free space. The response includes `required_bytes` and `free_bytes`. Delete maps you no longer need and retry.      |

## Follow the install

`GET /api/extraction/status`

Returns the progress of the latest map install. Poll it every few seconds after the upload returns.

```bash
curl http://192.168.218.100:5000/api/extraction/status
```

```json
{
  "code": "SUCCESS",
  "data": {
    "in_progress": true,
    "map_name": "a1b2c3d4_my_area",
    "phase": "validating",
    "message": "Validating map tiles",
    "current": 120,
    "total": 400,
    "percent": 30,
    "unit": "tiles",
    "error": null
  }
}
```

| `phase`      | Meaning                                     |
| ------------ | ------------------------------------------- |
| `extracting` | The archive is being received and unpacked. |
| `validating` | The device is checking the map.             |
| `complete`   | The map is installed and can be selected.   |
| `failed`     | The install failed. `error` explains why.   |

The device keeps this status in memory only. If it is empty, for example after the Cyclops computer restarts, check `completed` for the map in `GET /api/maps` instead.

## Choose the active map

`POST /api/maps/set`

### Request body

| Field      | Type   | Description                         |
| ---------- | ------ | ----------------------------------- |
| `map_name` | string | Name of an installed map. Required. |

```bash
curl -X POST http://192.168.218.100:5000/api/maps/set \
  -H "Content-Type: application/json" \
  -d '{"map_name": "a1b2c3d4_my_area"}'
```

```json
{
  "code": "SUCCESS",
  "data": {
    "active_map": "a1b2c3d4_my_area",
    "message": "Active map set to a1b2c3d4_my_area"
  }
}
```

Then set the home position, as described in [Installing a map](#installing-a-map).

### Errors

| Status | Cause                                                     |
| ------ | --------------------------------------------------------- |
| `400`  | `map_name` is missing, or the map install did not finish. |
| `404`  | No map with that name is installed.                       |

## Delete a map

`POST /api/maps/delete`

Deletes an installed map from the Cyclops computer.

### Request body

| Field            | Type   | Description                                                |
| ---------------- | ------ | ---------------------------------------------------------- |
| `map_name`       | string | Name of the map to delete. Required.                       |
| `new_active_map` | string | Map to make active if you delete the active map. Optional. |

```bash
curl -X POST http://192.168.218.100:5000/api/maps/delete \
  -H "Content-Type: application/json" \
  -d '{"map_name": "a1b2c3d4_my_area"}'
```

```json
{
  "code": "SUCCESS",
  "message": "Successfully deleted a1b2c3d4_my_area",
  "home_position_result": null
}
```

If you delete the active map without `new_active_map`, no map is active afterwards. If you pass `new_active_map`, set a home position inside it next so Cyclops restarts with it. If the new map cannot be selected, the map is still deleted and the response includes `new_active_map_error`.

### Errors

| Status | Cause                                                         |
| ------ | ------------------------------------------------------------- |
| `400`  | `map_name` is missing, or no map with that name is installed. |
