Reputation: 1
ConverFrom-JSON : Invalid JSON Primitive error, primitive is not being recognized by PowerShell for some reason.
I need to generate PowerBi Embedded Tokens for my PowerBi reports. I can log in to my Microsoft account with out no problem and can invoke the report as well. At the end code supposed to return a embedded token to me, but I encounter with error :
ConvertFrom-Json : Invalid JSON primitive: . At line:13 char:21 + $json = $response | ConvertFrom-Json + ~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [ConvertFrom-Json], ArgumentException + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand
I have already tried the Out-String and Raw with Get-Content method, they did not work either.
CODE:
//Sign in with a user that has admin rights to App Workspace
Login-PowerBI
//Regular Report
$url = "https://app.powerbi.com/reportEmbed?reportId=5515f33b-c114-41c9-a925-d1f85c323dab&groupId=e53e4fcd-16f8-46ef-8740-8e7167562ceb&autoAuth=true&ctid=c760270c-f3da-4cfa-9737-03808ef5579f/GenerateToken"
$body = "{ 'accessLevel': 'View' }"
$response = Invoke-PowerBIRestMethod -Url $url -Body $body -Method Post
$response
$json = $response | ConvertFrom-Json
$json.token
It should return a huge paragraph of gibberish code, which will be my report's embedded token.
Upvotes: 0
Views: 2419
Reputation: 1
$url is incorrect - need to call api.powerbi.com
https://api.powerbi.com/v1.0/myorg/groups/{GroupID}/reports/{ReportID}/GenerateToken
try
$url = "https://api.powerbi.com/v1.0/myorg/groups/e53e4fcd-16f8-46ef-8740-8e7167562ceb/reports/5515f33b-c114-41c9-a925-d1f85c323dab/GenerateToken"
Upvotes: 0