Forum Discussion

paritoshmishra's avatar
5 years ago

Imports pbix by using Create Temporary Upload location but error in "Imports - Post impost api"

I am using "Imports - Create Temporary Upload Location In Group" to import pbix to workspace having premium capacity.

$uri = "https://api.powerbi.com/v1.0/myorg/groups/XXXXXXX/imports/createTemporaryUploadLocation"

$tulResponse =Invoke-RestMethod -Uri $uri –Headers $auth_header –Method POST
  $tulResponse return  url , expiration ,and odata.context successfully .

$temp_path ="local path of Pbix "

$httpClient = New-Object System.Net.Http.Httpclient $httpClientHandler
$HttpClient.DefaultRequestHeaders.Add("x-ms-blob-type", "BlockBlob");
$packageFileStream = New-Object System.IO.FileStream @($temp_path, [System.IO.FileMode]::Open)
$contentDispositionHeaderValue = New-Object System.Net.Http.Headers.ContentDispositionHeaderValue "form-data"
$contentDispositionHeaderValue.Name = "<< file name>>"
$contentDispositionHeaderValue.FileName = "<<filename.pbix>>"
$streamContent = New-Object System.Net.Http.StreamContent $packageFileStream
$streamContent.Headers.ContentDisposition = $contentDispositionHeaderValue
$content = New-Object System.Net.Http.MultipartFormDataContent
$content.Add($streamContent)

$response1 = $httpClient.PutAsync($tulResponse.url, $content).Result

 

response1 return s

----

Version : 1.1
Content : System.Net.Http.StreamContent
StatusCode : Created
ReasonPhrase : Created
Headers : {[x-ms-request-id, System.String[]], [x-ms-version, System.String[]], [x-ms-request-server-encrypted, System.String[]], [Date, System.String[]]...}
RequestMessage : Method: PUT, RequestUri: 'https://XXxxxxxxxxxx.blob.core.windows.net/xxxxxx/yyyyyyy/Import/zzzz?sv=2015-12-11&sr=b&sig=ccccccc&st=2021-02-23T08:55:39Z&se=2021-02-24T09:00:39Z&sp=w',
Version: 1.1, Content: System.Net.Http.MultipartFormDataContent, Headers:
{
x-ms-blob-type: BlockBlob
Content-Type: multipart/form-data; boundary="xxxxxxxxx"
Content-Length: 1091275
}
IsSuccessStatusCode : True

till then all are good 

if($response1.IsSuccessStatusCode)
{

$bodypost = @{
'fileUrl' = $tulResponse.url
}
$uripost = "https://api.powerbi.com/v1.0/myorg/groups/xxxxx/imports?datasetDisplayName=<<filename>>&nameConflict=CreateOrOverwrite"
$respose2 =Invoke-RestMethod -Uri $uripost -Method POST -Body $bodypost -Headers $auth_header -ContentType 'multipart/form-data'

}

last line throw error 

Invoke-RestMethod : {"error":{"code":"UnknownError","pbi.error":{"code":"UnknownError","parameters":{},"details":[],"exceptionCulprit":1}}}


Please help me out !!  what I missed 

Thanks in advance 
Paritosh

 

7 Replies

  • V-lianl-msft's avatar
    V-lianl-msft
    Community Support

    Hi paritoshmishra ,

     

    Unfortunately It's hard for me to know the problem if I don't go through your whole process, you have to know if the file exists in the destination directory before you make the call.

     

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

    • paritoshmishra's avatar
      paritoshmishra
      Helper I

      Hi Liang 
      Pbix file store in my loacal system i.e $temp_path ="local path of Pbix "
      My pbix size is 1.2 MB .Is it size of file matter ? Is tempoaryloactionupload is only works on file of size is greater then 1 GB ??
      Please help me out 

      TIA

      • Anonymous's avatar
        Anonymous
        Not applicable

        Did you find a solution?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Can you please help with me for this API?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Right now, I am working on this API. I can create temporary blob storage , but by using that Url I can't upload my greater than 1GB report PBIX file.

    I don't know how to resolve this problem, Can you help me to sort out this problem?