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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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??

v-yiruan-msft
Community Support
Community Support

Hi @sweggle ,

Please review the content in the following threads, hope they can help you.

Power BI: Using anonymous authentication on Web data sources with a API key in URL

How to update credentials for an on-prem Power BI data source using PowerShell

Using The “Skip Test Connection” Option For Power BI Data Sources To Avoid Scheduled Refresh Failure...

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.