Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
In order to perform this action with code, we will draw from the SimplePBI Library built by LaDataWeb, but before diving into the code, let's explain how it works.
As of today, the API query catalog does not provide a method that allows us to copy .pbix files, but we do have other methods that will help us achieve this result. To do this, the following permissions will be necessary:
Report.ReadWrite.All and Dataset.ReadWrite.All
The first step will be to determine the environment in which to write our code to copy the reports. I recommend using a cloud environment such as an AzureVM, Azure Function, Automation Runbook, etc. Let's see why it's necessary and recommended to be in the cloud.
As we can see, since there is no native request for this, the way to do it will be by exporting and then re-importing the .pbix file. If our environment is local, we will have to download and upload it again, which can take quite some time depending on the file size. If we use a cloud environment, we can significantly reduce the time spent adjusting to local bandwidth.
Our library will contain the necessary method under the "Reports" category. Execution is quite straightforward. First, we import the necessary packages:
from simplepbi import token
from simplepbi import reports
We initialize objects by category to perform actions more comfortably:
t = token.Token(tenant_id, power_bi_client_id, power_bi_username, power_bi_password, None, use_service_principal=False)
r = reports.Reports(t.token)
NOTE: Remember that we can create our token by authenticating with a service principal if we locate the secret where we see the None and change the last argument to use_service_principal=True.
Once all that is created, we simply call the method with our desired values:
r.simple_copy_reports_between_groups(workspace_id_origin, report_id, workspace_id_destination, displayName=None, nameConflict="CreateOrOverwrite")
The arguments are:
Restrictions: This method only allows copying of reports that contain the dataset (less than 1Gb). It does not work with Live Connection.
With that simple line, we will have succeeded in making the copy of the report. This could help us generate our own deployment between different development environments of workspaces. I hope you find it useful and enjoy it. Follow SimplePBI for more useful methods built with API requests. Who knows, maybe one day we'll have one for copying between different tenants.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.