powerbi – Post Power BI Rest API statement within rest client visual code


I am using REST CLIENT extension for visual code and trying to post report into workspace
using this APIs: Microsoft Documentation for Posting Report File to Workspace

with GET statement there is no issue:
GET {{baseUrl}}/groups
Authorization: Bearer {{$aadV2Token new scopes:https://analysis.windows.net/powerbi/api/.default clientId:00f30f16-xxxx-xxxx-xxxx-xxxxxxxxx}}

it is returning response without any issues.

But how to make a post statement and refer to path local location?:
I tried with:

POST https://api.powerbi.com/v1.0/myorg/groups/8dc93093-a45a-4e50-9d4f-3766a43f2a07/imports
Authorization: Bearer {{$aadV2Token scopes:https://analysis.windows.net/powerbi/api/.default clientId:00f30f16-24bf-4f48-abe0-9d10095b25ff}}
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="DeploymentTableToPDFCopy.pbix"
Content-Type: application/octet-stream

< @C:/Users/User/Documents/DeploymentTableToPDFCopy.pbix
----WebKitFormBoundary7MA4YWxkTrZu0gW--

but it bad request syntax.

And what i found is code here from javascript which is working:

let url="https://api.powerbi.com/v1.0/myorg/groups/" + groupId + '/imports';
    
let options = {
  method: 'POST',
  headers: {
    'Content-Type': 'multipart/form-data',
    'authorization': 'Bearer ' + accessToken
  },
  body: fs.createReadStream(__dirname + '/Report.pbix'),
  url: 'https://api.powerbi.com/v1.0/myorg/groups/' + groupId + '/imports'
};

rp(options)
  .then(function (body) {
  console.log('success! ', body);
})
  .catch(function (err) {
  console.log('error', err);
});

how to move it to rest client extension in visual code? What will be the proper syntax?

Best Wishes,
Jacek

Leave a Reply

Your email address will not be published. Required fields are marked *