You can directly follow the steps from Microsoft docs or follow the below instructions:
- Get Azure Tenant ID (How to get)
- Register an app in Azure (Using Azure Portal, Using PowerShell is recommended)
- 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)
- Get Client ID (for the app created in Step 2)
- 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
- 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)
- [IMPORTANT] Enable the Power BI service admin settings for the service principal or the security group created in Step 5
- Clone the repository or download the "GeneratePDF.py" file and "data.json" file
- Update the data.json file based on values gathere from the pre-requisites section
- Open command prompt and run the command
python GeneratePDF.py
- A REST API is called to authenticate & authorize using the
CLIENT ID
andCLIENT SECRET
that was added in thedata.json
file. This returns an authentication token (for the curious) that will be used in subsequent REST API calls - 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
- After trigger the job, use polling to track the job until it is completed
- Once the poll returns job status as success, get the file of export from the server
- This file is then saved local to the execution of the code
- The REST APIs are still in public preview and can sometimes behave unexpectedly
- There are some known limitations captured in this official link
Feel free to contribute to the repository by raising issues or by creating Pull requests for any code/documentation updates.