<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: 'Post in Group' API using Nodejs in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Post-in-Group-API-using-Nodejs/m-p/2046932#M31442</link>
    <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/70763"&gt;@dpiret&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ended up contacting MSFT support about this issue shortly after posting here. They told me that the Content-Length header is required but is not listed in their documentation&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/imports/post-import-in-group" target="_blank"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/imports/post-import-in-group&lt;/A&gt;&amp;nbsp;- they also told me that they would update the documentation to include this detail but have not done so.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am still using the method I described above (write the file to disk, calculate length, submit, delete from disk) but I would prefer not to. If you figure anything else out please share &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 30 Aug 2021 18:44:40 GMT</pubDate>
    <dc:creator>nfadili</dc:creator>
    <dc:date>2021-08-30T18:44:40Z</dc:date>
    <item>
      <title>'Post in Group' API using Nodejs</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Post-in-Group-API-using-Nodejs/m-p/1054892#M23377</link>
      <description>&lt;P&gt;Hello. I am implementing a feature that allows a user to upload a .pbix file from their local machine through our webpage and have it published into a Power BI workspace by our web app's server. The only way I was able to get this to work was by creating a temp file of the user's .pbix on the server, calculating it's length, and then sending the POST /imports request with a `Content-Length` header with that length along with a stream of the temp file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My main question is this: &lt;STRONG&gt;does the POST /imports endpoint require the 'Content-Length' to be calculated before the request is sent?&lt;/STRONG&gt; I am trying to avoid storing potentially large temp files on the server (which is how I can get the length). The ideal scenario is that the file streams from the browser to the nodejs server, and then directly to the Power BI API endpoint. I have tried various http libraries and various combinations of headers and received a few different errors from Power BI. Sometimes I get 500 Internal Server Error responses with no detail, and sometimes I get 400 InvalidFileSizeError responses like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{"error":{"code":"InvalidFileSizeError","pbi.error":{"code":"InvalidFileSizeError","parameters":{"FileSize":"9223372036854775807"},"details":[],"exceptionCulprit":1}}}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems that with nodejs if a 'Content-Length' header is not specified when sending a stream it might default to using `Infinity`. Not sure if that is pertinent or not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a rough idea of the code that prints responses from Power BI:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const fetch = require('node-fetch');
const FormData = require('form-data');


const form: FormData = new FormData();

// readStream is a stream from the post request to the node server from the browser and is made with `createReadStream` from the 'streams' module
form.append('', readStream); 

const url = `https://api.powerbi.com/v1.0/myorg/groups/${workspaceId}/imports?datasetDisplayName=${displayName}&amp;amp;nameConflict=Abort`;
const options = {
    method: 'POST',
    body: form,
    headers: {
        Authorization: `Bearer &amp;lt;token&amp;gt;`,
        ...form.getHeaders()
    }
};

return fetch(url, options)
    .then((res) =&amp;gt; {
        console.log(res.ok);
        console.log(res.status);
        console.log(res.statusText);
        console.log(res.headers.raw());
        return res.text();
    })
    .then((data) =&amp;gt; console.log(data))
    .catch((err) =&amp;gt; {
        console.log(err);
    });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone knows the reason for these errors or has any experience with streaming forms to Power BI, any help would be very very much appreciated. Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Helpful links&lt;/U&gt;&lt;/P&gt;&lt;P&gt;- &lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/imports/postimportingroup" target="_blank" rel="noopener"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/imports/postimportingroup&lt;/A&gt;&lt;/P&gt;&lt;P&gt;- &lt;A href="https://github.com/form-data/form-data#readme" target="_blank" rel="noopener"&gt;https://github.com/form-data/form-data#readme&lt;/A&gt;&lt;/P&gt;&lt;P&gt;- &lt;A href="https://github.com/node-fetch/node-fetch" target="_blank" rel="noopener"&gt;https://github.com/node-fetch/node-fetch&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 01:11:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Post-in-Group-API-using-Nodejs/m-p/1054892#M23377</guid>
      <dc:creator>nfadili</dc:creator>
      <dc:date>2020-04-29T01:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: 'Post in Group' API using Nodejs</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Post-in-Group-API-using-Nodejs/m-p/2043976#M31404</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/101894"&gt;@nfadili&lt;/a&gt;&amp;nbsp;, did you sort this out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having the exact same message issue using Axios (I guess FileSize: '9223372036854775807' means infinite?). Mi pbix file size i s just 194KB&lt;/P&gt;&lt;P&gt;My code is quite similar to yours&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;async postImportInGroup(groupId, datasetDisplayName) {
try {
   let AccessToken = await auth.getMicrosoftToken();
   var formData = new FormData();
   formData.append(datasetDisplayName, fs.createReadStream(__basedir +'/pbix/workspace-master.pbix'));
   var headers = formData.getHeaders();
   headers['Authorization'] = `Bearer ${AccessToken}`;
   headers['content-type'] = 'multipart/form-data'
   const options = {
      method: 'POST',
      headers: headers,
      data: formData,
      url: Mustache.render("https://api.powerbi.com/v1.0/myorg/groups/{{groupId}}/imports?datasetDisplayName={{datasetDisplayName}}", { groupId: groupId, datasetDisplayName: datasetDisplayName }),
   };
   let response = await axios(options)
   return response.data
   }&lt;/LI-CODE&gt;&lt;P&gt;cheers&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Aug 2021 15:13:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Post-in-Group-API-using-Nodejs/m-p/2043976#M31404</guid>
      <dc:creator>dpiret</dc:creator>
      <dc:date>2021-08-28T15:13:19Z</dc:date>
    </item>
    <item>
      <title>Re: 'Post in Group' API using Nodejs</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Post-in-Group-API-using-Nodejs/m-p/2046932#M31442</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/70763"&gt;@dpiret&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ended up contacting MSFT support about this issue shortly after posting here. They told me that the Content-Length header is required but is not listed in their documentation&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/imports/post-import-in-group" target="_blank"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/imports/post-import-in-group&lt;/A&gt;&amp;nbsp;- they also told me that they would update the documentation to include this detail but have not done so.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am still using the method I described above (write the file to disk, calculate length, submit, delete from disk) but I would prefer not to. If you figure anything else out please share &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Aug 2021 18:44:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Post-in-Group-API-using-Nodejs/m-p/2046932#M31442</guid>
      <dc:creator>nfadili</dc:creator>
      <dc:date>2021-08-30T18:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: 'Post in Group' API using Nodejs</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Post-in-Group-API-using-Nodejs/m-p/2054650#M31519</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/101894"&gt;@nfadili&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I made it work, but I'm unsure whether it will help you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used form-data's async &lt;STRONG&gt;getLength()&lt;/STRONG&gt; function, which returns the length of the stream. This length is not exactly the file's lenght you obtain from the disk:&lt;/P&gt;&lt;P&gt;-&amp;nbsp;&lt;SPAN&gt;fs&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;statSync&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;__basedir&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;+&lt;/SPAN&gt;&lt;SPAN&gt;'/pbix/workspace-master.pbix'&lt;/SPAN&gt;&lt;SPAN&gt;).&lt;/SPAN&gt;&lt;SPAN&gt;size:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;199460&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- from getLenght:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;199672&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;A crude working version looks like this&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;try {
 let AccessToken = await auth.getMicrosoftToken();
 var formData = new FormData();
 formData.append(datasetDisplayName,fs.readFileSync(__basedir +'/pbix/workspace-master.pbix'));

 var options={};
 options.method= 'POST';
 options.data= formData;
 options.url= Mustache.render("https://api.powerbi.com/v1.0/myorg/groups/{{groupId}}/imports?datasetDisplayName={{datasetDisplayName}}", { groupId: groupId, datasetDisplayName: datasetDisplayName });

 var headers = formData.getHeaders();
 headers['Authorization'] = `Bearer ${AccessToken}`;
 headers['content-type'] = 'multipart/form-data'

 formData.getLength(async function(err, len) {
   headers['Content-Length']=len;
   options.headers= headers;
   console.log(`uploading PIX ${datasetDisplayName} to the workspace ${groupId}`)
   let response = await http.axios(options)
   console.log(`It may have worked\n${JSON.stringify(response.data)}`);
   return response.data
 });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I guess I'll see you around&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;d&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 16:40:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Post-in-Group-API-using-Nodejs/m-p/2054650#M31519</guid>
      <dc:creator>dpiret</dc:creator>
      <dc:date>2021-09-02T16:40:27Z</dc:date>
    </item>
  </channel>
</rss>

