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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Can't create PowerBi data source using Powershell

I have been trying creating PowerBi data source via Powershell however it's not working. 

 

My code is, 

Login-PowerBIServiceAccount

$gatewayId = "5***********************************************"
$URL = "https://api.powerbi.com/v1.0/myorg/gateways/$gatewayId"

$Body = @{
dataSourceType = "Web"
datasourceName = "Junk"
connectionDetails = "{`"path`":`"https://junk.junk.com.au/api/views/S%20Reporting%20Collection/Process%20by%20Location`"}"
credentialDetails = @{
credentialType = "Basic"
credentials = "{`"credentialData`":[{`"name`":`"username`", `"value`":`"S*****************`"},{`"name`":`"password`", `"value`":`"P*******`"}]}"
encryptedConnection = "None"
encryptionAlgorithm = "None"
privacyLevel = "Organizational"
}
} | ConvertTo-Json
#$Body
$response = Invoke-PowerBIRestMethod -Url $URL -Method post -Body $Body -Verbose

 

Error:

Invoke-PowerBIRestMethod : One or more errors occurred.
At line:19 char:13
+ $response = Invoke-PowerBIRestMethod -Url $URL -Method post -Body $Bo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIRestMethod], AggregateException
+ FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod

VERBOSE: Request Uri: https://api.powerbi.com/v1.0/myorg/gateways/5************************************
VERBOSE: Status Code: NotFound (404)

 

My code is based on https://community.powerbi.com/t5/Developer/Power-BI-REST-API-via-Powershell-Create-Datasource/td-p/5...

 

My question is, do I need to have PowerBi admin role in Microsoft 365 to be able to create data sources ? I wouldn't have thought so. I am administrator on the PowerBi gateway where trying to create data source. Thought that would have been sufficient. 

 

According to https://www.youtube.com/watch?v=SQ7ufcRayYY&list=PLIa2Rws8_X8hTpasShIpNIQsobxRCGlrw&index=2&t=0s, it seems PowerBi admin role is needed to create PowerBi data sources through Powershell. 

Status: New
Comments
v-chuncz-msft
Community Support

@niravmodi 

 

You may try Create Datasource and create a support ticket for assistance if necessary.

niravmodi
Regular Visitor

@v-chuncz-msft 

 

Thanks. 

 

I have had to speak to my organization's MS365 global admin to allow me access to be able to lodge a support ticket to https://powerbi.microsoft.com/en-us/support/pro/

 

To my surprise, going there, the options are 

 

Cant-create-PowerBi-data source-using-Powershell-1.jpg

https://community.powerbi.com/

https://ideas.powerbi.com/ideas/

https://aka.ms/issues.powerbi.com Or https://community.powerbi.com/t5/Issues/idb-p/Issues

 

Can you advise how to post a support ticket to MS. Thanks.