Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
najoua
New Member

Migrate Power BI report to Azure Power Bi Embedded

Hey Guys,

 

I'm working on integrating Power BI Embedded report into my web application, I followed  this article to create a workspace and reports in Azure power Bi Embedded end.

Is there a way to import pbix files via Microsoft Azure instead of running the console app utility?

 

Any help is appreciated.

 

Thanks,

1 ACCEPTED SOLUTION


@najoua wrote:

Hey Guys,

 

I'm working on integrating Power BI Embedded report into my web application, I followed  this article to create a workspace and reports in Azure power Bi Embedded end.

Is there a way to import pbix files via Microsoft Azure instead of running the console app utility?

 

Any help is appreciated.

 

Thanks,


@najoua

AFAIK, there's no such a Azure service. The console app is just one utility for ones who don't know coding. Since you're working on integrating PBI Embedded report into your own web app, so I suppose that you're a developer guy who has coding skills? Then you can reference below C# code to call the POST API. With below demo, you could create any toolkit by yourself to import pbix file if you don't like the console utility.

 

using System;
using System.Net;
using System.IO;  
namespace PBIGettingStarted
{
    class Program
    {
        //Access key for app token
        private static string accessKey = "myaccesskey";
//Power BI app token values
        private static string workspaceCollectionName = "myworkspace";
        private static string workspaceId = "myworkspaceid";
private static string pbixFileName = "AdventureWorksdddd.pbix";
static void Main(string[] args)
        {
            //Imports uri
            var uri = String.Format
                ("https://api.powerbi.com/v1.0/collections/{0}/workspaces/{1}/imports?datasetDisplayName=SampleImport",
                workspaceCollectionName, workspaceId);
//PBIX file to import
            DirectoryInfo di = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
            string fileName = @"C:\test\mytest.pbix";
 
            //Create web request
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
//Import Request format:
            // Header:
            //  Content - Type: multipart / form - data; ----------BOUNDARY
            //  Authorization: AppToken
// Body:
            //  ----------BOUNDARY
            //  Content - Disposition: form - data; filename = "{pbix file}.pbix"
            //  Content - Type: application / octet – stream

//Define POST
            request.Method = "POST";
            request.UseDefaultCredentials = true;
//Header
            // Boundary
            string boundary = "----------BOUNDARY";
            byte[] boundaryBytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
// Content - Type
            request.ContentType = "multipart/form-data; boundary=" + boundary;
// Authorization - Use AppToken jwt for Authorization header
            request.Headers.Add("Authorization", String.Format("AppKey {0}", accessKey));
//Body
            string bodyTemplate = "Content-Disposition: form-data; filename=\"{0}\"\r\nContent-Type: application / octet - stream\r\n\r\n";
            string body = string.Format(bodyTemplate, fileName);
            byte[] bodyBytes = System.Text.Encoding.UTF8.GetBytes(body);
//Get request stream 
            using (Stream rs = request.GetRequestStream())
            {
                rs.Write(boundaryBytes, 0, boundaryBytes.Length);
                rs.Write(bodyBytes, 0, bodyBytes.Length);
using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    byte[] buffer = new byte[4096];
                    int bytesRead = 0;
                    while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
                    {
                        rs.Write(buffer, 0, bytesRead);
                    }
                }
byte[] trailer = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
                rs.Write(trailer, 0, trailer.Length);
            }
//Get response
            using (HttpWebResponse response = request.GetResponse() as System.Net.HttpWebResponse)
            {
                //If Import succeeds, StatusCode = Accepted 
                var responseStatusCode = response.StatusCode.ToString();
            }
        }
    }
     
}

View solution in original post

2 REPLIES 2
najoua
New Member

Hey Guys,

 

I'm working on integrating Power BI Embedded report into my web application, I followed  this article to create a workspace and reports in Azure power Bi Embedded end.

Is there a way to import pbix files via Microsoft Azure instead of running the console app utility?

 

Any help is appreciated.

 

Thanks,


@najoua wrote:

Hey Guys,

 

I'm working on integrating Power BI Embedded report into my web application, I followed  this article to create a workspace and reports in Azure power Bi Embedded end.

Is there a way to import pbix files via Microsoft Azure instead of running the console app utility?

 

Any help is appreciated.

 

Thanks,


@najoua

AFAIK, there's no such a Azure service. The console app is just one utility for ones who don't know coding. Since you're working on integrating PBI Embedded report into your own web app, so I suppose that you're a developer guy who has coding skills? Then you can reference below C# code to call the POST API. With below demo, you could create any toolkit by yourself to import pbix file if you don't like the console utility.

 

using System;
using System.Net;
using System.IO;  
namespace PBIGettingStarted
{
    class Program
    {
        //Access key for app token
        private static string accessKey = "myaccesskey";
//Power BI app token values
        private static string workspaceCollectionName = "myworkspace";
        private static string workspaceId = "myworkspaceid";
private static string pbixFileName = "AdventureWorksdddd.pbix";
static void Main(string[] args)
        {
            //Imports uri
            var uri = String.Format
                ("https://api.powerbi.com/v1.0/collections/{0}/workspaces/{1}/imports?datasetDisplayName=SampleImport",
                workspaceCollectionName, workspaceId);
//PBIX file to import
            DirectoryInfo di = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
            string fileName = @"C:\test\mytest.pbix";
 
            //Create web request
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
//Import Request format:
            // Header:
            //  Content - Type: multipart / form - data; ----------BOUNDARY
            //  Authorization: AppToken
// Body:
            //  ----------BOUNDARY
            //  Content - Disposition: form - data; filename = "{pbix file}.pbix"
            //  Content - Type: application / octet – stream

//Define POST
            request.Method = "POST";
            request.UseDefaultCredentials = true;
//Header
            // Boundary
            string boundary = "----------BOUNDARY";
            byte[] boundaryBytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
// Content - Type
            request.ContentType = "multipart/form-data; boundary=" + boundary;
// Authorization - Use AppToken jwt for Authorization header
            request.Headers.Add("Authorization", String.Format("AppKey {0}", accessKey));
//Body
            string bodyTemplate = "Content-Disposition: form-data; filename=\"{0}\"\r\nContent-Type: application / octet - stream\r\n\r\n";
            string body = string.Format(bodyTemplate, fileName);
            byte[] bodyBytes = System.Text.Encoding.UTF8.GetBytes(body);
//Get request stream 
            using (Stream rs = request.GetRequestStream())
            {
                rs.Write(boundaryBytes, 0, boundaryBytes.Length);
                rs.Write(bodyBytes, 0, bodyBytes.Length);
using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    byte[] buffer = new byte[4096];
                    int bytesRead = 0;
                    while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
                    {
                        rs.Write(buffer, 0, bytesRead);
                    }
                }
byte[] trailer = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
                rs.Write(trailer, 0, trailer.Length);
            }
//Get response
            using (HttpWebResponse response = request.GetResponse() as System.Net.HttpWebResponse)
            {
                //If Import succeeds, StatusCode = Accepted 
                var responseStatusCode = response.StatusCode.ToString();
            }
        }
    }
     
}

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.