cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
oroberto
Frequent Visitor

multipartmimestreamformatexception error when importing pbix files using rest api

hi,

 

So I'm using powershell to automate my power BI reports into my workspace through imports API.

here's the code which I'm using :

    $PBIXuri="my azure blob storage url",
    $Workspaceurl="https://api.powerbi.com/v1.0/myorg/groups/mygroups/imports?datasetDisplayName=myreportname",
    $AccessToken="my oauth token"

    #download my pbix file from azure blob storage
    $cli = New-Object System.Net.WebClient
    $exportpbix = $cli.DownloadData($PBIXuri)

    $powerBiBody = @'
    --exptest
    Content-Disposition: form-data; name="file";
    Content-Type: application/x-zip-compressed

    {0}
    --exptest--

    '@

    #set my pbix file into request body
    $encoding = [System.Text.Encoding]::GetEncoding('iso-8859-1')
    $body = $powerBiBody -f $encoding.GetString($exportpbix)

    $headers = @{
    "Authorization" = "Bearer " + $AccessToken}

    Invoke-RestMethod -Uri $Workspaceurl -Method Post -Headers $headers -Body $body -ContentType "multipart/form-data; boundary=--exptest"

 

but it always return an error like :

 

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

 

where do I went wrong on my code?

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Top Solution Authors