using System; using SendGrid.Helpers.Mail; // If you are using the Mail Helper using Newtonsoft.Json; // You can generate your JSON string yourelf or with another library if you prefer string _apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); dynamic sg = new SendGrid.SendGridAPIClient(_apiKey); //////////////////////////////////////////////////////// // Retrieve email statistics by client type. // GET /clients/stats string queryParams = @"{ 'aggregated_by': 'day', 'end_date': '2016-04-01', 'start_date': '2016-01-01' }"; dynamic response = await sg.client.clients.stats.get(queryParams: queryParams); Console.WriteLine(response.StatusCode); Console.WriteLine(response.Body.ReadAsStringAsync().Result); Console.WriteLine(response.Headers.ToString()); Console.ReadLine(); //////////////////////////////////////////////////////// // Retrieve stats by a specific client type. // GET /clients/{client_type}/stats string queryParams = @"{ 'aggregated_by': 'day', 'end_date': '2016-04-01', 'start_date': '2016-01-01' }"; var client_type = "test_url_param"; dynamic response = await sg.client.clients._(client_type).stats.get(queryParams: queryParams); Console.WriteLine(response.StatusCode); Console.WriteLine(response.Body.ReadAsStringAsync().Result); Console.WriteLine(response.Headers.ToString()); Console.ReadLine();