Page 1 of 1

Looking for Script help for Synology API

Posted: Mon Feb 18, 2013 1:07 am
by Livin
I'm trying to figure out how to do this but not finding any examples.

I'd like to create some basic scripts that I can send commands to the Synology. To do this I need to authenticate, then pass the SID (token) to send the commands. Can someone help me with the Python portion?

Thank you for the help!


*INFO*

The API supports GET. Examples in the guides look like... GET /webapi/192.168.2.50:5000?api=SYNO.SurveillanceStation.ExternalRecording&method=Record&version=1&cameraId=2&action=start

To authenticate... http://192.168.2.50:5000/webapi/auth.cg ... format=sid
-- when I use this directly in the browser it replies with a SID and success.

Get Camera List... http://192.168.2.50:5000/webapi/Surveil ... &_sid=<SID>
-- when I use this directly in the browser it replies it gives an error saying "Logged in session does not have permission".

Send Command:
http://192.168.2.50:5000/webapi/query.c ... tion=start
... oddly no SID seems required. when I try it I get an error "requested API does not exist"

Synology general API doc... http://download.synology.com/download/d ... API_V9.pdf
Synology Security Station Web API doc... http://download.synology.com/download/d ... _v0.12.pdf

Re: Looking for Script help for Synology API

Posted: Fri Mar 01, 2013 10:03 pm
by Livin
No one is willing to help?

Re: Looking for Script help for Synology API

Posted: Fri Nov 22, 2013 8:53 pm
by rdgerken
I'm game...

Let's do it.

I did some hacking around... try this:

I'm using https on my setup - you may need to change that to http if you aren't using SSL. Also, I just grabbed the camera list for proof of concept - obviously you have a little more work to do - but this should be enough to get you going.

Code: Select all

import json, urllib2

#user configurables
ip='192.168.1.10'
port='5001'
username='admin'
password='yourpassword'

#Make Request for Auth API Version
jsondata = json.load(urllib2.urlopen('https://' + ip + ':' + port + '/webapi/query.cgi?api=SYNO.API.Info&method=Query&version=1&query=SYNO.API.Auth'))
#Check to make sure request is successful
if jsondata['success']:
        AuthAPIMaxVer = int(jsondata['data']['SYNO.API.Auth']['maxVersion'])
        if AuthAPIMaxVer > 1:
                jsondata = json.load(urllib2.urlopen('https://' + ip + ':' + port + '/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=2&account=' + username + '&passwd=' + password + '&session=SurveillanceStation&format=sid'))
                sid = jsondata['data']['sid']
                print 'Logged in with SessionID = ' + sid
                #Get Camera List
                jsondata = json.load(urllib2.urlopen('https://' + ip + ':' + port + '/webapi/SurveillanceStation/camera.cgi?api=SYNO.SurveillanceStation.Camera&method=List&version=1&_sid=' + sid))
                print jsondata
                #Logout
                jsondata = json.load(urllib2.urlopen('https://' + ip + ':' + port + '/webapi/auth.cgi?api=SYNO.API.Auth&method=Logout&version=2&session=SurveillanceStation&_sid=' + sid))
                print 'SessionID ' + sid + ' Logged Out'
        else:
                print 'Authentication API Version does not support SessionID'
else:
        print 'Error Querying Authentication API'