Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hello @All.
I am trying to upload one pbix report through "Post Import in Group" powerBI Rest API but getting 404 error. I followed the following link:
https://docs.microsoft.com/en-us/rest/api/power-bi/imports/post-import-in-group#post-import-example
But it is not helpful here. I am using following code. Please let me know if anyone can help me here.
var url = $"https://api.powerbi.com/v1.0/myorg/groups/{targetWorkspaceId}/imports?datasetDisplayName={downloadedDataset.Name}&nameConflict=Overwrite";
string boundary = String.Format("----------{0:N}", Guid.NewGuid());
string contentType = "multipart/form-data; boundary=" + boundary;
using (MemoryStream ms = new MemoryStream())
{
downloadedReportStream.CopyTo(ms);
var file_bytes = ms.ToArray();
byte[] formData = GetMultipartFormData(boundary, report.Name+".pbix", file_bytes);
var httpWebResponse = PostForm(url, contentType, formData, "Authorization", String.Format("Bearer {0}", GetPBIAccessToken()));
var responseStatusCode = httpWebResponse.StatusCode.ToString();
Console.WriteLine("imported pbix ", responseStatusCode);
}
//private methods
private static byte[] GetMultipartFormData(string boundary, string fileName, byte[] fileBytes)
{
Stream formDataStream = new System.IO.MemoryStream();
// Add just the first part of this param, since we will write the file data directly to the Stream
string header = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\"\r\nContent-Type: {3}\r\n\r\n",
boundary,
fileName,
fileName,
"application/octet-stream");
formDataStream.Write(Encoding.ASCII.GetBytes(header), 0, Encoding.ASCII.GetByteCount(header));
// Write the file data directly to the Stream, rather than serializing it to a string.
formDataStream.Write(fileBytes, 0, fileBytes.Length);
// Add the end of the request. Start with a newline
string footer = "\r\n--" + boundary + "--\r\n";
formDataStream.Write(Encoding.ASCII.GetBytes(footer), 0, Encoding.ASCII.GetByteCount(footer));
// Dump the Stream into a byte[]
formDataStream.Position = 0;
byte[] formData = new byte[formDataStream.Length];
formDataStream.Read(formData, 0, formData.Length);
formDataStream.Close();
return formData;
}
private static HttpWebResponse PostForm(string postUrl, string contentType, byte[] fileData, string headerkey, string headervalue)
{
HttpWebRequest request = WebRequest.Create(postUrl) as HttpWebRequest;
if (request == null)
{
throw new NullReferenceException("request is not a http request");
}
// Set up the request properties.
request.Method = "POST";
request.ContentType = contentType;
//request.CookieContainer = new CookieContainer();
request.ContentLength = fileData.Length;
//Add header if needed
request.Headers.Add(headerkey, headervalue);
// Send the form data to the request.
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(fileData, 0, fileData.Length);
requestStream.Close();
}
return request.GetResponse() as HttpWebResponse;
}
Hi @sachin131 ,
Whether your problem has been resolved? If yes, could you please mark the helpful post as Answered? It will help the others in the community find the solution easily if they face the same problem as yours. Thank you.
Best Regards
Hi @sachin131 ,
Please check if it hit any following limitations, you can find the details in this official documentation.
Error 404: what it means and how to fix it
Best Regards
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |