Package: pySSRSapi
Python SSRS APIPython implementation of the SSRS API that allows to list, add, edit, delete folders, datasources and reports on an SSRS server.Initiate api with basic authimportpySSRSapi# basic authapi=pySSRSapi.Api(url='http://localhost/Reports/api/v2.0',user='username',password='password')UserGet current useruser=api.getUser()SystemGet system infosystem=api.getSystem()FoldersGet folders# list foldersfolders=api.getFolders()# get folder by idfolder=api.getFolderById(id='00000000-0000-0000-0000-000000000000')# get folder by pathfolder=api.getFolderByPath(path='/folder1')# get root folderfolder=api.getRootFolder()Add folder# get root folder for parent folder idrootFolder=api.getRootFolder()# initiate new foldernewFolder=pySSRSapi.Folder(Id=None,Name='folder1',Description='Description folder 1',Path='/folder1',ParentFolderId=rootFolder.Id)# add new folderaddedFolder=api.addFolder(folder=newFolder)Edit folder# get folder to editfolder=api.getFolderByPath(path='/folder1')# modify valuesfolder.Description='Folder 1 desc'# edit foldereditedFolder=api.editFolder(id=folder.Id,folder=folder)Set folder policies# get folderfolder=api.getFolderByPath(path='/folder1')# initiate policiespolicies=dict(InheritParentPolicy=False,Policies=[dict(GroupUserName='SERVER\\user_ssrs_1',Roles=[dict(Name='Report Builder',Description=None)])])# set folder policiesapi.setFolderPolicies(id=folder.Id,policies=policies)Delete folder# get folder to editfolder=api.getFolderByPath(path='/folder1')# delete folderapi.deleteFolder(id=folder.Id)DatasourcesGet datatources# list datasourcesdatasources=api.getDatasources()# get datasource by iddatasource=api.getDatasourceById(id='00000000-0000-0000-0000-000000000000')# get datasource by pathdatasource=api.getDatasourceByPath(path='/folder1/datasource1')Add datasource# get folder to editfolder=api.getFolderByPath(path='/folder1')# get rds file in b64 json friendlywithopen('datasource1.rds','rb')asf:byte_content=f.read()base64_bytes=base64.b64encode(byte_content)file_content=base64_bytes.decode('utf-8')# initiate new datasourcenewDatasource=pySSRSapi.Datasource(Id=None,Name='datasource1',Description='Description datasource 1',Path='/folder1/datasource1',ParentFolderId=folder.Id,DataSourceType='ODBC',ConnectionString='Dsn=DATASOURCE_1_ODBC_CONNECTION',Content=file_content)# add new datasourceaddedDatasource=api.addDatasource(datasource=newDatasource)Edit datasource# get datasource to editdatasource=api.getDatasourceByPath(path='/folder1/datasource1')# modify valuesdatasource.Description='Datasource 1 desc'# edit datasourceeditedDatasource=api.editDatasource(id=datasource.Id,datasource=datasource)Set datasource policies# get datasourcedatasource=api.getDatasourceByPath(path='/folder1/datasource1')# initiate policiespolicies=dict(InheritParentPolicy=False,Policies=[dict(GroupUserName='SERVER\\user_ssrs_1',Roles=[dict(Name='Report Builder',Description=None)])])# set datasource policiesapi.setDatasourcePolicies(id=datasource.Id,policies=policies)Delete datasource# get datasource to editdatasource=api.getDatasourceByPath(path='/folder1/datasource1')# delete datasourceapi.deleteDatasource(id=datasource.Id)ReportsGet reports# list reportsreports=api.getReports()# get report by idreport=api.getReportById(id='00000000-0000-0000-0000-000000000000')# get report by pathreport=api.getReportByPath(path='/folder1/report1')Add report# get folder to editfolder=api.getFolderByPath(path='/folder1')# get rds file in b64 json friendlywithopen('report1.rdl','rb')asf:byte_content=f.read()base64_bytes=base64.b64encode(byte_content)file_content=base64_bytes.decode('utf-8')# initiate new reportnewReport=pySSRSapi.Report(Id=None,Name='report1',Description='Description report 1',Path='/folder1/report1',ParentFolderId=folder.Id,Content=file_content)# add new reportaddedReport=api.addReport(report=newReport)Edit report# get report to editreport=api.getReportByPath(path='/folder1/report1')# modify valuesreport.Description='Report 1 desc'# edit reporteditedReport=api.editReport(id=report.Id,datasource=report)Set report policies# get reportreport=api.getReportByPath(path='/folder1/report1')# initiate policiespolicies=dict(InheritParentPolicy=False,Policies=[dict(GroupUserName='SERVER\\user_ssrs_1',Roles=[dict(Name='Report Builder',Description=None)])])# set report policiesapi.setReportPolicies(id=report.Id,policies=policies)Delete report# get report to editreport=api.getReportByPath(path='/folder1/report1')# delete reportapi.deleteReport(id=report.Id)