How to use REST "POST /rest/system/config"

according to document ,I test “POST config” using curl,but not successed. This is my first test the API. I need a complate exmple. noted:I test “GET config” and “POST restart” sucessed

You post the same type of structure you get back from get.

1 Like

I have tried it.But the effect is not right.It reset the syncthing configuration. APIKEY automatically changed.

You need to post all data you get from GET

Get the config:

jb@unu:~ $ curl -s -H X-API-Key:V0a06AIXjmSyHG4wj1Y5sifURCqbzPnR \
    -o config.json http://localhost:8385/rest/system/config

The config is now in config.json. Post it back:

jb@unu:~ $ curl -s -H X-API-Key:V0a06AIXjmSyHG4wj1Y5sifURCqbzPnR \
    -X POST --data-binary @config.json http://localhost:8385/rest/system/config
1 Like

yes!yes!! It works.Thanks :slight_smile:

I have tried this (using PHP). However, when uses json_encode, the “params” of “versioning” seems not working.

If you want help, then post the output of the call to json_encode in question, and post how you’re calling it. Just saying “php generates something wrong” means that it’s impossible for anyone to help you and you’re just wasting your own time.

I have tried this (using PHP). However, when uses json_encode, the “params” of “versioning” seems not working. Here is what I have done:

  1. in PHP, using curl -s -H X-API-Key:V0a06AIXjmSyHG4wj1Y5sifURCqbzPnR
    -o config.json http://localhost:8385/rest/system/config and get the config.json
  2. in PHP, use json_decode to parse the file;
  3. without changing anything, use json_encode and write the result to another file config.json2;
  4. using curl -s -H X-API-Key:V0a06AIXjmSyHG4wj1Y5sifURCqbzPnR
    -X POST --data-binary @config.json2 API_URL to write it back

got the following error: json: cannot unmarshal array into Go struct field VersioningConfiguration.params of type map[string]string

Looking into config.json2, it shows that: “versioning”: { “type”: “simple”, “params”: [] }, However “params” should be an object? How to make it an object?

Object is {}