cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
talatiniket Member
Member

"skipReport=True" in import gives error in RestAPI

Hi,

 

When I use skipReport=True in import rest API, my code doesn't work and gives 404 error message in response code.

This work fines:

 

 try {
            "== Importing $report_name to target workspace"
            $uri = "https://api.powerbi.com/v1.0/$target_group_path/imports/?datasetDisplayName=$report_name.pbix&nameConflict=Overwrite"

            # Here we switch to HttpClient class to help POST the form data for importing PBIX
            $httpClient = New-Object System.Net.Http.Httpclient $httpClientHandler
            $httpClient.DefaultRequestHeaders.Authorization = New-Object System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", $token.AccessToken);
            $packageFileStream = New-Object System.IO.FileStream @($temp_path, [System.IO.FileMode]:Smiley Surprisedpen)
        
            $contentDispositionHeaderValue = New-Object System.Net.Http.Headers.ContentDispositionHeaderValue "form-data"
            $contentDispositionHeaderValue.Name = "file0"
            $contentDispositionHeaderValue.FileName = $file_name
 
            $streamContent = New-Object System.Net.Http.StreamContent $packageFileStream
            $streamContent.Headers.ContentDisposition = $contentDispositionHeaderValue
        
            $content = New-Object System.Net.Http.MultipartFormDataContent
            $content.Add($streamContent)
            $response = $httpClient.PostAsync($Uri, $content).Result            
            Write-Verbose -Verbose $response
 
            if (!$response.IsSuccessStatusCode) {
                $responseBody = $response.Content.ReadAsStringAsync().Result
                "= This report cannot be imported to target workspace. Skipping..."
                $errorMessage = "Status code {0}. Reason {1}. Server reported the following message: {2}." -f $response.StatusCode, $response.ReasonPhrase, $responseBody
                throw [System.Net.Http.HttpRequestException] $errorMessage
            } 

This don't:

try {
            "== Importing $report_name to target workspace"
            $uri = "https://api.powerbi.com/v1.0/$target_group_path/imports/?datasetDisplayName=$report_name.pbix&nameConflict=Overwrite&skipReport=True"

            # Here we switch to HttpClient class to help POST the form data for importing PBIX
            $httpClient = New-Object System.Net.Http.Httpclient $httpClientHandler
            $httpClient.DefaultRequestHeaders.Authorization = New-Object System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", $token.AccessToken);
            $packageFileStream = New-Object System.IO.FileStream @($temp_path, [System.IO.FileMode]:Smiley Surprisedpen)
        
            $contentDispositionHeaderValue = New-Object System.Net.Http.Headers.ContentDispositionHeaderValue "form-data"
            $contentDispositionHeaderValue.Name = "file0"
            $contentDispositionHeaderValue.FileName = $file_name
 
            $streamContent = New-Object System.Net.Http.StreamContent $packageFileStream
            $streamContent.Headers.ContentDisposition = $contentDispositionHeaderValue
        
            $content = New-Object System.Net.Http.MultipartFormDataContent
            $content.Add($streamContent)
            $response = $httpClient.PostAsync($Uri, $content).Result            
            Write-Verbose -Verbose $response    
 
            if (!$response.IsSuccessStatusCode) {
                $responseBody = $response.Content.ReadAsStringAsync().Result
                "= This report cannot be imported to target workspace. Skipping..."
                $errorMessage = "Status code {0}. Reason {1}. Server reported the following message: {2}." -f $response.StatusCode, $response.ReasonPhrase, $responseBody
                throw [System.Net.Http.HttpRequestException] $errorMessage
            }

Only change is I have added &skipReport=True in uri.

 

Can you please help to solve this. Basically I just want to import dataset not report.

 

Thank you in advance!

 

Regards,

Niket Talati