cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ybam
Frequent Visitor

PowerShell Invoke-PowerBIRestMethod -Method Post WriteError

Hi, 

I have a PowerShell script for Rebind my report in a workspace. 

 

$clientId = "myClientId"
$clientSec = "myClientSecret" | ConvertTo-SecureString -AsPlainText -Force
$tenantId = "myTenantId"

$credential = New-Object System.Management.Automation.PSCredential($clientId$clientSec)
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId $tenantId


$Workspace = Get-PowerBIWorkspace -Name WorkspaceName
$WorkspaceId = $Workspace.Id
write-host $WorkspaceId
$report = Get-PowerBIReport -WorkspaceId $WorkspaceId -Name ReportName
$reportId = $report.ID
write-host $reportId
$dataset = Get-PowerBIDataset -WorkspaceId $WorkspaceId
$datasetId = $dataset.ID
write-host $datasetId


# Get token
$token =  Get-PowerBIAccessToken -AsString
write-host $token

# Building Rest API header with authorization token
$authHeader = @{
   "Authorization"$token
   "Content-Type" = "application/json"
}

# POST body 
$postParams = @{
    "datasetId" = "$datasetId"
}

$jsonPostBody = $postParams | ConvertTo-JSON

# Rebing reports 
Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/$($WorkspaceId)/reports/&($reportId)/Rebind" -Method Post -Headers $authHeader -Body $jsonPostBody  -Verbose

 

When I run that I get this error:

"Invoke-PowerBIRestMethod : Une ou plusieurs erreurs se sont produites.
Au caractère path\Desktop\TestRebind.ps1:38 : 1
+ Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/gro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIRestMethod], AggregateException
+ FullyQualifiedErrorId : Une ou plusieurs erreurs se sont produites.,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod"

 

My token looks like : "Bearer *********"

My API permissions are Read and Write ALL except for Tenant because I am not admin

 

Someone can help me please ? 

1 ACCEPTED SOLUTION

Hi @v-lionel-msft , 

Yes I'm sure I have these permissions. 

My error was fixed. 

My problem was the "Headers" parameter of my invoke method. 

I didn't need the token since I was already logged in.

View solution in original post

3 REPLIES 3
v-lionel-msft
Community Support
Community Support

Hi @Ybam ,

 

thank you for your sharing.

 

Best regards,
Lionel Chen

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

v-lionel-msft
Community Support
Community Support

Hi @Ybam ,

 

Do you really have these two permissions?

v-lionel-msft_0-1606973007675.png

 

Best regards,
Lionel Chen

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

 

Hi @v-lionel-msft , 

Yes I'm sure I have these permissions. 

My error was fixed. 

My problem was the "Headers" parameter of my invoke method. 

I didn't need the token since I was already logged in.

View solution in original post

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Power BI December 2021 Update_carousel 768x460.jpg

Check it Out!

Click here to read more about the December 2021 Updates!

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Jan 2022 Dev Camp 768x460 copy.png

Power BI Dev Camp- January 27th, 2022

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors