I am using powershell to upload a RDL file to a specific folder in a SSRS instance (SQL Server 2019 Reporting Services Version 15.0.8863.19101)
$sourceItemPath = 'C:TempReportFolderReport.rdl'
$reportName = 'Report'
$apiPath = 'http://localhost/reports/api/v2.0'
$creds = New-Object System.Management.Automation.PSCredential ($SSRSReportUser, $SecurePassword)
$targetPath = "/Reports"
$sourceFileContent = [System.IO.File]::ReadAllBytes($sourceItemPath)
$sourceFileContent2 = [System.Convert]::ToBase64String( $sourceFileContent )
# ------------------
# Create Report
# ------------------
$CreateReportJSON=
'
{
"@odata.type": "#Model.Report",
"Content": "YYY",
"ContentType": "application/rdl",
"Name": "XXX",
"Path": "/ZZZ/XXX"
}
'
$targetPath = $targetPath.Replace('/','')
$CreateReportJSON = $CreateReportJSON.Replace('XXX',$reportName)
$CreateReportJSON = $CreateReportJSON.Replace('YYY',$sourceFileContent2)
$CreateReportJSON = $CreateReportJSON.Replace('ZZZ',$targetPath)
$CreateReportURI = "$apiPath/Reports(Path='/$targetPath')"
$createReportResponse = Invoke-RestMethod -Uri $CreateReportURI -Method POST -ContentType 'application/json' -Body $CreateReportJSON -Credential $creds
When I attempt to upload the report, I get the following error.
Invoke-RestMethod : {
"error":{
"code":"1027","message":"The definition of this report is not valid or supported by this version of Reporting Services. The report definition may have been created with a later version of Reporting Services, or contain content that is not well-formed
or not valid based on Reporting Services schemas. Details: Invalid character in the given encoding. Line 1206, position 80."
}
}
The beginning of the file is…
<?xml version="1.0" encoding="utf-8"?>
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:am="http://schemas.microsoft.com/sqlserver/reporting/authoringmetadata">
I can upload the file via the SSRS UI! Why can’t I upload it via Powershell? Can I get rid of the schema validation?