Getting list of "out of sync" items for a device via API?

  • syncthing version: syncthing v1.20.4 "Fermium Flea" (go1.18.4 linux-amd64) 2022-08-02 08:10:29 UTC [noupgrade]
  • OS: Ubuntu 22.04

I’ve been trying to (programmatically) get a list of out of sync items for a specific device, basically whatever is displayed in remoteNeededFilesModalView.

From reading the API docs, I figured this is the closest API method there is for this functionality:

curl -X GET -H "X-API-Key: <api key>" http://localhost:8384/rest/db/remoteneed?folder=<folder id>&device=<device ID>

However, the API call seems to return thousands of entries to me while in the web interface I only have a few dozen (they are mostly symlinks and files with special characters that my Android device isn’t able to ‘accept’).

I dug a bit and it seems that this function is responsible for the API call… but can’t tell straightaway what’s the issue syncthing/model.go at b10d106a55cb9e7e2da152206e4ac59fa3549c02 · syncthing/syncthing · GitHub

What am I doing wrong? :slight_smile: Thanks!

Your approach sounds about right, as documented here: GET /rest/db/remoteneed — Syncthing documentation

Have you looked at the GUI code whether it does any filtering on the results? Can you find some common factor about the extra items not displayed in the GUI?

1 Like

Yep, stared at the files for a bit, but didn’t notice any common pattern. But after a bit more poking and enabling debug API logs in the GUI, I found the issue: TLDR need to put the curl query in quotes, in particular the ampersand &. Kinda odd, didn’t realize it mattered unless the ampersand had a space after it.

What happened in my case is the query string was truncated at the first ampersand, so it ended up only querying http://localhost:8384/rest/db/remoteneed?folder=<folder id>, and I assume it returns the diff for all device IDs, which explains so many files :slight_smile:

After putting it in quotes, it returns same results as gui!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.