import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.sendgrid.*; import java.io.IOException; import java.util.HashMap; import java.util.Map; ////////////////////////////////////////////////////////////////// // Get a user's account information. // GET /user/account public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.GET); request.setEndpoint("user/account"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Retrieve your credit balance // GET /user/credits public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.GET); request.setEndpoint("user/credits"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Update your account email address // PUT /user/email public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.PUT); request.setEndpoint("user/email"); request.setBody("{\"email\":\"[email protected]\"}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Retrieve your account email address // GET /user/email public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.GET); request.setEndpoint("user/email"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Update your password // PUT /user/password public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.PUT); request.setEndpoint("user/password"); request.setBody("{\"new_password\":\"new_password\",\"old_password\":\"old_password\"}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Update a user's profile // PATCH /user/profile public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.PATCH); request.setEndpoint("user/profile"); request.setBody("{\"city\":\"Orange\",\"first_name\":\"Example\",\"last_name\":\"User\"}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Get a user's profile // GET /user/profile public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.GET); request.setEndpoint("user/profile"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Cancel or pause a scheduled send // POST /user/scheduled_sends public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("user/scheduled_sends"); request.setBody("{\"batch_id\":\"YOUR_BATCH_ID\",\"status\":\"pause\"}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Retrieve all scheduled sends // GET /user/scheduled_sends public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.GET); request.setEndpoint("user/scheduled_sends"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Update user scheduled send information // PATCH /user/scheduled_sends/{batch_id} public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.PATCH); request.setEndpoint("user/scheduled_sends/{batch_id}"); request.setBody("{\"status\":\"pause\"}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Retrieve scheduled send // GET /user/scheduled_sends/{batch_id} public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.GET); request.setEndpoint("user/scheduled_sends/{batch_id}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Delete a cancellation or pause of a scheduled send // DELETE /user/scheduled_sends/{batch_id} public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.DELETE); request.setEndpoint("user/scheduled_sends/{batch_id}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Update Enforced TLS settings // PATCH /user/settings/enforced_tls public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.PATCH); request.setEndpoint("user/settings/enforced_tls"); request.setBody("{\"require_tls\":true,\"require_valid_cert\":false}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Retrieve current Enforced TLS settings. // GET /user/settings/enforced_tls public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.GET); request.setEndpoint("user/settings/enforced_tls"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Update your username // PUT /user/username public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.PUT); request.setBody("user/username"); request.setBody("{\"username\":\"test_username\"}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Retrieve your username // GET /user/username public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.GET); request.setEndpoint("user/username"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Update Event Notification Settings // PATCH /user/webhooks/event/settings public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.PATCH); request.setEndpoint("user/webhooks/event/settings"); request.setBody("{\"group_resubscribe\":true,\"delivered\":true,\"group_unsubscribe\":true,\"spam_report\":true,\"url\":\"url\",\"enabled\":true,\"bounce\":true,\"deferred\":true,\"unsubscribe\":true,\"dropped\":true,\"open\":true,\"click\":true,\"processed\":true}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Retrieve Event Webhook settings // GET /user/webhooks/event/settings public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.GET); request.setEndpoint("user/webhooks/event/settings"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Test Event Notification Settings // POST /user/webhooks/event/test public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("user/webhooks/event/test"); request.setBody("{\"url\":\"url\"}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Create a parse setting // POST /user/webhooks/parse/settings public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("user/webhooks/parse/settings"); request.setBody("{\"url\":\"http://email.myhosthame.com\",\"send_raw\":false,\"hostname\":\"myhostname.com\",\"spam_check\":true}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Retrieve all parse settings // GET /user/webhooks/parse/settings public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.GET); request.setEndpoint("user/webhooks/parse/settings"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Update a parse setting // PATCH /user/webhooks/parse/settings/{hostname} public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.PATCH); request.setEndpoint("user/webhooks/parse/settings/{hostname}"); request.setBody("{\"url\":\"http://newdomain.com/parse\",\"send_raw\":true,\"spam_check\":false}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Retrieve a specific parse setting // GET /user/webhooks/parse/settings/{hostname} public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.GET); request.setEndpoint("user/webhooks/parse/settings/{hostname}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Delete a parse setting // DELETE /user/webhooks/parse/settings/{hostname} public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.DELETE); request.setEndpoint("user/webhooks/parse/settings/{hostname}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } } ////////////////////////////////////////////////////////////////// // Retrieves Inbound Parse Webhook statistics. // GET /user/webhooks/parse/stats public class Example { public static void main(String[] args) throws IOException { try { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.GET); request.setEndpoint("user/webhooks/parse/stats"); request.addQueryParam("aggregated_by", "day"); request.addQueryParam("limit", "test_string"); request.addQueryParam("start_date", "2016-01-01"); request.addQueryParam("end_date", "2016-04-01"); request.addQueryParam("offset", "test_string"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } catch (IOException ex) { throw ex; } } }