Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
sammicrosoft
New Member

Unable to Clone or Copy the Power BI Report

Dear All,

 

I had written the below code to clone the Power BI report , But I don't find the luck to clone the report .

Can any one help me in knowing what's wrong in my below code.

 

Code:

 

 

function CopyReport(reportId, Name, Dataset) {
    debugger;
    var deferred = $.ajax({
        url: "https://api.powerbi.com/v1.0/myorg/reports/" + reportId + "/Clone",
        type: "POST",
        headers: {
            "Authorization": "Bearer " + accessToken
        },
       // ContentType: "application/json",
        data: { Name: Name},
        //data: { name: Name, targetWorkspaceId: Dataset },
        success: function (responseData) {
            cache.write(responseData, "Copy report")
        },
        error: function (responseData) {
            debugger;
            cache.write(responseData, "Copy report")
        }
    });
    return deferred.promise();
}

Error:

{"error":{"code":"PowerBINotAuthorizedException","pbi.error":{"code":"PowerBINotAuthorizedException","parameters":{},"details":[],"exceptionCulprit":1}}}

 

1 ACCEPTED SOLUTION
Eric_Zhang
Employee
Employee

@sammicrosoft

As per the online documentation Clone report, it requires 3 parameters in the data JSON when calling that API. Based on my test, the below demo works to copy a report.

function CopyReport(reportId, Name, targetworkspace, targetDataset) {
    debugger;
    var deferred = $.ajax({
        url: "https://api.powerbi.com/v1.0/myorg/reports/" + reportId + "/Clone",
        type: "POST",
        headers: {
            "Authorization": "Bearer " + accesstoken
        },
       // ContentType: "application/json",
        //data: { Name: Name},
        data: { name: Name, targetWorkspaceId: targetworkspace, targetModelId:targetDataset},
        success: function (responseData) {
            cache.write(responseData, "Copy report")
        },
        error: function (responseData) {
            debugger;
            cache.write(responseData, "failed copying report")
        }
    });
    return deferred.promise();
}

View solution in original post

1 REPLY 1
Eric_Zhang
Employee
Employee

@sammicrosoft

As per the online documentation Clone report, it requires 3 parameters in the data JSON when calling that API. Based on my test, the below demo works to copy a report.

function CopyReport(reportId, Name, targetworkspace, targetDataset) {
    debugger;
    var deferred = $.ajax({
        url: "https://api.powerbi.com/v1.0/myorg/reports/" + reportId + "/Clone",
        type: "POST",
        headers: {
            "Authorization": "Bearer " + accesstoken
        },
       // ContentType: "application/json",
        //data: { Name: Name},
        data: { name: Name, targetWorkspaceId: targetworkspace, targetModelId:targetDataset},
        success: function (responseData) {
            cache.write(responseData, "Copy report")
        },
        error: function (responseData) {
            debugger;
            cache.write(responseData, "failed copying report")
        }
    });
    return deferred.promise();
}

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.