Esempio n. 1
0
        /// <summary>
        /// Creates a dataset, including tables/columns
        /// </summary>
        /// <param name="dataset">PowerBIDataset</param>
        /// <returns>Guid id of the new dataset</returns>
        public static async Task<Guid> CreateDataset(PowerBIDataset dataset)
        {
            var token = await getAccessToken();
            var baseAddress = new Uri("https://api.powerbi.com/beta/myorg/");
            using (var client = new HttpClient{ BaseAddress = baseAddress })
            {
                var content = new StringContent(JsonConvert.SerializeObject(dataset).Replace("\"id\":\"00000000-0000-0000-0000-000000000000\",", ""), System.Text.Encoding.Default, "application/json");
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
                client.DefaultRequestHeaders.Add("Accept", "application/json");
                using (var response = await client.PostAsync("datasets", content))
                {
                    string responseString = await response.Content.ReadAsStringAsync();
                    JObject oResponse = JObject.Parse(responseString);
                    dataset.id = new Guid(oResponse.SelectToken("id").ToString());
                }
            }

            return dataset.id;
        }
 public async Task<Guid> CreateDataset(PowerBIDataset dataset)
 {
     return await PowerBIModel.CreateDataset(dataset);
 }