> For the complete documentation index, see [llms.txt](https://docs.ceruleansonar.com/c/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ceruleansonar.com/c/sonarview/sonarlink/sonarlink-api-by-example.md).

# Sonarlink API by Example

A walk through SonarLink's HTTP API: find devices, start a session from a plan, change a device's settings, and get data out, live or recorded.

### Prerequisites

The examples use the `http` command from [HTTPie](https://httpie.io/cli), but any HTTP client should work. For POST requests, send a JSON body - this is the implicit behavior of `http` in the below examples.

SonarView's desktop app runs SonarLink for you, on port 7077 of the machine it runs on. On BlueOS, SonarLink runs as an extension, on port 7077 of the vehicle's computer.

Every endpoint is documented, and can be tried out, at <http://localhost:7077/docs>, which SonarView also links from its Support Resources menu (in the menu bar: 🛟, API Documentation). Endpoints tagged `internal` are SonarView's own and may change; prefer the `public` ones.

{% stepper %}
{% step %}

### Check SonarLink status

```sh
http -b localhost:7077/status
```

```json
{
   "sonarlink_version": "1.15.0",
   "os_hostname": "blueos.local",
   "sessions": [],
   "serial_okay": true
}
```

This tells us that SonarLink is running, with no active sessions.
{% endstep %}

{% step %}

### Discover devices

```sh
http -b POST localhost:7077/discover_devices
```

```json
{
   "devices": [
      {
         "url": "tcp://10.0.128.131:51200",
         "product_id": "os450",
         "connectable": true,
         "variant": "AIO",
         "firmware_version": "1.5.21"
      }
   ]
}
```

One device: an Omniscan 450. SonarLink waits 2 seconds for devices to answer; for slow networks, wait longer with `wait_s`, and for devices a broadcast doesn't reach, name their addresses in `hosts`:

```sh
http -b POST localhost:7077/discover_devices wait_s:=5 'hosts[]=192.168.2.2'
```

{% endstep %}

{% step %}

### Get session plans

A session plan is a set of devices, and optionally a vehicle, configured in SonarView's [Session Configurations](https://docs.ceruleansonar.com/c/sonarview/session-configurations.md).

```sh
http -b localhost:7077/session_plans
```

```jsonc
{
   "plans": [
      {
         "session_plan_name": "os450 and bluerov",
         "devices": [
            {
               "url": "tcp://10.0.128.131:51200",
               "product_id": "os450",
               "device_id": 1,
               "nickname": "Omniscan",
               "options": {
                  "transducer_deg": 0,
                  "imu_deg": 0,
               },
            },
         ],
         "platform": {
            "protocol": "mavlink2rest",
            "url": "ws://blueos.local:6040/v1/ws/mavlink?filter=ATTITUDE|GLOBAL_POSITION_INT|...",
            "options": {
               // system_id, periodic_messages omitted for brevity
            },
            "model": "blue_rov",
            "nickname": "BlueROV",
         },
         "is_active": false,
      },
   ],
}
```

One plan, "os450 and bluerov", not currently running.
{% endstep %}

{% step %}

### Start a session

Starting sessions from plans is the easiest way to use the API, since a plan has a stable name, and you don't need to track down the session's id, a number that changes each time a session starts.

```sh
http -b localhost:7077/start_session session_plan_name="os450 and bluerov"
```

```json
{
   "session_id": 1,
   "is_recording": false
}
```

The session's id is 1. Starting a plan that's already running returns the session running from it, rather than starting another.

The endpoints below that act on a running session take a `session` parameter: either the name of the plan the session was started from (a string), or the session's id (a number). With HTTPie, `session="os450 and bluerov"` sends a string and `session:=1` sends a number.

{% hint style="info" %}
Earlier versions of SonarLink named the session with `session_id`. It still works, but is deprecated: use `session` instead.
{% endhint %}
{% endstep %}

{% step %}

### Check active sessions

`/status` lists the running sessions, each device's connection status and options, and the apps connected to each session.

```sh
http -b localhost:7077/status
```

```jsonc
{
   "sonarlink_version": "1.15.0",
   "os_hostname": "blueos.local",
   "sessions": [
      {
         "session_id": 1,
         "session_uptime": 12.3,
         "session_devices": [
            {
               "url": "tcp://10.0.128.131:51200",
               "options": {
                  "transducer_deg": 0,
                  "imu_deg": 0,
                  "channel_number": 0,
                  "doppler_enable": true,
                  "enable": false,
                  "range": 25,
                  "gain_index": "auto",
                  "profile_resolution": 1200,
                  "injection_level": 0,
               },
               "device_id": 1,
               "product_id": "os450",
               "nickname": "Omniscan",
               "status": "CONNECTED",
            },
         ],
         "session_platform": {
            "protocol": "mavlink2rest",
            // url, options, model, and nickname as in the plan
            "device_id": 2,
            "status": "CONNECTED",
         },
         "session_clients": [],
         "session_plan_name": "os450 and bluerov",
         "is_recording": false,
      },
   ],
   "serial_okay": true,
}
```

The device's options include the settings SonarLink set it up with, like `enable` (is it pinging?) and `range`, even where the plan didn't give them.
{% endstep %}

{% step %}

### Change device settings

Start the Omniscan pinging, out to 10 meters:

```sh
http -b localhost:7077/device_options session="os450 and bluerov" device_id:=1 'options[enable]:=true' 'options[range]:=10'
```

```json
{
   "transducer_deg": 0,
   "imu_deg": 0,
   "channel_number": 0,
   "doppler_enable": true,
   "enable": true,
   "range": 10,
   "gain_index": "auto",
   "profile_resolution": 1200,
   "injection_level": 0
}
```

SonarLink sends the device the new settings and returns the newly updated options. Options you leave out keep their values.

The same request, naming the session by its id:

```sh
http -b localhost:7077/device_options session:=1 device_id:=1 'options[enable]:=true' 'options[range]:=10'
```

{% endstep %}

{% step %}

### Record a session

Start recording:

```sh
http -b localhost:7077/logging session="os450 and bluerov" enable:=true
```

SonarLink records the session into a directory named after its session plan, within the log directory set in SonarView's settings. To name the directory yourself, add `subpath="my survey"`.

Stop recording:

```sh
http -b localhost:7077/logging session="os450 and bluerov" enable:=false
```

{% endstep %}

{% step %}

### Get recent data

Each running session keeps its last few seconds of data. Fetch them by session plan name or session id:

```sh
http --download 'localhost:7077/recent_data?session=os450 and bluerov&duration_s=30'
http --download 'localhost:7077/recent_data?session=1&duration_s=30'
```

In a URL, a `session` of only digits is taken as a session id, and anything else as a session plan name.

The response is in the packet format svlog recordings use, starting with a `SONARLINK_JSON` packet describing the session, so it can be read on its own. SonarLink keeps about 16 MB per session, so with a lot of data, a long window may start later than asked.
{% endstep %}

{% step %}

### Stream live data

`/join` streams a session's data for as long as the connection stays open. Save it to a file, and press Ctrl-C to stop:

```sh
http -b --stream 'localhost:7077/join?session=1' > live.svlog
```

`--stream` makes HTTPie write the data as it arrives, rather than holding it back. The data is binary, in the same packet format as svlog recordings, starting with a `SONARLINK_JSON` packet describing the session, so it's saved here as an `.svlog` file. To process it live instead, pipe it to a program that parses [Cerulean Ping Protocol](https://docs.ceruleansonar.com/c/cerulean-ping-protocol) packets.

WebSocket clients can connect to `ws://localhost:7077/connect_ws?session=1` instead. Add `&write=1` to also send data to the session's devices.
{% endstep %}

{% step %}

### End a session

```sh
http -b localhost:7077/end_session session="os450 and bluerov"
```

Or by its id:

```sh
http -b localhost:7077/end_session session:=1
```

SonarLink tells the devices it set up to stop pinging, and disconnects from them.
{% endstep %}
{% endstepper %}

## Working with recorded data

{% stepper %}
{% step %}

### List recordings

```sh
http -b localhost:7077/list_logs
```

```json
{
   "logs": [
      {
         "plan": "os450 and bluerov",
         "filename": "2026-06-19-12-42.svlz",
         "url": "/log/os450%20and%20bluerov/2026-06-19-12-42.svlz",
         "size": 100269794,
         "modified_at": "2026-06-19T12:25:59.000Z"
      }
   ]
}
```

SonarLink records each session into a directory of its own, named after its session plan, within the log directory set in SonarView's settings.
{% endstep %}

{% step %}

### Download a recording

Fetch a recording's `url`, as `/list_logs` gives it - `/log/{plan}/{filename}`:

```sh
http --download 'localhost:7077/log/os450 and bluerov/2026-06-19-12-42.svlz'
```

```
HTTP/1.1 200 OK
Content-Disposition: attachment; filename="2026-06-19-12-42.svlz"
Content-Length: 100269794
Content-Type: application/octet-stream

Downloading to 2026-06-19-12-42.svlz
Done. 100.3 MB in 00:0.27091 (370.1 MB/s)
```

{% endstep %}
{% endstepper %}

## Troubleshooting

### Error log

SonarLink's log is saved in a jsonl (newline-delimited JSON) format. You can use `pino-pretty` to get a friendlier output. The log includes server-emitted logs and may also include messages from the SonarView graphical client.

```sh
http -b localhost:7077/errlog | npx pino-pretty
```

```
[13:20:35.087] INFO (23942): Starting sonarlink...
[13:20:35.111] INFO (23942): Config file okay
    path: "/Users/me/Library/Application Support/SonarView/config.json"
[13:20:35.116] INFO (23942): SonarLink http server started on port 7077
```
