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 all recent access attempts // GET /access_settings/activity string queryParams = @"{ 'limit': 1 }"; dynamic response = await sg.client.access_settings.activity.get(queryParams: queryParams); Console.WriteLine(response.StatusCode); Console.WriteLine(response.Body.ReadAsStringAsync().Result); Console.WriteLine(response.Headers.ToString()); Console.ReadLine(); //////////////////////////////////////////////////////// // Add one or more IPs to the whitelist // POST /access_settings/whitelist string data = @"{ 'ips': [ { 'ip': '192.168.1.1' }, { 'ip': '192.*.*.*' }, { 'ip': '192.168.1.3/32' } ] }"; Object json = JsonConvert.DeserializeObject(data); data = json.ToString(); dynamic response = await sg.client.access_settings.whitelist.post(requestBody: data); Console.WriteLine(response.StatusCode); Console.WriteLine(response.Body.ReadAsStringAsync().Result); Console.WriteLine(response.Headers.ToString()); Console.ReadLine(); //////////////////////////////////////////////////////// // Retrieve a list of currently whitelisted IPs // GET /access_settings/whitelist dynamic response = await sg.client.access_settings.whitelist.get(); Console.WriteLine(response.StatusCode); Console.WriteLine(response.Body.ReadAsStringAsync().Result); Console.WriteLine(response.Headers.ToString()); Console.ReadLine(); //////////////////////////////////////////////////////// // Remove one or more IPs from the whitelist // DELETE /access_settings/whitelist string data = @"{ 'ids': [ 1, 2, 3 ] }"; Object json = JsonConvert.DeserializeObject(data); data = json.ToString(); dynamic response = await sg.client.access_settings.whitelist.delete(requestBody: data); Console.WriteLine(response.StatusCode); Console.WriteLine(response.Body.ReadAsStringAsync().Result); Console.WriteLine(response.Headers.ToString()); Console.ReadLine(); //////////////////////////////////////////////////////// // Retrieve a specific whitelisted IP // GET /access_settings/whitelist/{rule_id} var rule_id = "test_url_param"; dynamic response = await sg.client.access_settings.whitelist._(rule_id).get(); Console.WriteLine(response.StatusCode); Console.WriteLine(response.Body.ReadAsStringAsync().Result); Console.WriteLine(response.Headers.ToString()); Console.ReadLine(); //////////////////////////////////////////////////////// // Remove a specific IP from the whitelist // DELETE /access_settings/whitelist/{rule_id} var rule_id = "test_url_param"; dynamic response = await sg.client.access_settings.whitelist._(rule_id).delete(); Console.WriteLine(response.StatusCode); Console.WriteLine(response.Body.ReadAsStringAsync().Result); Console.WriteLine(response.Headers.ToString()); Console.ReadLine();