0
votes

I am using a Powershell script to generate an embed token for a Power BI dashboard:

Login-PowerBI

$url = "https://api.powerbi.com/v1.0/myorg/groups/395ce617-f2b9-xyz/dashboards/084c9cc4-xyz/GenerateToken"

$body = "{ 'accessLevel': 'View' }"

$response = Invoke-PowerBIRestMethod -Url $url -Body $body -Method Post -ErrorAction "Stop"
$response

$json = $response | ConvertFrom-Json
$json.token

This works, however I was hoping to make the dashboard editable by changing the accessLebel like this:

$body = "{ 'accessLevel': 'Edit' }"

Instead of generating a token, an error is thrown indicating Bad Request, but with no other detail. How can I determine how the request should be created? Are dashboards even editable like reports are? (I can generate edit tokens for reports with no issue) I can't find a code sample for that, and I note the online sample doesn't allow you to edit dashboards like you are able to with reports: https://microsoft.github.io/PowerBI-JavaScript/demo/v2-demo/index.html

1
Seams pretty obvious, but are you sure that Dashboard.ReadWrite.All, Report.ReadWrite.All and Dataset.ReadWrite.All privileges are granted? - Andrey Nikolov

1 Answers

2
votes

You got the error Bad request because accessLevel: Edit is not supported for dashboards. The accessLevel supported for Generate EmbedToken for dashboard in the group is only View.

Create and Edit accessLevel is available only for reports.

Refer to this link: https://docs.microsoft.com/en-us/rest/api/power-bi/embedtoken/dashboards_generatetokeningroup#tokenaccesslevel

You can use the Try it feature there to see how the REST API calls are made.