Hello! I have a some trouble with SyncThing version above 1.2.0. Program written on C#. First of all I get api key from config.xml then I try GET method to read current config.xml:
public SyncThingConfig GetSystemConfig()
{
var res = Get("/system/config");
if (res.ErrorException != null)
{
throw new SyncThingApiException(res.ErrorMessage);
}
return Deserialize<SyncThingConfig>(res.Content);
}
Further I change some nodes and try to write new config using POST method:
public HttpStatusCode SetConfiguration(SyncThingConfig config)
{
var res = Post("/system/config", config);
if (res.ErrorException != null)
{
throw new SyncThingApiException(res.ErrorMessage);
}
if (res.StatusCode != HttpStatusCode.OK)
{
throw new SyncThingApiException(res.ErrorMessage);
}
return res.StatusCode;
}
And after write command i wanna to restart app using POST and got exception like a :
“Basic connection closed: The connection that was supposed to work was disconnected by the server.” In “/system/config” POST method. In SyncThing console I see next:
[OMMFY] 17:30:59 INFO: API call returned HTTP error: 400 Bad Request
Preformatted text`[OMMFY] 17:31:05 INFO: quic://0.0.0.0:22000 detected NAT type: Symmetric NAT
BTW my config.xml change properly!
If I downgraded to 1.2.0 Version everything works fine… Maybe this is due to the fact that it cannot apply configuration automatically? What’s a correct way to change config using web api? PS: Get method with headers
private IRestResponse Get(string path)
{
var request = new RestRequest($"rest{path}", Method.GET);
request.AddHeader("X-API-Key", apikey);
return client.Execute(request);
}
Post:
private IRestResponse Post<TBody>(string path, TBody data)
{
var request = new RestRequest($"rest{path}", Method.POST);
request.AddHeader("X-API-Key", apikey);
request.RequestFormat = DataFormat.Json;
request.AddJsonBody(JsonConvert.SerializeObject(data));
return client.Execute(request);
}