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

(Coollei) #1

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

(Audrius Butkevicius) #2

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

(Coollei) #3

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

(Audrius Butkevicius) #4

You need to post all data you get from GET

(Jakob Borg) #5

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

(Coollei) #6

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.

(Antony Male) #8

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?

(Audrius Butkevicius) #10

Object is {}