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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Generate Embedtoken with PowerShell and Invoke-PowerBIRestMethod

Hi,

 

My goal is to generate an embedToken to be able to have a firm connection with PBI Service. I want to display the PBI dashboard at our Angualar app. Currently I'm using PBI Service, the tiral version. I'm also an administrator of the workspace where the dashboard is.

 

I've tried to generate the token with AAD method, it worked but (as mentioned) need something firm/stable.
My limitation is to create MS Entra ID.

 

I have went through a yt channel of Guyinacube -> Power BI Embed Token Using Powershell (youtube.com)

Thought it is going to be super easy, but in the end I can't generate the token as Adam does.

 

Here's my script:

 

$url = "https://app.powerbi.com/v1.0/myorg/groups/bcq2e688-f920-4343-adud-fhaa78f20e1d/reports/64d5d4d4-i96a..."

# JSON body (use double quotes for keys and values)
# $body = "{ `accessLevel`: `View` }"
$body = "{ `"accessLevel`": `"View`" }"

# Invoke the REST API
$response = Invoke-PowerBIRestMethod -Url $url -Body $body -Method Post

# Parse the response
$json = $response | ConvertFrom-Json
$json.token

 

 

 

Naturally (as it was covered at the yt video) I first run "Login-PowerBI" command which restul with a success.

Environment : Public
TenantId : eaad02fb-2df7-422b-a3ga-3d8f671ebb86
UserName : jnowak@you.com

 

 

When I run the main piece of script to return me the token, the output shows:

 

ConvertFrom-Json : Invalid JSON primitive: .
At line:11 char:21
+ $json = $response | ConvertFrom-Json
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand

 

 

 

I've tried to debug it but have not found nothing specific that would help.

 

 

HELP is what I need dear community 🙂

 

1 REPLY 1
Anonymous
Not applicable

Hi @Anonymous ,

Based on the description, try to modify the json body and enter the following body formula.

# Replace with your actual report ID
$reportId = "64d5d4d4-i96a-..."
$url = "https://api.powerbi.com/v1.0/myorg/reports/$reportId/GenerateToken"

$body = @{
  "accessLevel" = "View"
} | ConvertTo-Json

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

# Parse the response
$json = $response | ConvertFrom-Json
$json.token

You can view the following documents to learn more information.

Generate an embed token in Power BI embedded analytics - Power BI | Microsoft Learn

 

Best Regards,

Wisdom Wu

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

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.