Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import requests #request library is to send HTTP requests
url_system_status = ""
#according to the documentation of Syncthing,/rest/system/config exposes configuration details
headers= {"X-API-Key" : "XXXXXXXXXXX"}
headers is for authentication. Syncthing REST API exposes the end points via API Key
API key can be found at Syncthing GUI --> Actions --> Settings
This is to ensure that the information seen at the end point is not visible to unauthorised users.
response = requests.get(url_system_status,headers=headers).json()
response variable is where the real HTTP GET request happening.
Basically it says that, use the requests libabry which has already been imported
and execute the get function for url_system_status (which is
and include headers which is the X-API-KEY itself
At this point we already have the result saved into response variable.
.json() #This is to convert incoming info into a Python list of dictionaries
for key,values in response.items():
print (key,values)
Since a dictionary is a combination of keys and values, then we can iterate over each key with the corresponding value
and print them one by one. This part of the code is not a must but it is nice to read the response.
with open('config.json', 'w') as config_file:
json.dump(response, config_file, indent=4)
by using json.dump we can write the result to a file which can be used later for a reference or for a config change.
This code will create config.json in the same directory where the script is. response will be used to create the content of this file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.