Rest API sync now not working

I’m trying to get syncthing to sync on demand from a bash script, but when I test this at the terminal it doesn’t work:

pi@raspberrypi:~ $ curl -X POST http://127.0.0.1:8384/rest/db/scan

CSRF Error

what am I doing wrong?

I also tried it with a specific folder like this:

curl -X POST http://127.0.0.1:8384/rest/db/scan?folder=default&sub="/home/pi/Seagate Backup Plus Drive/NVIDIA_SHIELD/SyncthingFolders/ZettlrMarkor"

with and without quotes (because of the spaces in the filename (which I can’t rename as the usb drive is hard-wire named that)) and that gave a different error, but all I need is “sync all folders now”

Thanks,

  • Dave

Please refer to REST API — Syncthing v1 documentation, specifically the paragraph about using an api key.

Thanks. I generated the API key in the GUI and then tried this:

david@hpb:~$ curl -X POST -H “X-API-Key: 4iNg(xxxx)yuCdh” http://127.0.0.1:8384/rest/db/scan?folder=default

CSRF Error

I found this to test (from here: How to integrate your Syncthing, and even make it talk - Share your Projects! - Home Assistant Community)

Try if it works

Using curl in a terminal window, you can easily check if the REST API works. Let’s assume Syncthing runs on a machine called studio1 in the local network. Type the following command, substituting server name and API key with your own:

curl -X GET -H "X-API-Key: Ziegheizee7do7Je8uiMiepu8Abeevee" http://studio1:8384/rest/system/version

You should get a JSON response like …

… but I didn’t get the proper response, instead got

david@Orby:~$ curl -X GET -H “X-API-Key: tTeDxxxVbPAn” http://127.0.0.1:8384/rest/system/version

CSRF Error

Any hints about what I am doing wrong?

Is it a simple copy error? ” does not equal "

this DOES work at one computer:

curl -X POST -H “X-API-Key: ZLSvqmxxx35UCxu” http://127.0.0.1:8384/rest/db/scan?

and so does this:

curl -X POST -H “X-API-Key: ZLSvqmxxx35UCxu” http://127.0.0.1:8384/rest/db/scan?folder=(folder ID)

v1.13.1, Linux (64-bit Intel/AMD) “Fermium Flea” Build 2021-01-11

I’ll check the version number at home later - maybe different versions work differently? (should be the same version I think)

Double check the api key. Maybe there’s a simple copy&paste error, maybe you are copying from the wrong config.xml file (you can copy from the web UI to be sure that’s not the case).

Oh, that’s what that other post meant (d’oh!)

thank you so much, I’ll try that again :slight_smile:

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