Forum Discussion

karthiknc's avatar
karthiknc
Frequent Visitor
3 years ago

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