예제 #1
0
        static DatasetManager()
        {
            string AccessToken = TokenManger.GetAccessTokenInteractive(scopesManageDashboards);

            pbiClient = new PowerBIClient(new Uri(urlPowerBiRestApiRoot),
                                          new TokenCredentials(AccessToken, "Bearer"));
        }
예제 #2
0
        private static string CreateDatasetFromJSON(string json)
        {
            string accessToken = TokenManger.GetAccessTokenWithUserPassword(scopesManageDashboards);
            string restUri     = urlPowerBiRestApiRoot + "v1.0/myorg/groups/" + appWorkspaceId + "/datasets/";

            HttpContent body = new StringContent(json);

            body.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Add("Accept", "application/json");
            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
            HttpResponseMessage response = client.PostAsync(restUri, body).Result;

            string datasetId = string.Empty;

            if (response.IsSuccessStatusCode)
            {
                string      jsonResult = response.Content.ReadAsStringAsync().Result;
                JsonDataset dataset    = JsonConvert.DeserializeObject <JsonDataset>(jsonResult);
                datasetId = dataset.id;
            }

            return(datasetId);
        }