See More

import com.sendgrid.Method; import com.sendgrid.Request; import com.sendgrid.Response; import com.sendgrid.SendGrid; import java.io.IOException; ////////////////////////////////////////////////////////////////// // Create a new suppression group // POST /asm/groups 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("asm/groups"); request.setBody("{\"is_default\":true,\"description\":\"Suggestions for products our users might like.\",\"name\":\"Product Suggestions\"}"); 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 information about multiple suppression groups // GET /asm/groups 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("asm/groups"); request.addQueryParam("id", "1"); 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 suppression group. // PATCH /asm/groups/{group_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("asm/groups/{group_id}"); request.setBody("{\"description\":\"Suggestions for items our users might like.\",\"name\":\"Item Suggestions\",\"id\":103}"); 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 information on a single suppression group. // GET /asm/groups/{group_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("asm/groups/{group_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 suppression group. // DELETE /asm/groups/{group_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("asm/groups/{group_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; } } } ////////////////////////////////////////////////////////////////// // Add suppressions to a suppression group // POST /asm/groups/{group_id}/suppressions 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("asm/groups/{group_id}/suppressions"); request.setBody("{\"recipient_emails\":[\"[email protected]\",\"[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 all suppressions for a suppression group // GET /asm/groups/{group_id}/suppressions 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("asm/groups/{group_id}/suppressions"); 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; } } } ////////////////////////////////////////////////////////////////// // Search for suppressions within a group // POST /asm/groups/{group_id}/suppressions/search 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("asm/groups/{group_id}/suppressions/search"); request.setBody("{\"recipient_emails\":[\"[email protected]\",\"[email protected]\",\"[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; } } } ////////////////////////////////////////////////////////////////// // Delete a suppression from a suppression group // DELETE /asm/groups/{group_id}/suppressions/{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.DELETE); request.setEndpoint("asm/groups/{group_id}/suppressions/{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; } } } ////////////////////////////////////////////////////////////////// // Retrieve all suppressions // GET /asm/suppressions 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("asm/suppressions"); 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; } } } ////////////////////////////////////////////////////////////////// // Add recipient addresses to the global suppression group. // POST /asm/suppressions/global 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("asm/suppressions/global"); request.setBody("{\"recipient_emails\":[\"[email protected]\",\"[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 a Global Suppression // GET /asm/suppressions/global/{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("asm/suppressions/global/{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; } } } ////////////////////////////////////////////////////////////////// // Delete a Global Suppression // DELETE /asm/suppressions/global/{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.DELETE); request.setEndpoint("asm/suppressions/global/{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; } } } ////////////////////////////////////////////////////////////////// // Retrieve all suppression groups for an email address // GET /asm/suppressions/{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("asm/suppressions/{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; } } }