Syncthing API Examples
local device_id: 6Q5DZNK-OUR81B9-7XVBNEW-G98K9LW-E7ZI313-MSF2DZJ-YU0POJ9-N4FGYV9
remote device_id: N098QOW-3F17I07-NJ7LT0T-PC5YC33-ULTQJZD-JTMVKP1-8A283AM-DD79XNL
local apikey: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn
remote apikey: CbWoJOlVgdftUfN1kBoueAKO4SZKB5c0
Get API Key from config.xml
# grep apikey config.xml
<apikey>35P6t2XKq9KKF0R5b4JRu58m1uZGplLn</apikey>
This response indicates the wrong key is being used:
# curl -s -X GET -H "X-API-Key: LEWiudzxdETBzRk28BFLGQQ63M5Q0X4h" http://localhost:8384/rest/config/options
CSRF Error
Get all options:
# curl -s -X GET -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" http://localhost:8384/rest/config/options
Set an option, relaysEnabled, from true to false:
# grep -i relays config.xml
<relaysEnabled>true</relaysEnabled>
This indicates the wrong type of payload is being sent:
# curl -s -X PATCH -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" -d '[ { "relaysEnabled": false } ]' http://localhost:8384/rest/config/options
json: cannot unmarshal array into Go value of type config.OptionsConfiguration
Let’s correct that:
# curl -s -X PATCH -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" -d '{ "relaysEnabled": false }' http://localhost:8384/rest/config/options
# grep -i relays config.xml
<relaysEnabled>true</relaysEnabled>
Show me all the devices:
# curl -s -X GET -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" http://localhost:8384/rest/config/devices
Add a device:
# curl -s -X PUT -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" -d '[ { "deviceID": "6Q5DZNK-OUR81B9-7XVBNEW-G98K9LW-E7ZI313-MSF2DZJ-YU0POJ9-N4FGYV9" } ]' http://localhost:8384/rest/config/devices
Did that work?
# curl -s -X GET -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" http://localhost:8384/rest/config/devices
Let’s an a name to that device:
# curl -s -X PUT -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" -d '[ { "deviceID": "6Q5DZNK-OUR81B9-7XVBNEW-G98K9LW-E7ZI313-MSF2DZJ-YU0POJ9-N4FGYV9", "name": "foobar_plus" } ]' http://localhost:8384/rest/config/devices
Folders. The local/client side is 6Q5DZNK. Let’s ask the remote/server side N098QOW to share the ‘default’ folder with us. This is sent to the remote end.
# curl -s -X PUT -H "X-API-Key: CbWoJOlVgdftUfN1kBoueAKO4SZKB5c0" -d '[ { "deviceID": "6Q5DZNK-OUR81B9-7XVBNEW-G98K9LW-E7ZI313-MSF2DZJ-YU0POJ9-N4FGYV9", "name": "my_local_syncthing" } ]' https://syncthing.somewhere.io:8384/rest/config/devices
What is the name of the default folder on my local syncthing:
# curl -s -X GET -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" http://localhost:8384/rest/config/folders
[
{
"id": "default",
...
I see that it’s “id: default”. Let’s use jq
to extract the value only:
# curl -s -X GET -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" http://localhost:8384/rest/config/folders | jq '.[].id'
"default"
Let’s look at the configuration of the folder with id “default”:
# curl -s -X GET -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" localhost:8384/rest/config/folders/default
Add a device to that “default” folder for sharing:
# curl -s -X PATCH -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" -d '{ "devices": [ { "deviceID": "6Q5DZNK-OUR81B9-7XVBNEW-G98K9LW-E7ZI313-MSF2DZJ-YU0POJ9-N4FGYV9" } ] }' localhost:8384/rest/config/folders/default
Set Remote Address. AKA: for this device id, use this address/port tcp://remote_syncthing.somewhere.io:22000
. First, look at the existing configuration, then set it, then view again:
# curl -s -X GET -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" localhost:8384/rest/config/devices/6Q5DZNK-OUR81B9-7XVBNEW-G98K9LW-E7ZI313-MSF2DZJ-YU0POJ9-N4FGYV9
# curl -s -X PATCH -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" -d '{ "addresses": [ "tcp://remote_syncthing.somewhere.io:22000" ] }' localhost:8384/rest/config/devices/6Q5DZNK-OUR81B9-7XVBNEW-G98K9LW-E7ZI313-MSF2DZJ-YU0POJ9-N4FGYV9
# curl -s -X GET -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" localhost:8384/rest/config/devices/6Q5DZNK-OUR81B9-7XVBNEW-G98K9LW-E7ZI313-MSF2DZJ-YU0POJ9-N4FGYV9
Set maxSendKbps, maxRecvKbps for the device. Be careful, these options appear in a few places. In this case, we want to set it per the local device:
# curl -s -X GET -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" localhost:8384/rest/config/options
# curl -s -X GET -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" localhost:8384/rest/config/devices
# curl -s -X PATCH -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" -d '{ "maxSendKbps": 6000 }' localhost:8384/rest/config/devices/6Q5DZNK-OUR81B9-7XVBNEW-G98K9LW-E7ZI313-MSF2DZJ-YU0POJ9-N4FGYV9
# curl -s -X PATCH -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" -d '{ "maxRecvKbps": 6000 }' localhost:8384/rest/config/devices/6Q5DZNK-OUR81B9-7XVBNEW-G98K9LW-E7ZI313-MSF2DZJ-YU0POJ9-N4FGYV9
Change default folder from “type”: “sendreceive” to “type”: "“receiveonly”
# curl -s -X GET -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" localhost:8384/rest/config/folders
# curl -s -X PATCH -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" -d '{ "type": "receiveonly" }' localhost:8384/rest/config/folders/default
Set autoAcceptFolders to true per the remote device:
# curl -s -X GET -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" localhost:8384/rest/config/devices/N098QOW-3F17I07-NJ7LT0T-PC5YC33-ULTQJZD-JTMVKP1-8A283AM-DD79XNL
# curl -s -X PATCH -H "X-API-Key: 35P6t2XKq9KKF0R5b4JRu58m1uZGplLn" -d '{ "autoAcceptFolders": true }' localhost:8384/rest/config/devices/N098QOW-3F17I07-NJ7LT0T-PC5YC33-ULTQJZD-JTMVKP1-8A283AM-DD79XNL