Forum Discussion
send report in pdf
- 6 years agoSubscribing to PBIX reports as PDF is currently not supported. It’s in our planned backlog. We will get to it in coming months but no specific timeline to share yet.
This is the API call to use:
https://docs.microsoft.com/en-us/rest/api/power-bi/reports/exporttofile
You would use Flow (Power Automate) to implement this by calling a PowerShell script, etc. I'm not super up on Flow but you can ask in the Power Automate forums. You would then use the Flow to send the generated file.
Hi Greg_Deckler ,
Thanks for your reply.
I tried to Export to PDF with the below code but was getting 1 or more errors.
Invoke-PowerBIRestMethod -Method POST -Url reports/76746e90-02e9-4677-ac7a-0ea5755c6c47/ExportTo -Body PDF -OutFile PDF
Could you or anybody else please help me out in this code? I would like to export it in pdf.
Thanks
Prakash
- Greg_Deckler6 years ago
Community Champion
I believe the correct code is closer to:
$params = @{"format"="PDF"}
Invoke-PowerBIRestMethod -Method POST -Url reports/a9b01471-0982-4e14-bbf7-ddb60a89ab43/ExportTo -Body $params
However, I am getting some kind of Write error:
Invoke-PowerBIRestMethod : One or more errors occurred.
At line:1 char:1
+ Invoke-PowerBIRestMethod -Method POST -Url reports/a9b01471-0982-4e14 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIR
estMethod], AggregateException
+ FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod- Anonymous6 years agoNot applicable
Hi Greg_Deckler ,
Thanks for your reply. I am also getting the same error.
It would be really helpful if any body help me out on the below code.
$params = @{"format"="PDF"}
Invoke-PowerBIRestMethod -Method POST -Url reports/a9b01471-0982-4e14-bbf7-ddb60a89ab43/ExportTo -Body $params
Regards,
Prakash
- Greg_Deckler6 years ago
Community Champion
Well, this is what I am seeing but I know I have full Admin access to this workspace so I don't know why I am getting 403 Forbidden. Anonymous v-easonf-msft rpatkar Pikachu-Power Jayendran Mariusz edhans parry2k VasTg az38 HotChilli
Anyone know why this doesn't work? I would be happy with a simple PNG export at this point.
Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. Try the new cross-platform PowerShell https://aka.ms/pscore6 PS C:\WINDOWS\system32> cd \temp PS C:\temp> Connect-PowerBIServiceAccount Environment : Public TenantId : UserName : [email protected] PS C:\temp> Invoke-PowerBIRestMethod -Method POST -Url reports/4557598e-158d-407e-90e5-35a08b7c7584/ExportTo WARNING: The Body parameter was null, the request may be invalid when Method parameter is Post. Invoke-PowerBIRestMethod : One or more errors occurred. At line:1 char:1 + Invoke-PowerBIRestMethod -Method POST -Url reports/4557598e-158d-407e ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIR estMethod], AggregateException + FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod PS C:\temp> Resolve-PowerBIError HistoryId: 3 Message : Response status code does not indicate success: 403 (Forbidden). StackTrace : at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() at Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod.<InvokeRestMethod>d__31.MoveNext() Exception : System.Net.Http.HttpRequestException InvocationInfo : {Invoke-PowerBIRestMethod} Line : Invoke-PowerBIRestMethod -Method POST -Url reports/4557598e-158d-407e-90e5-35a08b7c7584/ExportTo Position : At line:1 char:1 + Invoke-PowerBIRestMethod -Method POST -Url reports/4557598e-158d-407e ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : 3I have also tried this by creating a Service Principal, creating the application id, secret client key, adding the service principal to the workspace as Admin, here is the session from that, instead of 403 Forbidden I get back 401 Unauthorized. Note that I have also enabled Service Principal access to Power BI in the Tenant Settings Developer:
Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. Try the new cross-platform PowerShell https://aka.ms/pscore6 PS C:\WINDOWS\system32> cd \temp PS C:\temp> Connect-PowerBIServiceAccount -ServicePrincipal -Credential (Get-Credential) cmdlet Get-Credential at command pipeline position 1 Supply values for the following parameters: Credential Environment : Public TenantId : ClientId : Password : ******** PS C:\temp> Invoke-PowerBIRestMethod -Method POST -Url reports/4557598e-158d-407e-90e5-35a08b7c7584/ExportTo WARNING: The Body parameter was null, the request may be invalid when Method parameter is Post. Invoke-PowerBIRestMethod : One or more errors occurred. At line:1 char:1 + Invoke-PowerBIRestMethod -Method POST -Url reports/4557598e-158d-407e ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIR estMethod], AggregateException + FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod PS C:\temp> Resolve-PowerBIError HistoryId: 3 Message : Response status code does not indicate success: 401 (Unauthorized). StackTrace : at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() at Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod.<InvokeRestMethod>d__31.MoveNext() Exception : System.Net.Http.HttpRequestException InvocationInfo : {Invoke-PowerBIRestMethod} Line : Invoke-PowerBIRestMethod -Method POST -Url reports/4557598e-158d-407e-90e5-35a08b7c7584/ExportTo Position : At line:1 char:1 + Invoke-PowerBIRestMethod -Method POST -Url reports/4557598e-158d-407e ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : 3