Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Problem with new new REST API and report datasources

I am having problems with the new SSRS REST API, in particular relinking uploaded reports to their datasources. Microsoft have confirmed that the API doc as published is not correct in that the PUT on report datasources should take an array of datasources, not just one datasource but I still can't get it to do anything other than return 400 errors every time, no matter what I try. Nothing useful in the logs either. Here is a minimal snippet in Powershell where I simply get the datasources, modify the path and try to PUT the changes datasources back again. The PUT always gets a 400 error.

 

 

$ret = Invoke-RESTMethod -Uri "$restroot/Reports(Path='/$replib/$fname')/DataSources" -Method GET -ContentType "application/json" -UseDefaultCredentials

# $ret is correct and $ret.value is an array of datasources

# Change datasource path
$ret.value | % {
  $_.Path = "/$dclib/" + $_.Name
}

# Convert to JSON
$body = $ret.value | ConvertTo-Json

# Put modified Datasources array back into report
$ret = Invoke-RESTMethod -Uri "$restroot/Reports(Path='/$replib/$fname')/DataSources" -Method PUT -Body $body -ContentType "application/json" -UseDefaultCredentials

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Solved myself - by increasing tracing level on PBIRS logs and seeing a complaint about JSON payload not matching to an array type. I only had one datasource and due to the amazingly stupid mapping of single-item arrays into the bare item which Powershell does in some circumstances, the endpoint was not getting a JSON array. Fix was to replace:

 

$body = $ret.value | ConvertTo-Json

 with

 

$body = ConvertTo-Json $ret.value

 

because the pipe invokes the stupid array unwrapping. This silly behaviour of Powershell is particularly annoying in APIs where datatypes matter so much.

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Solved myself - by increasing tracing level on PBIRS logs and seeing a complaint about JSON payload not matching to an array type. I only had one datasource and due to the amazingly stupid mapping of single-item arrays into the bare item which Powershell does in some circumstances, the endpoint was not getting a JSON array. Fix was to replace:

 

$body = $ret.value | ConvertTo-Json

 with

 

$body = ConvertTo-Json $ret.value

 

because the pipe invokes the stupid array unwrapping. This silly behaviour of Powershell is particularly annoying in APIs where datatypes matter so much.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.