Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext 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
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:
# 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 🙂
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.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.