Forum Discussion

Shiroyasha1's avatar
Shiroyasha1
New Member
1 year ago
Solved

Export PBIT from PBIX in bulk automated using Python or Powershell

Hi,

 

Is there a way I could convert a pbix file to pbit through code?

Say I have hundreds or thousands of files. I would like to extract the json (DataModelSchema) file of each pbix which I have to do for all files manually and could only be done through manual export or using save as for every single file. 

 

1- save a pbix file as pbit (main problem to automate)

2-unzip the file and extract the json (feasible in python)

 

Thanks.

 

  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi Shiroyasha1 ,

    Thank you for reaching out and sharing the links in your conformation query. Unfortunately, I am unable to access external links. However, I do have detailed information regarding the topic you're asking about.

    As discussed, the Power BI API doesn't support PBIX to PBIT conversion. You could try Power Automate for exporting reports, but it only works with Power BI Service-hosted reports, not local PBIX files.

    You’ve used pyautogui to automate the "Save As" process for exporting PBIX to PBIT, which works but isn’t ideal for large batches.

    You mentioned that you can access the Power BI REST API but only see SSRS reports, not Power BI reports. This indicates that your current access may be pointing to the SSRS reports endpoint rather than Power BI reports.

    The endpoint GET https://api.powerbi.com/v1.0/myorg/reports/{reportId}/Export exports Power BI report contents (e.g., PDF, PPTX), not the PBIX file. To work with Power BI reports, use the correct API endpoints for Power BI reports (not SSRS reports).

     

    To list Power BI reports in your workspace, use:

    GET https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports

    This will return a list of reports (not SSRS) in the specified workspace.

    The endpoint you found exports a Power BI report (not PBIX). After retrieving the report, use the export endpoint to trigger the export.

    GET https://api.powerbi.com/v1.0/myorg/reports/{reportId}/Export

    Ensure you're querying the correct workspace by using the right groupId. You may need to list your organization’s workspaces to confirm it. There’s no API to download PBIX files from the Power BI Service. The API only exports report contents (e.g., PDF, PPTX), not the PBIX file.

     

    For more information refer to below link:

    Reports - REST API (Power BI Power BI REST APIs) | Microsoft Learn

    Reports - Export Report In Group - REST API (Power BI Power BI REST APIs) | Microsoft Learn

    Reports - Export To File - REST API (Power BI Power BI REST APIs) | Microsoft Learn

     

    I hope this helps! If you have any more questions or need further assistance, feel free to let me know.

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

    Thankyou

5 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Shiroyasha1 ,

    Thanks for reaching out to the Microsoft fabric community forum.

     

    For your question, here are my answers:

    Q1:  save a pbix file as pbit (main problem to automate):

    • Power BI Desktop doesn't have a built-in way to automatically save PBIX files as PBIT files using command-line tools like PowerShell or Python. The usual "Save As" process to create a PBIT file must be done manually or using the app’s interface.
    • You can automate the process if your PBIX files are uploaded to the Power BI Service using Power Automate or the Power BI REST API. This would require setting up Power Automate desktop flows or writing custom scripts that interact with Power BI.

    For your reference go through it:
    https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/Automate-the-process-of-exporting-Power-BI-files-pbix-to/td-p/489910

     

    Q2: unzip the file and extract the json (feasible in python).

    Once the PBIX files are converted to PBIT files, the next task is to extract the DataModelSchema (JSON) from the PBIT file, which is essentially a ZIP archive.

    Follow below link for your reference:
    zipfile — Work with ZIP archives — Python 3.13.1 documentation

     

    I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

     

    Best regards,

    Pranay
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Shiroyasha1's avatar
      Shiroyasha1
      New Member

      Hi Pranay, thank you for reaching out. 

      Please mind my knowledge gaps, as I am fairly new to this.

       

      Anyways, for Q2 it was smoothly done as for the 1st part, my current solution was to use pyautogui and simulate the exact keyboard steps I need to export a pbix file as pbit.

      Could you elaborate more about the REST API? This could be the solution I need as we are using PowerBI Development Server for both PBIX and SSRS reports, which I'm assuming is the same thing as PowerBI Service. I did connect to https://pbi.#######.com/reports/api/v2.0/Reports. (#### being my org internal name instead). This lists all the SSRS reports and does not include the PBI reports. Is there another API for specifically PBI reports? I found the following from https://learn.microsoft.com/en-us/rest/api/power-bi/reports/export-report -- GET https://api.powerbi.com/v1.0/myorg/reports/{reportId}/Export Is there a way I could utilize this?

      The end goal is obtaining the json file (most likely from a .pbit file). Appreciate your help.

       

      thanks again,

      Ali

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Shiroyasha1 ,

        Thank you for reaching out and sharing the links in your conformation query. Unfortunately, I am unable to access external links. However, I do have detailed information regarding the topic you're asking about.

        As discussed, the Power BI API doesn't support PBIX to PBIT conversion. You could try Power Automate for exporting reports, but it only works with Power BI Service-hosted reports, not local PBIX files.

        You’ve used pyautogui to automate the "Save As" process for exporting PBIX to PBIT, which works but isn’t ideal for large batches.

        You mentioned that you can access the Power BI REST API but only see SSRS reports, not Power BI reports. This indicates that your current access may be pointing to the SSRS reports endpoint rather than Power BI reports.

        The endpoint GET https://api.powerbi.com/v1.0/myorg/reports/{reportId}/Export exports Power BI report contents (e.g., PDF, PPTX), not the PBIX file. To work with Power BI reports, use the correct API endpoints for Power BI reports (not SSRS reports).

         

        To list Power BI reports in your workspace, use:

        GET https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports

        This will return a list of reports (not SSRS) in the specified workspace.

        The endpoint you found exports a Power BI report (not PBIX). After retrieving the report, use the export endpoint to trigger the export.

        GET https://api.powerbi.com/v1.0/myorg/reports/{reportId}/Export

        Ensure you're querying the correct workspace by using the right groupId. You may need to list your organization’s workspaces to confirm it. There’s no API to download PBIX files from the Power BI Service. The API only exports report contents (e.g., PDF, PPTX), not the PBIX file.

         

        For more information refer to below link:

        Reports - REST API (Power BI Power BI REST APIs) | Microsoft Learn

        Reports - Export Report In Group - REST API (Power BI Power BI REST APIs) | Microsoft Learn

        Reports - Export To File - REST API (Power BI Power BI REST APIs) | Microsoft Learn

         

        I hope this helps! If you have any more questions or need further assistance, feel free to let me know.

         

        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

         

        Thankyou