Skip to content

This is an example python script on generating pdf from a Power BI report using REST APIs

License

Notifications You must be signed in to change notification settings

nanda-nainadurai/powerbi-generate-pdf-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Script to Generate PDF using REST APIs

You can directly follow the steps from Microsoft docs or follow the below instructions:

Pre-requisites

  1. Get Azure Tenant ID (How to get)
  2. Register an app in Azure (Using Azure Portal, Using PowerShell is recommended)
  3. Create & Get Client Secret from Azure Portal (HINT: You get access to your client secret only once, at the time of creation - so take a copy of it somewhere safe)
  4. Get Client ID (for the app created in Step 2)
  5. Ensure appropriate access is provided to the created service principal. In this case, the required scopes are the following:
  • Report.ReadWrite.All or Report.Read.All
  • Dataset.ReadWrite.All or Dataset.Read.All
  1. The workspace must be created in Power BI Premium or Power BI Embedded Capacity for the API's to work (otherwise, you will get 403 errors while executing code)
  2. [IMPORTANT] Enable the Power BI service admin settings for the service principal or the security group created in Step 5

How to use

  1. Clone the repository or download the "GeneratePDF.py" file and "data.json" file
  2. Update the data.json file based on values gathere from the pre-requisites section
  3. Open command prompt and run the command python GeneratePDF.py

How it works!

  1. A REST API is called to authenticate & authorize using the CLIENT ID and CLIENT SECRET that was added in the data.json file. This returns an authentication token (for the curious) that will be used in subsequent REST API calls
  2. Export to File in Group API is called to initiate the generation of file (PDF is passed as the parameter) and returns an id to track the status of the job
  3. After trigger the job, use polling to track the job until it is completed
  4. Once the poll returns job status as success, get the file of export from the server
  5. This file is then saved local to the execution of the code

Things to Note

  1. The REST APIs are still in public preview and can sometimes behave unexpectedly
  2. There are some known limitations captured in this official link

Contributions

Feel free to contribute to the repository by raising issues or by creating Pull requests for any code/documentation updates.

About

This is an example python script on generating pdf from a Power BI report using REST APIs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages