/// <summary>
        /// Gets a specific dataset based on id
        /// </summary>
        /// <param name="id">Guid id of dataset</param>
        /// <returns>PowerBIDataset</returns>
        public static async Task <PowerBIDataset> GetDataset(Guid id)
        {
            PowerBIDataset dataset = null;
            var            token   = await getAccessToken();

            var baseAddress = new Uri("https://api.powerbi.com/beta/myorg/");

            using (var client = new HttpClient {
                BaseAddress = baseAddress
            })
            {
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
                client.DefaultRequestHeaders.Add("Accept", "application/json; odata=verbose");
                using (var response = await client.GetAsync(String.Format("datasets/{0}", id.ToString())))
                {
                    string responseString = await response.Content.ReadAsStringAsync();

                    JObject oResponse = JObject.Parse(responseString);
                }
            }

            return(dataset);
        }
        /// <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);
        }
Esempio n. 3
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);
 }