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

Reply
karthiknc
Frequent Visitor

Invoke-PowerBIRestMethod Bad Request And Unauthorized

Hello ,

 

Thanks for seeing my Post.

 

Im trying to Automate Power Bi Deployments Via Azure DevOps using Service Principle.

 

After Deploying the Report and Dataset, while Configuring the DataSources for the Dataset using the Invoke-PowerBIRestMethod PATC METHOd, Im getting 400 Bad REQUEST.

 

I have given Power Bi adminstrator ROle to Service Principle. Below is My code

 

 

 

 

 

$datasourePatchUrl = "gateways/46519456-166e-4893-be1e-97e3bede8q92/datasources/78907969-f0df-4d1d-a7eb-24bf4a11f51b"
$jsonCredentials =  ConvertTo-Json -InputObject @{
>>             credentialDetails = @{
>>                 credentialType      = "OAuth2"
>>                 credentials         = $credentials
>>                 encryptedConnection = "Not Encrypted"
>>                 encryptionAlgorithm = "None"
>>                 privacyLevel        = "Organizational"
>>             }
>>         }
PS H:\> Invoke-PowerBIRestMethod -Method Patch -Url $datasourePatchUrl -Body $jsonCredentials -VERBOSE
Invoke-PowerBIRestMethod : One or more errors occurred.
At line:1 char:1
+ Invoke-PowerBIRestMethod -Method Patch -Url $datasourePatchUrl -Body  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + 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/34219456-156e-4893-be1e-67e3bede8b92/datasources/78907969-f0df-4d1d-a7eb-24bf4a11f51b
VERBOSE: Status Code: BadRequest (400)

 

 

 

 

 Not sure anything is missing on it Or not.

In Order to verify if the service Principle has read access , I tried the Get Call, returning 401 Unauthorized for Reading all Datasets in WorkSpace.

 

 

 

 

 

Invoke-PowerBIRestMethod -Method Get -Url "https://api.powerbi.com/v1.0/myorg/admin/groups/31246a39-0dc6-478c-a67a-a7a2a84702b8/datasets" -verbose
Invoke-PowerBIRestMethod : One or more errors occurred.
At line:1 char:1
+ Invoke-PowerBIRestMethod -Method Get -Url "https://api.powerbi.com/v1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + 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/admin/groups/31246a39-0dc6-478c-a67a-a7a2a84702b8/datasets
VERBOSE: Status Code: Unauthorized (401)

 

 

 

 

Can Someone help me with any pointers please.

 

Regards

Karthik

3 REPLIES 3
R1k91
Super User
Super User

did you allow service principals to use APIs?

 

Embed Power BI content in an embedded analytics application with service principal and an applicatio...

 


--
Riccardo Perico
BI Architect @ Lucient Italia | Microsoft MVP

Blog | GitHub

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

Yes, Currently its enabled to Entire Organization

karthiknc
Frequent Visitor

Any Help ?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.