REST API - Get device name for devices connected via API

Apologies if “Development” is the wrong category. Since the REST and Events APIs are documented under “Development” in the docs, it seemed appropriate.

I am writing a UI which allows the user to connect to remote machines without the user of the Syncthing GUI. It’s following these steps:

  • Find nearby devices: /rest/system/discovery
  • Connect to a device: /rest/config/devices (POST)

I don’t see a way to find out the Device Name of the discovered device prior to connecting the device. However, if I choose an arbitrary name for the POST, Syncthing then thinks that’s what I want as a Device Name. If I leave the ‘name’ key blank in the POST, Syncthing displays the first 7 letters of the Device ID (in the GUI) instead of using the hostname and returns "name": "" from GETs to /rest/config/devices.

Using only the API, is there a way to get the correct Device Name (as Syncthing would display under normal circumstances) from the discovery API or to patch a connected device, shortly after connecting to it, with its correct name? The user won’t have any access to the Syncthing GUI or CLI.

Since this is only for informational/display purposes, the Device ID isn’t helpful to the user, as it doesn’t have any meaning to them.

Apologies if I overlooked something in the documentation; the API is really thorough, so I was quite surprised when I couldn’t figure out how to do this. I figured I would ask here before reading through the Syncthing source, since I’d prefer not to replicate behaviour Syncthing already provides.

Thanks so much!

2 Likes

The name is not included in the discovery, so there is no way to know it prior to having actually connected to the device. If the device is added to the config with a blank name, Syncthing will update the name once the devices have connected. At that point you can get it from the config.

3 Likes

So it does! You’ll have to excuse me for not getting that far earlier… I’d only connected the one side (many times) but I’d never bothered to connect the remote side. It’s another OS and this little Electron app was misbehaving enough on that side to discourage me from going all the way.

Very cool. Thanks so, so much for your quick reply. :pray: (And for Syncthing, in general. It’s rad.)

3 Likes