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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
sweggle
Regular Visitor

Update Source Credentials with PowerShell for Web Type & Anonymous

Hi,

I'm new to PowerBI but not to PowerShell.

 

I've got a dataset which is a Web type and is coming from Azure API. The credentials are anonymous, the parameters handle the authentication eg apikey and so on.

 

I want to refresh it automatically each day using the service principal. I can do the take over of the dataset and initiate a refresh as the SP, but it then fails due to an error validating the source credentials. If i could actually skip this section it would just work.

So i am now trying to perform creating a new Web type Anonymous credential with PowerShell as the SP but I'm hitting some bugs.

 

Here is my credential setting in the powerbi gui:

 

sweggle_0-1632413586717.png

 

However, after my SP takes over the dataset and tries to refresh it, i get this dreaded error. SO i assume I need to update / delete and recreate the credentials.

sweggle_1-1632413664848.png

 

I followed something from the MS PowerBI Github that is very similar but for a SQL source: PowerShell

 

I've edited the code slightly to look like this, but i still get a generic 500 error.

 

 

 

 

# create HTTP request body to update datasource connection details
$postBody = @{
  "updateDetails" = @(
   @{
    "connectionDetails" = @{
      "url" = "https://xxx.azure-api.net/"
    }
    "datasourceSelector" = @{
      "datasourceType" = "Web"
      "connectionDetails" = @{
        "url" = "https://xxx.azure-api.net/"
      }
      "gatewayId" = "$gatewayId"
      "datasourceId" = "$datasourceId"
    }
  })
}

# convert body contents to JSON
$postBodyJson = ConvertTo-Json -InputObject $postBody -Depth 6 -Compress

# execute POST operation to update datasource connection details
Invoke-PowerBIRestMethod -Method Post -Url $datasourePatchUrl -Body $postBodyJson

 

 

 

 

I've also tried it like this:

 

 

 

 

$New = @{
    dataSourceType = "Web"
    datasourceName = "Dummy Web Connection"
    connectionDetails = "{`"url`":`"https://xxx.azure-api.net/`"}"
    credentialDetails = @{
        credentialType = "Anonymous"
        credentials = "{`"credentialData`":`"`"}"
        encryptedConnection = "NotEncrypted"
        encryptionAlgorithm = "None"
        privacyLevel = "None"
    }
} | ConvertTo-Json


Invoke-PowerBIRestMethod -Url "gateways/$GatewayId/datasources/" -Method Post -Body $new -Verbose

 

 

 

 

However in fiddler i get the following:

A7
{"error":{"code":"DMTS_InvalidEncryptionAlgorithmError","pbi.error":{"code":"DMTS_InvalidEncryptionAlgorithmError","parameters":{},"details":[],"exceptionCulprit":1}}}
0

 

My source type is web and credential type is anonymous. There is no username or password, this should be really straightforward but I am finding it very difficult to overcome this issue - hoping someone can help.

 

Any help appreciated!

2 REPLIES 2
thomasio
New Member

Hi

So is there a solution check the "skip test connection" checkbox for a service principal??

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors