Hi I’m trying to manage Syncthing with Powershell. As an exercise, I’m trying to turn on/off the master setting on all folders.
My code at the moment:
$Url = "http://localhost:8080/rest/system/config"
#Getting Config
$Config = Invoke-RestMethod -Uri $Url -Method Get
#Turning on Master on every folder
foreach ($folder in $Config.folders)
{
$folder.readOnly = "True"
}
#curl headers from firefox developer console when a config is applied
$Headers = @{
#"Host" = "localhost:8080"
#"User-Agent" = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0"
#"Accept" = "application/json, text/plain, */*"
#"Accept-Language" = "en-US,en;q=0.5"
#"Content-Type" = "application/json; charset=UTF-8"
"X-CSRF-Token-UM5L5" = "JpdUOIqFIgPcGDQC0KAXqspLD0eHOvHq"
#"Referer" = "http://localhost:8080/"
#"Content-Length" = "13507"
"Cookie" = "CSRF-Token-UM5L5=JpdUOIqFIgPcGDQC0KAXqspLD0eHOvHq"
#"Connection" = "keep-alive"
#"Pragma" = "no-cache"
#"Cache-Control" = "no-cache"
}
#Converting to Json and cleaning up
$JsonConfig = ($Config | ConvertTo-Json | Out-String).Replace(" ","")
$JsonConfig = $JsonConfig.Replace([Environment]::NewLine,"")
Invoke-RestMethod -Uri $Url -Method Post -Body $JsonConfig -Headers $Headers -ContentType application/json
It does not change any settings, and this error pops up: “Invoke-RestMethod : json: cannot unmarshal string into Go value of type []config.FolderDeviceConfigur ation”. But I get the same error in the web interface of Syncthing, so the posting part seems to work. I suspect the config isn’t formatted right before posting. I’ve tried without the cleanup at the end, and only using the ConvertTo-Json. Same error.
Anyone here who can help?