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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
abernal
Frequent Visitor

Update Datasources REST API operation for live connections

I am trying to update the connection string of a live connection power bi report published to the service. In order to do so, I am using the "Update Datasources In Group" datasets operation of the REST API.  I'm getting an "InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException" in the response. Is is possible to change connection strings of published Power BI reports in live connection mode? Below is  what I am trying to do and the response that I am getting... Thanks,

 

Request

 

$body = @" 
{ 
  "updateDetails":[ 
    { 
      "connectionDetails": 
      { 
        "server": "$($targetServer)", 
        "database": "$($targetDatabase)" 
      }, 
      "datasourceSelector": 
      { 
        "datasourceType": "$($datasourceType)", 
        "connectionDetails": 
        { 
          "server": "$($originalServer)", 
          "database": "$($originalDatabase)" 
        } 
      } 
    } 
  ] 
} 
"@

$uri = "https://api.powerbi.com/v1.0/$groupsPath/datasets/$datasetID/Default.UpdateDatasources"
Invoke-RestMethod -Uri $uri -Headers $authHeader -Method POST -Body $body

  

Response

Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At H:\Projects\User Story 7483 - Infrastructure-Automated deployment of Power BI reports\20181003 Attempt\Change MOR Financial Report - Prod Orig to QA - Rest API.ps1:105 char:1
+ Invoke-RestMethod -Uri $uri -Headers $authHeader -Method POST -Body $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

 

 

 

4 REPLIES 4
AlexMur
New Member

Hi, I had the same error when I tried updating a datasource server & database to the same value as now (even with difference in character case). Hence, resolved the issue by not doing such updates. Regards, Alex.
Anonymous
Not applicable

Hi,

 

I am facing similar Issue, did you get solution for this.

 

 

orygreg2
Frequent Visitor

Hi - did you ever resolve this?  I'm having same problem.

Wondering if you could share whatever you learned.

Thanks,

Greg

 

Sorry Greg, I did not. I'll let you know if I find a solution. 

Alex

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.