public PBIImport ImportPBIX(string displayName, string pbixPath, PBIImportConflictHandlerMode nameConflict = PBIImportConflictHandlerMode.Abort) { string fullUrl = string.Format("{0}/{1}?datasetDisplayName={2}&nameConflict={3}", ApiURL, PBIAPI.Imports.ToString().ToLower(), displayName, nameConflict.ToString()); FileStream content = File.Open(pbixPath, FileMode.Open); Dictionary <string, string> contentHeaders = new Dictionary <string, string>(); contentHeaders.Add("Content-Type", "application/octet-stream"); contentHeaders.Add("Content-Disposition", @"form-data; name=""file""; filename=""" + pbixPath + @""""); using (HttpResponseMessage response = ParentPowerBIAPI.SendPOSTRequest(fullUrl, content, contentHeaders)) { string result = response.ResponseToString(); PBIImport import = JsonConvert.DeserializeObject <PBIImport>(result); import.ParentObject = this; import.ParentPowerBIAPI = ParentPowerBIAPI; if (!(this is PBIAPIClient)) // if the caller is a PBIClient, we do not have a ParentGroup but need to use "My Workspace" instead { import.ParentGroup = this; } return(import); } }
public void AddGroupMember(PBIGroupMember groupMember) { if (this is PBIAPIClient) // if the caller is a PBIClient, we do not have a ParentGroup but need to use "My Workspace" instead { throw new Exception("Cannot add users to 'My Workspace'!"); } using (HttpWebResponse response = ParentPowerBIAPI.SendPOSTRequest(ApiURL, PBIAPI.Users, PBIJsonHelper.SerializeObject(groupMember))) { string result = response.ResponseToString(); } }
public void Rebind(PBIDataset newDataset) { if (ParentPowerBIAPI == null) { throw new Exception("No PowerBI API Object was supplied!"); } using (HttpWebResponse response = ParentPowerBIAPI.SendPOSTRequest(ApiURL + "/Rebind", "{\"datasetId\": \"" + newDataset.Id + "\"}")) { string result = response.ResponseToString(); } }
public void Clone(string newReportName, PBIGroup targetGroup, PBIDataset targetDataset) { if (ParentPowerBIAPI == null) { throw new Exception("No PowerBI API Object was supplied!"); } string body; body = "{\"name\": \"" + newReportName + "\", \"targetModelId\": \"" + targetDataset.Id + "\""; if (targetGroup != null && targetGroup.ParentGroup != null) { body = body + ", \"targetWorkspaceId\": \"" + targetGroup.Id + "\""; } body = body + "}"; using (HttpWebResponse response = ParentPowerBIAPI.SendPOSTRequest(ApiURL + "/Clone", body)) { string result = response.ResponseToString(); } }
public PBIImport ImportPBIX(string displayName, string pbixPath) { string fullUrl = string.Format("{0}/{1}?datasetDisplayName={2}", ApiURL, PBIAPI.Imports.ToString().ToLower(), displayName); FileStream content = File.Open(pbixPath, FileMode.Open); using (HttpWebResponse response = ParentPowerBIAPI.SendPOSTRequest(fullUrl, content)) { string result = response.ResponseToString(); return(JsonConvert.DeserializeObject <PBIImport>(result)); } /* * // create REST URL with import name in quer string * string restUrlImportPbix = ProgramConstants.PowerBiServiceRootUrl + "imports?datasetDisplayName=" + importName; * // load PBIX file into StreamContent object * var pbixBodyContent = new StreamContent(File.Open(pbixPath, FileMode.Open)); * // add headers for request bod content * pbixBodyContent.Headers.Add("Content-Type", "application/octet-stream"); * pbixBodyContent.Headers.Add("Content-Disposition", * @"form-data; name=""file""; filename=""" + pbixFilePath + @""""); * // load PBIX content into body using multi-part form data * MultipartFormDataContent requestBody = new MultipartFormDataContent(Guid.NewGuid().ToString()); * requestBody.Add(pbixBodyContent); * // create and configure HttpClient * HttpClient client = new HttpClient(); * client.DefaultRequestHeaders.Add("Accept", "application/json"); * client.DefaultRequestHeaders.Add("Authorization", "Bearer " + AccessToken); * // post request * var response = client.PostAsync(restUrlImportPbix, requestBody).Result; * // check for success * if (response.StatusCode.ToString().Equals("Accepted")) * { * Console.WriteLine("Import process complete: " + response.Content.ReadAsStringAsync().Result); * } */ }