Check out our) spring line!
\",\"list_ids\":[110,124],\"sender_id\":124451,\"subject\":\"New Products for Spring!\",\"plain_content\":\"Check out our spring line!\",\"suppression_group_id\":42,\"title\":\"March Newsletter\",\"segment_ids\":[110],\"categories\":[\"spring line\"],\"ip_pool\":\"marketing\"}"; + 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 Campaigns + +**This endpoint allows you to retrieve a list of all of your campaigns.** + +Returns campaigns in reverse order they were created (newest first). + +Returns an empty array if no campaigns exist. + +For more information: + +* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) + +### GET /campaigns + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("campaigns"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "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 Campaign + +Update a campaign. This is especially useful if you only set up the campaign using POST /campaigns, but didn't set many of the parameters. + +For more information: + +* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) + +### PATCH /campaigns/{campaign_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("campaigns/{campaign_id}"); + request.setBody("{\"html_content\":\"Check out our summer line!
\",\"subject\":\"New Products for Summer!\",\"title\":\"May Newsletter\",\"categories\":[\"summer line\"],\"plain_content\":\"Check out our summer line!\"}"; + 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 single campaign + +**This endpoint allows you to retrieve a specific campaign.** + +Our Marketing Campaigns API lets you create, manage, send, and schedule campaigns. + +For more information: + +* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) + +### GET /campaigns/{campaign_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("campaigns/{campaign_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 Campaign + +**This endpoint allows you to delete a specific campaign.** + +Our Marketing Campaigns API lets you create, manage, send, and schedule campaigns. + +For more information: + +* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) + +### DELETE /campaigns/{campaign_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("campaigns/{campaign_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 a Scheduled Campaign + +**This endpoint allows to you change the scheduled time and date for a campaign to be sent.** + +For more information: + +* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) + +### PATCH /campaigns/{campaign_id}/schedules + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("campaigns/{campaign_id}/schedules"); + request.setBody("{\"send_at\":1489451436}"); + 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; + } + ``` +## Schedule a Campaign + +**This endpoint allows you to schedule a specific date and time for your campaign to be sent.** + +For more information: + +* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) + +### POST /campaigns/{campaign_id}/schedules + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("campaigns/{campaign_id}/schedules"); + request.setBody("{\"send_at\":1489771528}"); + 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; + } + ``` +## View Scheduled Time of a Campaign + +**This endpoint allows you to retrieve the date and time that the given campaign has been scheduled to be sent.** + +For more information: + +* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) + +### GET /campaigns/{campaign_id}/schedules + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("campaigns/{campaign_id}/schedules"); + 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; + } + ``` +## Unschedule a Scheduled Campaign + +**This endpoint allows you to unschedule a campaign that has already been scheduled to be sent.** + +A successful unschedule will return a 204. +If the specified campaign is in the process of being sent, the only option is to cancel (a different method). + +For more information: + +* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) + +### DELETE /campaigns/{campaign_id}/schedules + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("campaigns/{campaign_id}/schedules"); + 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; + } + ``` +## Send a Campaign + +**This endpoint allows you to immediately send a campaign at the time you make the API call.** + +Normally a POST would have a request body, but since this endpoint is telling us to send a resource that is already created, a request body is not needed. + +For more information: + +* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) + +### POST /campaigns/{campaign_id}/schedules/now + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("campaigns/{campaign_id}/schedules/now"); + 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; + } + ``` +## Send a Test Campaign + +**This endpoint allows you to send a test campaign.** + +To send to multiple addresses, use an array for the JSON "to" value ["one@address","two@address"] + +For more information: + +* [User Guide > Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) + +### POST /campaigns/{campaign_id}/schedules/test + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("campaigns/{campaign_id}/schedules/test"); + request.setBody("{\"to\":\"your.email@example.com\"}"); + 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; + } + ``` + +# CATEGORIES + +## Retrieve all categories + +**This endpoint allows you to retrieve a list of all of your categories.** + +Categories can help organize your email analytics by enabling you to tag emails by type or broad topic. You can define your own custom categories. For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/categories.html). + +### GET /categories + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("categories"); + request.addQueryParam("category", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "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; + } + ``` +## Retrieve Email Statistics for Categories + +**This endpoint allows you to retrieve all of your email statistics for each of your categories.** + +If you do not define any query parameters, this endpoint will return a sum for each category in groups of 10. + +Categories allow you to group your emails together according to broad topics that you define. For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/categories.html). + +### GET /categories/stats + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("categories/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("categories", "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; + } + ``` +## Retrieve sums of email stats for each category [Needs: Stats object defined, has category ID?] + +**This endpoint allows you to retrieve the total sum of each email statistic for every category over the given date range.** + +If you do not define any query parameters, this endpoint will return a sum for each category in groups of 10. + +Categories allow you to group your emails together according to broad topics that you define. For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/categories.html). + +### GET /categories/stats/sums + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("categories/stats/sums"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("sort_by_direction", "asc"); + 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; + } + ``` + +# CLIENTS + +## Retrieve email statistics by client type. + +**This endpoint allows you to retrieve your email statistics segmented by client type.** + +**We only store up to 7 days of email activity in our database.** By default, 500 items will be returned per request via the Advanced Stats API endpoints. + +Advanced Stats provide a more in-depth view of your email statistics and the actions taken by your recipients. You can segment these statistics by geographic location, device type, client type, browser, and mailbox provider. For more information about statistics, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/index.html). + +### GET /clients/stats + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("clients/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + 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 stats by a specific client type. + +**This endpoint allows you to retrieve your email statistics segmented by a specific client type.** + +**We only store up to 7 days of email activity in our database.** By default, 500 items will be returned per request via the Advanced Stats API endpoints. + +## Available Client Types +- phone +- tablet +- webmail +- desktop + +Advanced Stats provide a more in-depth view of your email statistics and the actions taken by your recipients. You can segment these statistics by geographic location, device type, client type, browser, and mailbox provider. For more information about statistics, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/index.html). + +### GET /clients/{client_type}/stats + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("clients/{client_type}/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + 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; + } + ``` + +# CONTACTDB + +## Create a Custom Field + +**This endpoint allows you to create a custom field.** + +The contactdb is a database of your contacts for [Twilio SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html). + +### POST /contactdb/custom_fields + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("contactdb/custom_fields"); + request.setBody("{\"type\":\"text\",\"name\":\"pet\"}"); + 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 custom fields + +**This endpoint allows you to retrieve all custom fields.** + +The contactdb is a database of your contacts for [Twilio SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html). + +### GET /contactdb/custom_fields + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/custom_fields"); + 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 Custom Field + +**This endpoint allows you to retrieve a custom field by ID.** + +The contactdb is a database of your contacts for [Twilio SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html). + +### GET /contactdb/custom_fields/{custom_field_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/custom_fields/{custom_field_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 Custom Field + +**This endpoint allows you to delete a custom field by ID.** + +The contactdb is a database of your contacts for [Twilio SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html). + +### DELETE /contactdb/custom_fields/{custom_field_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/custom_fields/{custom_field_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; + } + ``` +## Create a List + +**This endpoint allows you to create a list for your recipients.** + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +### POST /contactdb/lists + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("contactdb/lists"); + request.setBody("{\"name\":\"your list name\"}"); + 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 lists + +**This endpoint allows you to retrieve all of your recipient lists. If you don't have any lists, an empty array will be returned.** + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +### GET /contactdb/lists + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/lists"); + 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 Multiple lists + +**This endpoint allows you to delete multiple recipient lists.** + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +### DELETE /contactdb/lists + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/lists"); + request.setBody("[1,2,3,4]"); + 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 List + +**This endpoint allows you to update the name of one of your recipient lists.** + + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +### PATCH /contactdb/lists/{list_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("contactdb/lists/{list_id}"); + request.setBody("{\"name\":\"newlistname\"}"); + 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 single list + +This endpoint allows you to retrieve a single recipient list. + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +### GET /contactdb/lists/{list_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/lists/{list_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 List + +**This endpoint allows you to delete a specific recipient list with the given ID.** + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +### DELETE /contactdb/lists/{list_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/lists/{list_id}"); + request.addQueryParam("delete_contacts", "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; + } + ``` +## Add Multiple Recipients to a List + +**This endpoint allows you to add multiple recipients to a list.** + +Adds existing recipients to a list, passing in the recipient IDs to add. Recipient IDs should be passed exactly as they are returned from recipient endpoints. + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +### POST /contactdb/lists/{list_id}/recipients + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("contactdb/lists/{list_id}/recipients"); + request.setBody("[\"recipient_id1\",\"recipient_id2\"]"); + 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 recipients on a List + +**This endpoint allows you to retrieve all recipients on the list with the given ID.** + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +### GET /contactdb/lists/{list_id}/recipients + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/lists/{list_id}/recipients"); + request.addQueryParam("page", "1"); + request.addQueryParam("page_size", "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; + } + ``` +## Add a Single Recipient to a List + +**This endpoint allows you to add a single recipient to a list.** + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +### POST /contactdb/lists/{list_id}/recipients/{recipient_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("contactdb/lists/{list_id}/recipients/{recipient_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 Single Recipient from a Single List + +**This endpoint allows you to delete a single recipient from a list.** + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +### DELETE /contactdb/lists/{list_id}/recipients/{recipient_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/lists/{list_id}/recipients/{recipient_id}"); + request.addQueryParam("recipient_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 Recipient + +**This endpoint allows you to update one or more recipients.** + +The body of an API call to this endpoint must include an array of one or more recipient objects. + +It is of note that you can add custom field data as parameters on recipient objects. We have provided an example using some of the default custom fields Twilio SendGrid provides. + +The contactdb is a database of your contacts for [Twilio SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html). + +### PATCH /contactdb/recipients + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("contactdb/recipients"); + request.setBody("[{\"first_name\":\"Guy\",\"last_name\":\"Jones\",\"email\":\"jones@example.com\"}]"); + 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 recipients + +**This endpoint allows you to add a Marketing Campaigns recipient.** + +It is of note that you can add custom field data as a parameter on this endpoint. We have provided an example using some of the default custom fields Twilio SendGrid provides. + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +### POST /contactdb/recipients + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("contactdb/recipients"); + request.setBody("[{\"age\":25,\"last_name\":\"User\",\"email\":\"example@example.com\",\"first_name\":\"\"},{\"age\":25,\"last)_name\":\"User\",\"email\":\"example2@example.com\",\"first_name\":\"Example\"}]"; + 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 recipients + +**This endpoint allows you to retrieve all of your Marketing Campaigns recipients.** + +Batch deletion of a page makes it possible to receive an empty page of recipients before reaching the end of +the list of recipients. To avoid this issue; iterate over pages until a 404 is retrieved. + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +### GET /contactdb/recipients + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients"); + request.addQueryParam("page", "1"); + request.addQueryParam("page_size", "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; + } + ``` +## Delete Recipient + +**This endpoint allows you to deletes one or more recipients.** + +The body of an API call to this endpoint must include an array of recipient IDs of the recipients you want to delete. + +The contactdb is a database of your contacts for [Twilio SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html). + +### DELETE /contactdb/recipients + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/recipients"); + request.setBody("[\"recipient_id1\",\"recipient_id2\"]"); + 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 the count of billable recipients + +**This endpoint allows you to retrieve the number of Marketing Campaigns recipients that you will be billed for.** + +You are billed for marketing campaigns based on the highest number of recipients you have had in your account at one time. This endpoint will allow you to know the current billable count value. + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +### GET /contactdb/recipients/billable_count + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/billable_count"); + 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 Count of Recipients + +**This endpoint allows you to retrieve the total number of Marketing Campaigns recipients.** + +The contactdb is a database of your contacts for [Twilio SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html). + +### GET /contactdb/recipients/count + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/count"); + 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 recipients matching search criteria + +**This endpoint allows you to perform a search on all of your Marketing Campaigns recipients.** + +field_name: + +* is a variable that is substituted for your actual custom field name from your recipient. +* Text fields must be url-encoded. Date fields are searchable only by unix timestamp (e.g. 2/2/2015 becomes 1422835200) +* If field_name is a 'reserved' date field, such as created_at or updated_at, the system will internally convert +your epoch time to a date range encompassing the entire day. For example, an epoch time of 1422835600 converts to +Mon, 02 Feb 2015 00:06:40 GMT, but internally the system will search from Mon, 02 Feb 2015 00:00:00 GMT through +Mon, 02 Feb 2015 23:59:59 GMT. + +The contactdb is a database of your contacts for [Twilio SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html). + +### GET /contactdb/recipients/search + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/search"); + request.addQueryParam("{field_name}", "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; + } + ``` +## Retrieve a single recipient + +**This endpoint allows you to retrieve a single recipient by ID from your contact database.** + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +### GET /contactdb/recipients/{recipient_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/{recipient_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 Recipient + +**This endpoint allows you to delete a single recipient with the given ID from your contact database.** + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +### DELETE /contactdb/recipients/{recipient_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/recipients/{recipient_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; + } + ``` +## Retrieve the lists that a recipient is on + +**This endpoint allows you to retrieve the lists that a given recipient belongs to.** + +Each recipient can be on many lists. This endpoint gives you all of the lists that any one recipient has been added to. + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +### GET /contactdb/recipients/{recipient_id}/lists + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/{recipient_id}/lists"); + 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 reserved fields + +**This endpoint allows you to list all fields that are reserved and can't be used for custom field names.** + +The contactdb is a database of your contacts for [Twilio SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html). + +### GET /contactdb/reserved_fields + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/reserved_fields"); + 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 Segment + +**This endpoint allows you to create a segment.** + +All recipients in your contactdb will be added or removed automatically depending on whether they match the criteria for this segment. + +List Id: + +* Send this to segment from an existing list +* Don't send this in order to segment from your entire contactdb. + +Valid operators for create and update depend on the type of the field you are segmenting: + +* **Dates:** "eq", "ne", "lt" (before), "gt" (after) +* **Text:** "contains", "eq" (is - matches the full field), "ne" (is not - matches any field where the entire field is not the condition value) +* **Numbers:** "eq", "lt", "gt" +* **Email Clicks and Opens:** "eq" (opened), "ne" (not opened) + +Segment conditions using "eq" or "ne" for email clicks and opens should provide a "field" of either *clicks.campaign_identifier* or *opens.campaign_identifier*. The condition value should be a string containing the id of a completed campaign. + +Segments may contain multiple conditions, joined by an "and" or "or" in the "and_or" field. The first condition in the conditions list must have an empty "and_or", and subsequent conditions must all specify an "and_or". + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +For more information about segments in Marketing Campaigns, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/lists.html#-Create-a-Segment). + +### POST /contactdb/segments + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("contactdb/segments"); + request.setBody("{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and)_or\":\"\",\"value\":\"Miller\"},{\"operator\":\"gt\",\"field\":\"last_clicked\",\"and_or\":\"and\",\"value\":\"01/02/2015\"},{\"operator\":\"eq\",\"field\":\"clicks.campaign_identifier\",\"and_or\":\"or\",\"value\":\"513\"}],\"name\":\"Last Name Miller\",\"list_id\":4}"; + 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 segments + +**This endpoint allows you to retrieve all of your segments.** + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +For more information about segments in Marketing Campaigns, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/lists.html#-Create-a-Segment). + +### GET /contactdb/segments + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/segments"); + 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 segment + +**This endpoint allows you to update a segment.** + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +For more information about segments in Marketing Campaigns, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/lists.html#-Create-a-Segment). + +### PATCH /contactdb/segments/{segment_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("contactdb/segments/{segment_id}"); + request.setBody("{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and)_or\":\"\",\"value\":\"Miller\"}],\"name\":\"The Millers\",\"list_id\":5}"; + request.addQueryParam("segment_id", "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; + } + ``` +## Retrieve a segment + +**This endpoint allows you to retrieve a single segment with the given ID.** + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +For more information about segments in Marketing Campaigns, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/lists.html#-Create-a-Segment). + +### GET /contactdb/segments/{segment_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/segments/{segment_id}"); + request.addQueryParam("segment_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; + } + ``` +## Delete a segment + +**This endpoint allows you to delete a segment from your recipients database.** + +You also have the option to delete all the contacts from your Marketing Campaigns recipient database who were in this segment. + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +For more information about segments in Marketing Campaigns, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/lists.html#-Create-a-Segment). + +### DELETE /contactdb/segments/{segment_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/segments/{segment_id}"); + request.addQueryParam("delete_contacts", "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 recipients on a segment + +**This endpoint allows you to retrieve all of the recipients in a segment with the given ID.** + +The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. + +For more information about segments in Marketing Campaigns, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/lists.html#-Create-a-Segment). + +### GET /contactdb/segments/{segment_id}/recipients + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/segments/{segment_id}/recipients"); + request.addQueryParam("page", "1"); + request.addQueryParam("page_size", "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; + } + ``` + +# DEVICES + +## Retrieve email statistics by device type. + +**This endpoint allows you to retrieve your email statistics segmented by the device type.** + +**We only store up to 7 days of email activity in our database.** By default, 500 items will be returned per request via the Advanced Stats API endpoints. + +## Available Device Types +| **Device** | **Description** | **Example** | +|---|---|---| +| Desktop | Email software on desktop computer. | I.E., Outlook, Sparrow, or Apple Mail. | +| Webmail | A web-based email client. | I.E., Yahoo, Google, AOL, or Outlook.com. | +| Phone | A smart phone. | iPhone, Android, Blackberry, etc. +| Tablet | A tablet computer. | iPad, android based tablet, etc. | +| Other | An unrecognized device. | + +Advanced Stats provide a more in-depth view of your email statistics and the actions taken by your recipients. You can segment these statistics by geographic location, device type, client type, browser, and mailbox provider. For more information about statistics, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/index.html). + +### GET /devices/stats + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("devices/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("offset", "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; + } + ``` + +# GEO + +## Retrieve email statistics by country and state/province. + +**This endpoint allows you to retrieve your email statistics segmented by country and state/province.** + +**We only store up to 7 days of email activity in our database.** By default, 500 items will be returned per request via the Advanced Stats API endpoints. + +Advanced Stats provide a more in-depth view of your email statistics and the actions taken by your recipients. You can segment these statistics by geographic location, device type, client type, browser, and mailbox provider. For more information about statistics, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/index.html). + +### GET /geo/stats + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("geo/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("country", "US"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + 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; + } + ``` + +# IPS + +## Retrieve all IP addresses + +**This endpoint allows you to retrieve a list of all assigned and unassigned IPs.** + +Response includes warm up status, pools, assigned subusers, and authorization info. The start_date field corresponds to when warmup started for that IP. + +A single IP address or a range of IP addresses may be dedicated to an account in order to send email for multiple domains. The reputation of this IP is based on the aggregate performance of all the senders who use it. + +### GET /ips + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("ips"); + request.addQueryParam("subuser", "test_string"); + request.addQueryParam("ip", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("exclude_whitelabels", "true"); + request.addQueryParam("offset", "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; + } + ``` +## Retrieve all assigned IPs + +**This endpoint allows you to retrieve only assigned IP addresses.** + +A single IP address or a range of IP addresses may be dedicated to an account in order to send email for multiple domains. The reputation of this IP is based on the aggregate performance of all the senders who use it. + +### GET /ips/assigned + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("ips/assigned"); + 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 an IP pool. + +**This endpoint allows you to create an IP pool.** + +**Each user can create up to 10 different IP pools.** + +IP Pools allow you to group your dedicated Twilio SendGrid IP addresses together. For example, you could create separate pools for your transactional and marketing email. When sending marketing emails, specify that you want to use the marketing IP pool. This allows you to maintain separate reputations for your different email traffic. + +IP pools can only be used with authenticated IP addresses. + +If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools. + +### POST /ips/pools + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("ips/pools"); + request.setBody("{\"name\":\"marketing\"}"); + 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 IP pools. + +**This endpoint allows you to retrieve all of your IP pools.** + +IP Pools allow you to group your dedicated Twilio SendGrid IP addresses together. For example, you could create separate pools for your transactional and marketing email. When sending marketing emails, specify that you want to use the marketing IP pool. This allows you to maintain separate reputations for your different email traffic. + +IP pools can only be used with authenticated IP addresses. + +If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools. + +### GET /ips/pools + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("ips/pools"); + 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 an IP pools name. + +**This endpoint allows you to update the name of an IP pool.** + +IP Pools allow you to group your dedicated Twilio SendGrid IP addresses together. For example, you could create separate pools for your transactional and marketing email. When sending marketing emails, specify that you want to use the marketing IP pool. This allows you to maintain separate reputations for your different email traffic. + +IP pools can only be used with authenticated IP addresses. + +If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools. + +### PUT /ips/pools/{pool_name} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PUT); + request.setEndpoint("ips/pools/{pool_name}"); + request.setBody("{\"name\":\"new_pool_name\"}"); + 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 IPs in a specified pool. + +**This endpoint allows you to list all of the IP addresses that are in a specific IP pool.** + +IP Pools allow you to group your dedicated Twilio SendGrid IP addresses together. For example, you could create separate pools for your transactional and marketing email. When sending marketing emails, specify that you want to use the marketing IP pool. This allows you to maintain separate reputations for your different email traffic. + +IP pools can only be used with authenticated IP addresses. + +If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools. + +### GET /ips/pools/{pool_name} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("ips/pools/{pool_name}"); + 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 an IP pool. + +**This endpoint allows you to delete an IP pool.** + +IP Pools allow you to group your dedicated Twilio SendGrid IP addresses together. For example, you could create separate pools for your transactional and marketing email. When sending marketing emails, specify that you want to use the marketing IP pool. This allows you to maintain separate reputations for your different email traffic. + +IP pools can only be used with authenticated IP addresses. + +If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools. + +### DELETE /ips/pools/{pool_name} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("ips/pools/{pool_name}"); + 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 an IP address to a pool + +**This endpoint allows you to add an IP address to an IP pool.** + +You can add the same IP address to multiple pools. It may take up to 60 seconds for your IP address to be added to a pool after your request is made. + +A single IP address or a range of IP addresses may be dedicated to an account in order to send email for multiple domains. The reputation of this IP is based on the aggregate performance of all the senders who use it. + +### POST /ips/pools/{pool_name}/ips + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("ips/pools/{pool_name}/ips"); + request.setBody("{\"ip\":\"0.0.0.0\"}"); + 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; + } + ``` +## Remove an IP address from a pool. + +**This endpoint allows you to remove an IP address from an IP pool.** + +The same IP address can be added to multiple IP pools. + +A single IP address or a range of IP addresses may be dedicated to an account in order to send email for multiple domains. The reputation of this IP is based on the aggregate performance of all the senders who use it. + +### DELETE /ips/pools/{pool_name}/ips/{ip} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("ips/pools/{pool_name}/ips/{ip}"); + 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 an IP to warmup + +**This endpoint allows you to enter an IP address into warmup mode.** + +Twilio SendGrid can automatically warm up dedicated IP addresses by limiting the amount of mail that can be sent through them per hour, with the limit determined by how long the IP address has been in warmup. See the [warmup schedule](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_warmup_schedule.html) for more details on how Twilio SendGrid limits your email traffic for IPs in warmup. + +For more general information about warming up IPs, please see our [Classroom](https://sendgrid.com/docs/Classroom/Deliver/Delivery_Introduction/warming_up_ips.html). + +### POST /ips/warmup + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("ips/warmup"); + request.setBody("{\"ip\":\"0.0.0.0\"}"); + 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 IPs currently in warmup + +**This endpoint allows you to retrieve all of your IP addresses that are currently warming up.** + +Twilio SendGrid can automatically warm up dedicated IP addresses by limiting the amount of mail that can be sent through them per hour, with the limit determined by how long the IP address has been in warmup. See the [warmup schedule](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_warmup_schedule.html) for more details on how Twilio SendGrid limits your email traffic for IPs in warmup. + +For more general information about warming up IPs, please see our [Classroom](https://sendgrid.com/docs/Classroom/Deliver/Delivery_Introduction/warming_up_ips.html). + +### GET /ips/warmup + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("ips/warmup"); + 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 warmup status for a specific IP address + +**This endpoint allows you to retrieve the warmup status for a specific IP address.** + +Twilio SendGrid can automatically warm up dedicated IP addresses by limiting the amount of mail that can be sent through them per hour, with the limit determined by how long the IP address has been in warmup. See the [warmup schedule](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_warmup_schedule.html) for more details on how Twilio SendGrid limits your email traffic for IPs in warmup. + +For more general information about warming up IPs, please see our [Classroom](https://sendgrid.com/docs/Classroom/Deliver/Delivery_Introduction/warming_up_ips.html). + +### GET /ips/warmup/{ip_address} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("ips/warmup/{ip_address}"); + 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; + } + ``` +## Remove an IP from warmup + +**This endpoint allows you to remove an IP address from warmup mode.** + +Twilio SendGrid can automatically warm up dedicated IP addresses by limiting the amount of mail that can be sent through them per hour, with the limit determined by how long the IP address has been in warmup. See the [warmup schedule](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_warmup_schedule.html) for more details on how Twilio SendGrid limits your email traffic for IPs in warmup. + +For more general information about warming up IPs, please see our [Classroom](https://sendgrid.com/docs/Classroom/Deliver/Delivery_Introduction/warming_up_ips.html). + +### DELETE /ips/warmup/{ip_address} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("ips/warmup/{ip_address}"); + 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 IP pools an IP address belongs to + +**This endpoint allows you to see which IP pools a particular IP address has been added to.** + +The same IP address can be added to multiple IP pools. + +A single IP address or a range of IP addresses may be dedicated to an account in order to send email for multiple domains. The reputation of this IP is based on the aggregate performance of all the senders who use it. + +### GET /ips/{ip_address} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("ips/{ip_address}"); + 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; + } + ``` + +# MAIL + +## Create a batch ID + +**This endpoint allows you to generate a new batch ID. This batch ID can be associated with scheduled sends via the mail/send endpoint.** + +If you set the SMTPAPI header `batch_id`, it allows you to then associate multiple scheduled mail/send requests together with the same ID. Then at anytime up to 10 minutes before the schedule date, you can cancel all of the mail/send requests that have this batch ID by calling the Cancel Scheduled Send endpoint. + +More Information: + +* [Scheduling Parameters > Batch ID](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html) + +### POST /mail/batch + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("mail/batch"); + 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; + } + ``` +## Validate batch ID + +**This endpoint allows you to validate a batch ID.** + +If you set the SMTPAPI header `batch_id`, it allows you to then associate multiple scheduled mail/send requests together with the same ID. Then at anytime up to 10 minutes before the schedule date, you can cancel all of the mail/send requests that have this batch ID by calling the Cancel Scheduled Send endpoint. + +More Information: + +* [Scheduling Parameters > Batch ID](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html) + +### GET /mail/batch/{batch_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail/batch/{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; + } + ``` +## v3 Mail Send + +This endpoint allows you to send email over Twilio SendGrid's v3 Web API, the most recent version of our API. If you are looking for documentation about the v2 Mail Send endpoint, please see our [v2 API Reference](https://sendgrid.com/docs/API_Reference/Web_API/mail.html). + +* Top level parameters are referred to as "global". +* Individual fields within the personalizations array will override any other global, or message level, parameters that are defined outside of personalizations. + +For an overview of the v3 Mail Send endpoint, please visit our [v3 API Reference](https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html) + +For more detailed information about how to use the v3 Mail Send endpoint, please visit our [Classroom](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/index.html). + +### POST /mail/send + +This endpoint has a helper, check it out [here](https://github.com/sendgrid/sendgrid-java/blob/master/src/main/java/com/sendgrid/helpers/README.md). + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("mail/send"); + request.setBody("{\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\")[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"from\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"attachments\":[{\"name\":\"file1\",\"filename\":\"file1.jpg\",\"content\":\"[BASE64 encoded content block here]\",\"disposition\":\"inline\",\"content_id\":\"ii_139db99fdb5c3704\",\"type\":\"jpg\"}],\"personalizations\":[{\"to\":[{\"email\":\"john.doe@example.com\",\"name\":\"John Doe\"}],\"cc\":[{\"email\":\"jane.doe@example.com\",\"name\":\"Jane Doe\"}],\"bcc\":[{\"email\":\"sam.doe@example.com\",\"name\":\"Sam Doe\"}],\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\"[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"headers\":{\"X-Accept-Language\":\"en\",\"X-Mailer\":\"MyApp\"},\"send_at\":1409348513,\"substitutions\":{\"type\":\"object\",\"id\":\"substitutions\"},\"subject\":\"Hello, World!\"}],\"subject\":\"Hello, World!\",\"ip_pool_name\":\"[YOUR POOL NAME GOES HERE]\",\"content\":[{\"type\":\"text/html\",\"value\":\"Hello, world!
ThanksThe Twilio SendGrid Team
\"},\"spam_check\":{\"threshold\":3,\"post_to_url\":\"http://example.com/compliance\",\"enable\":true},\"bypass_list_management\":{\"enable\":true},\"sandbox_mode\":{\"enable\":false},\"bcc\":{\"enable\":true,\"email\":\"ben.doe@example.com\"}},\"reply_to\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"sections\":{\"section\":{\":sectionName2\":\"section 2 text\",\":sectionName1\":\"section 1 text\"}},\"template_id\":\"[YOUR TEMPLATE ID GOES HERE]\",\"categories\":[\"category1\",\"category2\"],\"send_at\":1409348513}"; + 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; + } + ``` + +# MAIL SETTINGS + +## Retrieve all mail settings + +**This endpoint allows you to retrieve a list of all mail settings.** + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### GET /mail_settings + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "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 address whitelist mail settings + +**This endpoint allows you to update your current email address whitelist settings.** + +The address whitelist setting whitelists a specified email address or domain for which mail should never be suppressed. For example, you own the domain example.com, and one or more of your recipients use email@example.com addresses, by placing example.com in the address whitelist setting, all bounces, blocks, and unsubscribes logged for that domain will be ignored and sent as if under normal sending conditions. + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### PATCH /mail_settings/address_whitelist + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/address_whitelist"); + request.setBody("{\"list\":[\"email1@example.com\",\"example.com\"],\"enabled\":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 address whitelist mail settings + +**This endpoint allows you to retrieve your current email address whitelist settings.** + +The address whitelist setting whitelists a specified email address or domain for which mail should never be suppressed. For example, you own the domain example.com, and one or more of your recipients use email@example.com addresses, by placing example.com in the address whitelist setting, all bounces, blocks, and unsubscribes logged for that domain will be ignored and sent as if under normal sending conditions. + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### GET /mail_settings/address_whitelist + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/address_whitelist"); + 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 BCC mail settings + +**This endpoint allows you to update your current BCC mail settings.** + +When the BCC mail setting is enabled, Twilio SendGrid will automatically send a blind carbon copy (BCC) to an address for every email sent without adding that address to the header. Please note that only one email address may be entered in this field, if you wish to distribute BCCs to multiple addresses you will need to create a distribution group or use forwarding rules. + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### PATCH /mail_settings/bcc + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/bcc"); + request.setBody("{\"enabled\":false,\"email\":\"email@example.com\"}"); + 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 BCC mail settings + +**This endpoint allows you to retrieve your current BCC mail settings.** + +When the BCC mail setting is enabled, Twilio SendGrid will automatically send a blind carbon copy (BCC) to an address for every email sent without adding that address to the header. Please note that only one email address may be entered in this field, if you wish to distribute BCCs to multiple addresses you will need to create a distribution group or use forwarding rules. + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### GET /mail_settings/bcc + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/bcc"); + 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 bounce purge mail settings + +**This endpoint allows you to update your current bounce purge settings.** + +This setting allows you to set a schedule for Twilio SendGrid to automatically delete contacts from your soft and hard bounce suppression lists. + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### PATCH /mail_settings/bounce_purge + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/bounce_purge"); + request.setBody("{\"hard_bounces\":5,\"soft_bounces\":5,\"enabled\":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 bounce purge mail settings + +**This endpoint allows you to retrieve your current bounce purge settings.** + +This setting allows you to set a schedule for Twilio SendGrid to automatically delete contacts from your soft and hard bounce suppression lists. + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### GET /mail_settings/bounce_purge + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/bounce_purge"); + 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 footer mail settings + +**This endpoint allows you to update your current Footer mail settings.** + +The footer setting will insert a custom footer at the bottom of the text and HTML bodies. Use the embedded HTML editor and plain text entry fields to create the content of the footers to be inserted into your emails. + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### PATCH /mail_settings/footer + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/footer"); + request.setBody("{\"html_content\":\"...\",\"enabled\":true,\"plain_content\":\"...\"}"); + 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 footer mail settings + +**This endpoint allows you to retrieve your current Footer mail settings.** + +The footer setting will insert a custom footer at the bottom of the text and HTML bodies. Use the embedded HTML editor and plain text entry fields to create the content of the footers to be inserted into your emails. + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### GET /mail_settings/footer + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/footer"); + 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 forward bounce mail settings + +**This endpoint allows you to update your current bounce forwarding mail settings.** + +Activating this setting allows you to specify an email address to which bounce reports are forwarded. + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### PATCH /mail_settings/forward_bounce + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/forward_bounce"); + request.setBody("{\"enabled\":true,\"email\":\"example@example.com\"}"); + 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 forward bounce mail settings + +**This endpoint allows you to retrieve your current bounce forwarding mail settings.** + +Activating this setting allows you to specify an email address to which bounce reports are forwarded. + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### GET /mail_settings/forward_bounce + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/forward_bounce"); + 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 forward spam mail settings + +**This endpoint allows you to update your current Forward Spam mail settings.** + +Enabling the forward spam setting allows you to specify an email address to which spam reports will be forwarded. + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### PATCH /mail_settings/forward_spam + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/forward_spam"); + request.setBody("{\"enabled\":false,\"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 forward spam mail settings + +**This endpoint allows you to retrieve your current Forward Spam mail settings.** + +Enabling the forward spam setting allows you to specify an email address to which spam reports will be forwarded. + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### GET /mail_settings/forward_spam + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/forward_spam"); + 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 plain content mail settings + +**This endpoint allows you to update your current Plain Content mail settings.** + +The plain content setting will automatically convert any plain text emails that you send to HTML before sending. + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### PATCH /mail_settings/plain_content + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/plain_content"); + request.setBody("{\"enabled\":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 plain content mail settings + +**This endpoint allows you to retrieve your current Plain Content mail settings.** + +The plain content setting will automatically convert any plain text emails that you send to HTML before sending. + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### GET /mail_settings/plain_content + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/plain_content"); + 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 spam check mail settings + +**This endpoint allows you to update your current spam checker mail settings.** + +The spam checker filter notifies you when emails are detected that exceed a predefined spam threshold. + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### PATCH /mail_settings/spam_check + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/spam_check"); + request.setBody("{\"url\":\"url\",\"max_score\":5,\"enabled\":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 spam check mail settings + +**This endpoint allows you to retrieve your current Spam Checker mail settings.** + +The spam checker filter notifies you when emails are detected that exceed a predefined spam threshold. + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### GET /mail_settings/spam_check + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/spam_check"); + 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 template mail settings + +**This endpoint allows you to update your current legacy email template settings.** + +This setting refers to our original email templates. We currently support more fully featured [transactional templates](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). + +The legacy email template setting wraps an HTML template around your email content. This can be useful for sending out marketing email and/or other HTML formatted messages. + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### PATCH /mail_settings/template + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/template"); + request.setBody("{\"html_content\":\"<% body %>\",\"enabled\":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 legacy template mail settings + +**This endpoint allows you to retrieve your current legacy email template settings.** + +This setting refers to our original email templates. We currently support more fully featured [transactional templates](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). + +The legacy email template setting wraps an HTML template around your email content. This can be useful for sending out marketing email and/or other HTML formatted messages. + +Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html). + +### GET /mail_settings/template + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/template"); + 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; + } + ``` + +# MAILBOX PROVIDERS + +## Retrieve email statistics by mailbox provider. + +**This endpoint allows you to retrieve your email statistics segmented by recipient mailbox provider.** + +**We only store up to 7 days of email activity in our database.** By default, 500 items will be returned per request via the Advanced Stats API endpoints. + +Advanced Stats provide a more in-depth view of your email statistics and the actions taken by your recipients. You can segment these statistics by geographic location, device type, client type, browser, and mailbox provider. For more information about statistics, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/index.html). + +### GET /mailbox_providers/stats + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mailbox_providers/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("mailbox_providers", "test_string"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + 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; + } + ``` + +# PARTNER SETTINGS + +## Returns a list of all partner settings. + +**This endpoint allows you to retrieve a list of all partner settings that you can enable.** + +Our partner settings allow you to integrate your Twilio SendGrid account with our partners to increase your Twilio SendGrid experience and functionality. For more information about our partners, and how you can begin integrating with them, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/partners.html). + +### GET /partner_settings + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("partner_settings"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "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; + } + ``` +## Updates New Relic partner settings. + +**This endpoint allows you to update or change your New Relic partner settings.** + +Our partner settings allow you to integrate your Twilio SendGrid account with our partners to increase your Twilio SendGrid experience and functionality. For more information about our partners, and how you can begin integrating with them, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/partners.html). + +By integrating with New Relic, you can send your Twilio SendGrid email statistics to your New Relic Dashboard. If you enable this setting, your stats will be sent to New Relic every 5 minutes. You will need your New Relic License Key to enable this setting. For more information, please see our [Classroom](https://sendgrid.com/docs/Classroom/Track/Collecting_Data/new_relic.html). + +### PATCH /partner_settings/new_relic + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("partner_settings/new_relic"); + request.setBody("{\"enable_subuser_statistics\":true,\"enabled\":true,\"license_key\":\"\"}"); + 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; + } + ``` +## Returns all New Relic partner settings. + +**This endpoint allows you to retrieve your current New Relic partner settings.** + +Our partner settings allow you to integrate your Twilio SendGrid account with our partners to increase your Twilio SendGrid experience and functionality. For more information about our partners, and how you can begin integrating with them, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/partners.html). + +By integrating with New Relic, you can send your Twilio SendGrid email statistics to your New Relic Dashboard. If you enable this setting, your stats will be sent to New Relic every 5 minutes. You will need your New Relic License Key to enable this setting. For more information, please see our [Classroom](https://sendgrid.com/docs/Classroom/Track/Collecting_Data/new_relic.html). + +### GET /partner_settings/new_relic + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("partner_settings/new_relic"); + 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; + } + ``` + +# SCOPES + +## Retrieve a list of scopes for which this user has access. + +**This endpoint returns a list of all scopes that this user has access to.** + +API Keys can be used to authenticate the use of [Twilio SendGrid's v3 Web API](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html), or the [Mail API Endpoint](https://sendgrid.com/docs/API_Reference/Web_API/mail.html). API Keys may be assigned certain permissions, or scopes, that limit which API endpoints they are able to access. For a more detailed explanation of how you can use API Key permissions, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/api_keys.html#-API-Key-Permissions) or [Classroom](https://sendgrid.com/docs/Classroom/Basics/API/api_key_permissions.html). + +### GET /scopes + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("scopes"); + 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; + } + ``` + +# SENDERS + +## Create a Sender Identity + +**This endpoint allows you to create a new sender identity.** + +*You may create up to 100 unique sender identities.* + +Sender Identities are required to be verified before use. If your domain has been authorized, it will auto verify on creation. Otherwise an email will be sent to the `from.email`. + +### POST /senders + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("senders"); + request.setBody("{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example) INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender 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; + } + ``` +## Get all Sender Identities + +**This endpoint allows you to retrieve a list of all sender identities that have been created for your account.** + +Sender Identities are required to be verified before use. If your domain has been authorized, it will auto verify on creation. Otherwise an email will be sent to the `from.email`. + +### GET /senders + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("senders"); + 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 Sender Identity + +**This endpoint allows you to update a sender identity.** + +Updates to `from.email` require re-verification. If your domain has been authorized, it will auto verify on creation. Otherwise an email will be sent to the `from.email`. + +Partial updates are allowed, but fields that are marked as "required" in the POST (create) endpoint must not be nil if that field is included in the PATCH request. + +### PATCH /senders/{sender_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("senders/{sender_id}"); + request.setBody("{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example) INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender 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; + } + ``` +## View a Sender Identity + +**This endpoint allows you to retrieve a specific sender identity.** + +Sender Identities are required to be verified before use. If your domain has been authorized, it will auto verify on creation. Otherwise an email will be sent to the `from.email`. + +### GET /senders/{sender_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("senders/{sender_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 Sender Identity + +**This endpoint allows you to delete one of your sender identities.** + +Sender Identities are required to be verified before use. If your domain has been authorized, it will auto verify on creation. Otherwise an email will be sent to the `from.email`. + +### DELETE /senders/{sender_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("senders/{sender_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; + } + ``` +## Resend Sender Identity Verification + +**This endpoint allows you to resend a sender identity verification email.** + +Sender Identities are required to be verified before use. If your domain has been authorized, it will auto verify on creation. Otherwise an email will be sent to the `from.email`. + +### POST /senders/{sender_id}/resend_verification + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("senders/{sender_id}/resend_verification"); + 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; + } + ``` + +# SENDER AUTHENTICATION + +## Create an authenticated domain. + +**This endpoint allows you to create a domain authentication for one of your domains.** + +If you are creating a domain authentication that you would like a subuser to use, you have two options: +1. Use the "username" parameter. This allows you to create am authenticated subuser. This means the subuser is able to see and modify the created authentication. +2. Use the Association workflow (see Associate Domain section). This allows you to assign a domain authentication created by the parent to a subuser. This means the subuser will default to the assigned domain authentication, but will not be able to see or modify that authentication. However, if the subuser creates their own domain authentication it will overwrite the assigned domain authentication. + +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. + +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/) + +### POST /whitelabel/domains + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/domains"); + request.setBody("{\"automatic)_security\":false,\"username\":\"john@example.com\",\"domain\":\"example.com\",\"default\":true,\"custom_spf\":true,\"ips\":[\"192.168.1.1\",\"192.168.1.2\"],\"subdomain\":\"news\"}"; + 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; + } + ``` +## List all domain authentications. + +**This endpoint allows you to retrieve a list of all domain authentications you have created.** + +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. + +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/) + +### GET /whitelabel/domains + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/domains"); + request.addQueryParam("username", "test_string"); + request.addQueryParam("domain", "test_string"); + request.addQueryParam("exclude_subusers", "true"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "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; + } + ``` +## Get the default domain authentication. + +**This endpoint allows you to retrieve the default authentication for a domain.** + +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. + +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/) + +## URI Parameters +| URI Parameter | Type | Description | +|---|---|---| +| domain | string |The domain to find a default domain whitelabel for. | + +### GET /whitelabel/domains/default + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/domains/default"); + 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; + } + ``` +## List the domain authentication associated with the given user. + +**This endpoint allows you to retrieve all of the domain authentications that have been assigned to a specific subuser.** + +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. + +Domain authentications can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's authenticated domains. To associate a domain authentication with a subuser, the parent account must first create the domain authentication and validate it. The parent may then associate the domain authentication via the subuser management tools. + +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/) + +## URI Parameters +| URI Parameter | Type | Description | +|---|---|---| +| username | string | Username of the subuser to find associated whitelabels for. | + +### GET /whitelabel/domains/subuser + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/domains/subuser"); + 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; + } + ``` +## Disassociate a domain authentication from a given user. + +**This endpoint allows you to disassociate a specific domain authentication from a subuser.** + +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. + +Domain authentications can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's authenticated domains. To associate a domain authentication with a subuser, the parent account must first create the domain authentication and validate it. The parent may then associate the domain authentication via the subuser management tools. + +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/) + +## URI Parameters +| URI Parameter | Type | Required? | Description | +|---|---|---|---| +| username | string | required | Username for the subuser to find associated whitelabels for. | + +### DELETE /whitelabel/domains/subuser + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/domains/subuser"); + 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 domain authentication. + +**This endpoint allows you to update the settings for a domain authentication.** + +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. + +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/) + +### PATCH /whitelabel/domains/{domain_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("whitelabel/domains/{domain_id}"); + request.setBody("{\"default\":false,\"custom_spf\":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 a domain authentication. + +**This endpoint allows you to retrieve a specific domain authentication.** + +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. + +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/) + + +### GET /whitelabel/domains/{domain_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/domains/{domain_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 domain authentication. + +**This endpoint allows you to delete a domain authentication.** + +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. + +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/) + +### DELETE /whitelabel/domains/{domain_id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/domains/{domain_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; + } + ``` +## Associate a domain authentication with a given user. + +**This endpoint allows you to associate a specific domain authentication with a subuser.** + +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. + +Domain authentications can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's authenticated domains. To associate a domain authentication with a subuser, the parent account must first create the domain authentication and validate it. The parent may then associate the domain authentication via the subuser management tools. + +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/) + +## URI Parameters +| URI Parameter | Type | Description | +|---|---|---| +| domain_id | integer | ID of the domain whitelabel to associate with the subuser. | + +### POST /whitelabel/domains/{domain_id}/subuser + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/domains/{domain_id}/subuser"); + request.setBody("{\"username\":\"jane@example.com\"}"); + 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 an IP to a domain authentication. + +**This endpoint allows you to add an IP address to a domain authentication.** + +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. + +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/) + +## URI Parameters +| URI Parameter | Type | Description | +|---|---|---| +| id | integer | ID of the domain to which you are adding an IP | + +### POST /whitelabel/domains/{id}/ips + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/domains/{id}/ips"); + request.setBody("{\"ip\":\"192.168.0.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; + } + ``` +## Remove an IP from a domain authenticaiton. + +**This endpoint allows you to remove a domain's IP address from that domain's authentication.** + +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. + +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/) + +## URI Parameters +| URI Parameter | Type | Description | +|---|---|---| +| id | integer | ID of the domain whitelabel to delete the IP from. | +| ip | string | IP to remove from the domain whitelabel. | + +### DELETE /whitelabel/domains/{id}/ips/{ip} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/domains/{id}/ips/{ip}"); + 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; + } + ``` +## Validate a domain authentication. + +**This endpoint allows you to validate a domain authentication. If it fails, it will return an error message describing why the domain could not be validated.** + +A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record. + +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/) + +## URI Parameters +| URI Parameter | Type | Description | +|---|---|---| +| id | integer |ID of the domain whitelabel to validate. | + +### POST /whitelabel/domains/{id}/validate + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/domains/{id}/validate"); + 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 reverse DNS + +**This endpoint allows you to create a reverse DNS record.** + +When creating a reverse DNS record, you should use the same subdomain that you used when you created a domain authentication. + +Reverse DNS consists of a subdomain and domain that will be used to generate a record for a given IP. Once Twilio SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated. + +For more information, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-reverse-dns/). + +### POST /whitelabel/ips + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/ips"); + request.setBody("{\"ip\":\"192.168.1.1\",\"domain\":\"example.com\",\"subdomain\":\"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 reverse DNS records + +**This endpoint allows you to retrieve all of the reverse DNS records that have been created by this account.** + +You may include a search key by using the "ip" parameter. This enables you to perform a prefix search for a given IP segment (e.g. "192."). + +Reverse DNS consists of a subdomain and domain that will be used to generate a record for a given IP. Once Twilio SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated. + +For more information, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-reverse-dns/). + +### GET /whitelabel/ips + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/ips"); + request.addQueryParam("ip", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "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; + } + ``` +## Retrieve an reverse DNS record + +**This endpoint allows you to retrieve a reverse DNS record.** + +Reverse DNS consists of a subdomain and domain that will be used to generate a record for a given IP. Once Twilio SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated. + +For more information, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-reverse-dns/). + +### GET /whitelabel/ips/{id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/ips/{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 an reverse DNS record + +**This endpoint allows you to delete a reverse DNS record.** + +Reverse DNS consists of a subdomain and domain that will be used to generate a record for a given IP. Once Twilio SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated. + +For more information, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-reverse-dns/). + +### DELETE /whitelabel/ips/{id} + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/ips/{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; + } + ``` +## Validate a reverse DNS record + +**This endpoint allows you to validate a reverse DNS record.** + +Reverse DNS consists of a subdomain and domain that will be used to generate a record for a given IP. Once Twilio SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated. + +For more information, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-reverse-dns/). + +### POST /whitelabel/ips/{id}/validate + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/ips/{id}/validate"); + 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 Branded Link + +**This endpoint allows you to create a new link branding.** + +Email link branding allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net. + +For more information, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-link-branding/). + +### POST /whitelabel/links + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/links"); + request.setBody("{\"default\":true,\"domain\":\"example.com\",\"subdomain\":\"mail\"}"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "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; + } + ``` +## Retrieve all link brandings + +**This endpoint allows you to retrieve all link brandings.** + +Email link branding allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net. + +For more information, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-link-branding/). + +### GET /whitelabel/links + + +```java + try { + SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/links"); + request.addQueryParam("limit", "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; + } + ``` +## Retrieve a Default Link Branding + +**This endpoint allows you to retrieve the default link branding.** + +Default link branding is the actual link branding to be used when sending messages. If there are multiple link brandings, the default is determined by the following order: +Check out our spring line!
\",\"list_ids\":[110,124],\"sender_id\":124451,\"subject\":\"New Products for Spring!\",\"plain_content\":\"Check out our spring line!\",\"suppression_group_id\":42,\"title\":\"March Newsletter\",\"segment_ids\":[110],\"categories\":[\"spring line\"],\"ip_pool\":\"marketing\"}"); + 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 Campaigns +// GET /campaigns + + +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("campaigns"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "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 Campaign +// PATCH /campaigns/{campaign_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("campaigns/{campaign_id}"); + request.setBody("{\"html_content\":\"Check out our summer line!
\",\"subject\":\"New Products for Summer!\",\"title\":\"May Newsletter\",\"categories\":[\"summer line\"],\"plain_content\":\"Check out our summer line!\"}"); + 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 single campaign +// GET /campaigns/{campaign_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("campaigns/{campaign_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 Campaign +// DELETE /campaigns/{campaign_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("campaigns/{campaign_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 a Scheduled Campaign +// PATCH /campaigns/{campaign_id}/schedules + + +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("campaigns/{campaign_id}/schedules"); + request.setBody("{\"send_at\":1489451436}"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Schedule a Campaign +// POST /campaigns/{campaign_id}/schedules + + +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("campaigns/{campaign_id}/schedules"); + request.setBody("{\"send_at\":1489771528}"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// View Scheduled Time of a Campaign +// GET /campaigns/{campaign_id}/schedules + + +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("campaigns/{campaign_id}/schedules"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Unschedule a Scheduled Campaign +// DELETE /campaigns/{campaign_id}/schedules + + +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("campaigns/{campaign_id}/schedules"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Send a Campaign +// POST /campaigns/{campaign_id}/schedules/now + + +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("campaigns/{campaign_id}/schedules/now"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Send a Test Campaign +// POST /campaigns/{campaign_id}/schedules/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("campaigns/{campaign_id}/schedules/test"); + request.setBody("{\"to\":\"your.email@example.com\"}"); + 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; + } + } +} + diff --git a/examples/categories/categories.java b/examples/categories/categories.java new file mode 100644 index 00000000..7ac73822 --- /dev/null +++ b/examples/categories/categories.java @@ -0,0 +1,91 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve all categories +// GET /categories + + +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("categories"); + request.addQueryParam("category", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Retrieve Email Statistics for Categories +// GET /categories/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("categories/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("categories", "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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Retrieve sums of email stats for each category [Needs: Stats object defined, has category ID?] +// GET /categories/stats/sums + + +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("categories/stats/sums"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("sort_by_direction", "asc"); + 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; + } + } +} + diff --git a/examples/clients/clients.java b/examples/clients/clients.java new file mode 100644 index 00000000..9b755d86 --- /dev/null +++ b/examples/clients/clients.java @@ -0,0 +1,59 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve email statistics by client type. +// GET /clients/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("clients/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + 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 stats by a specific client type. +// GET /clients/{client_type}/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("clients/{client_type}/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + 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; + } + } +} + diff --git a/examples/contactdb/customfields.java b/examples/contactdb/customfields.java new file mode 100644 index 00000000..e4ce5c58 --- /dev/null +++ b/examples/contactdb/customfields.java @@ -0,0 +1,97 @@ +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; + +////////////////////////////////////////////////////////////////// +// Create a Custom Field +// POST /contactdb/custom_fields + + +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("contactdb/custom_fields"); + request.setBody("{\"type\":\"text\",\"name\":\"pet\"}"); + 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 custom fields +// GET /contactdb/custom_fields + + +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("contactdb/custom_fields"); + 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 Custom Field +// GET /contactdb/custom_fields/{custom_field_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("contactdb/custom_fields/{custom_field_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 Custom Field +// DELETE /contactdb/custom_fields/{custom_field_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("contactdb/custom_fields/{custom_field_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; + } + } +} diff --git a/examples/contactdb/listrecipients.java b/examples/contactdb/listrecipients.java new file mode 100644 index 00000000..cfe621e7 --- /dev/null +++ b/examples/contactdb/listrecipients.java @@ -0,0 +1,102 @@ +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; + +////////////////////////////////////////////////////////////////// +// Add Multiple Recipients to a List +// POST /contactdb/lists/{list_id}/recipients + + +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("contactdb/lists/{list_id}/recipients"); + request.setBody("[\"recipient_id1\",\"recipient_id2\"]"); + 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 recipients on a List +// GET /contactdb/lists/{list_id}/recipients + + +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("contactdb/lists/{list_id}/recipients"); + request.addQueryParam("page", "1"); + request.addQueryParam("page_size", "1"); + request.addQueryParam("list_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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Add a Single Recipient to a List +// POST /contactdb/lists/{list_id}/recipients/{recipient_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.POST); + request.setEndpoint("contactdb/lists/{list_id}/recipients/{recipient_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 Single Recipient from a Single List +// DELETE /contactdb/lists/{list_id}/recipients/{recipient_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("contactdb/lists/{list_id}/recipients/{recipient_id}"); + request.addQueryParam("recipient_id", "1"); + request.addQueryParam("list_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; + } + } +} diff --git a/examples/contactdb/lists.java b/examples/contactdb/lists.java new file mode 100644 index 00000000..1e55fd29 --- /dev/null +++ b/examples/contactdb/lists.java @@ -0,0 +1,146 @@ +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; + +////////////////////////////////////////////////////////////////// +// Create a List +// POST /contactdb/lists + + +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("contactdb/lists"); + request.setBody("{\"name\":\"your list name\"}"); + 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 lists +// GET /contactdb/lists + + +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("contactdb/lists"); + 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 Multiple lists +// DELETE /contactdb/lists + + +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("contactdb/lists"); + request.setBody("[1,2,3,4]"); + 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 List +// PATCH /contactdb/lists/{list_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("contactdb/lists/{list_id}"); + request.setBody("{\"name\":\"newlistname\"}"); + request.addQueryParam("list_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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Retrieve a single list +// GET /contactdb/lists/{list_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("contactdb/lists/{list_id}"); + request.addQueryParam("list_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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Delete a List +// DELETE /contactdb/lists/{list_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("contactdb/lists/{list_id}"); + request.addQueryParam("delete_contacts", "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; + } + } +} diff --git a/examples/contactdb/recipients.java b/examples/contactdb/recipients.java new file mode 100644 index 00000000..ebba8d90 --- /dev/null +++ b/examples/contactdb/recipients.java @@ -0,0 +1,234 @@ +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; + +////////////////////////////////////////////////////////////////// +// Update Recipient +// PATCH /contactdb/recipients + + +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("contactdb/recipients"); + request.setBody("[{\"first_name\":\"Guy\",\"last_name\":\"Jones\",\"email\":\"jones@example.com\"}]"); + 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 recipients +// POST /contactdb/recipients + + +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("contactdb/recipients"); + request.setBody("[{\"age\":25,\"last_name\":\"User\",\"email\":\"example@example.com\",\"first_name\":\"\"},{\"age\":25,\"last_name\":\"User\",\"email\":\"example2@example.com\",\"first_name\":\"Example\"}]"); + 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 recipients +// GET /contactdb/recipients + + +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("contactdb/recipients"); + request.addQueryParam("page", "1"); + request.addQueryParam("page_size", "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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Delete Recipient +// DELETE /contactdb/recipients + + +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("contactdb/recipients"); + request.setBody("[\"recipient_id1\",\"recipient_id2\"]"); + 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 the count of billable recipients +// GET /contactdb/recipients/billable_count + + +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("contactdb/recipients/billable_count"); + 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 Count of Recipients +// GET /contactdb/recipients/count + + +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("contactdb/recipients/count"); + 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 recipients matching search criteria +// GET /contactdb/recipients/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.GET); + request.setEndpoint("contactdb/recipients/search"); + request.addQueryParam("{field_name}", "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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Retrieve a single recipient +// GET /contactdb/recipients/{recipient_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("contactdb/recipients/{recipient_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 Recipient +// DELETE /contactdb/recipients/{recipient_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("contactdb/recipients/{recipient_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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Retrieve the lists that a recipient is on +// GET /contactdb/recipients/{recipient_id}/lists + + +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("contactdb/recipients/{recipient_id}/lists"); + 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; + } + } +} diff --git a/examples/contactdb/reservedfields.java b/examples/contactdb/reservedfields.java new file mode 100644 index 00000000..e9ceafa9 --- /dev/null +++ b/examples/contactdb/reservedfields.java @@ -0,0 +1,30 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve reserved fields +// GET /contactdb/reserved_fields + + +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("contactdb/reserved_fields"); + 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; + } + } +} diff --git a/examples/contactdb/segments.java b/examples/contactdb/segments.java new file mode 100644 index 00000000..84c60027 --- /dev/null +++ b/examples/contactdb/segments.java @@ -0,0 +1,147 @@ +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; + +////////////////////////////////////////////////////////////////// +// Create a Segment +// POST /contactdb/segments + + +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("contactdb/segments"); + request.setBody("{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and_or\":\"\",\"value\":\"Miller\"},{\"operator\":\"gt\",\"field\":\"last_clicked\",\"and_or\":\"and\",\"value\":\"01/02/2015\"},{\"operator\":\"eq\",\"field\":\"clicks.campaign_identifier\",\"and_or\":\"or\",\"value\":\"513\"}],\"name\":\"Last Name Miller\",\"list_id\":4}"); + 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 segments +// GET /contactdb/segments + + +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("contactdb/segments"); + 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 segment +// PATCH /contactdb/segments/{segment_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("contactdb/segments/{segment_id}"); + request.setBody("{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and_or\":\"\",\"value\":\"Miller\"}],\"name\":\"The Millers\",\"list_id\":5}"); + request.addQueryParam("segment_id", "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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Retrieve a segment +// GET /contactdb/segments/{segment_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("contactdb/segments/{segment_id}"); + request.addQueryParam("segment_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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Delete a segment +// DELETE /contactdb/segments/{segment_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("contactdb/segments/{segment_id}"); + request.addQueryParam("delete_contacts", "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 recipients on a segment +// GET /contactdb/segments/{segment_id}/recipients + + +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("contactdb/segments/{segment_id}/recipients"); + request.addQueryParam("page", "1"); + request.addQueryParam("page_size", "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; + } + } +} diff --git a/examples/dependencies/jackson-annotations-2.7.0.jar b/examples/dependencies/jackson-annotations-2.7.0.jar new file mode 100644 index 00000000..96fb17cf Binary files /dev/null and b/examples/dependencies/jackson-annotations-2.7.0.jar differ diff --git a/examples/dependencies/jackson-core-2.7.3.jar b/examples/dependencies/jackson-core-2.7.3.jar new file mode 100644 index 00000000..9b20cee6 Binary files /dev/null and b/examples/dependencies/jackson-core-2.7.3.jar differ diff --git a/examples/dependencies/jackson-databind-2.7.3.jar b/examples/dependencies/jackson-databind-2.7.3.jar new file mode 100644 index 00000000..29d90afe Binary files /dev/null and b/examples/dependencies/jackson-databind-2.7.3.jar differ diff --git a/examples/devices/devices.java b/examples/devices/devices.java new file mode 100644 index 00000000..7c253eac --- /dev/null +++ b/examples/devices/devices.java @@ -0,0 +1,36 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve email statistics by device type. +// GET /devices/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("devices/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("offset", "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; + } + } +} + diff --git a/examples/geo/geo.java b/examples/geo/geo.java new file mode 100644 index 00000000..6b74fda9 --- /dev/null +++ b/examples/geo/geo.java @@ -0,0 +1,37 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve email statistics by country and state/province. +// GET /geo/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("geo/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("country", "US"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + 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; + } + } +} + diff --git a/examples/helpers/eventwebhook/Example.java b/examples/helpers/eventwebhook/Example.java new file mode 100644 index 00000000..786d5902 --- /dev/null +++ b/examples/helpers/eventwebhook/Example.java @@ -0,0 +1,27 @@ +import com.sendgrid.helpers.eventwebhook.EventWebhook; +import java.security.PublicKey; +import java.security.Security; +import java.security.interfaces.ECPublicKey; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bouncycastle.jce.provider.BouncyCastleProvider; + +public class Example { + + public static void main(String[] args) { + Security.addProvider(new BouncyCastleProvider()); + + try { + String publicKey = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEEDr2LjtURuePQzplybdC+u4CwrqDqBaWjcMMsTbhdbcwHBcepxo7yAQGhHPTnlvFYPAZFceEu/1FwCM/QmGUhA=="; + String payload = "{\"category\":\"example_payload\",\"event\":\"test_event\",\"message_id\":\"message_id\"}"; + String signature = "MEUCIQCtIHJeH93Y+qpYeWrySphQgpNGNr/U+UyUlBkU6n7RAwIgJTz2C+8a8xonZGi6BpSzoQsbVRamr2nlxFDWYNH2j/0="; + String timestamp = "1588788367"; + EventWebhook ew = new EventWebhook(); + ECPublicKey ellipticCurvePublicKey = ew.ConvertPublicKeyToECDSA(publicKey); + boolean valid = ew.VerifySignature(ellipticCurvePublicKey, payload, signature, timestamp); + System.out.println("Valid Signature: " + valid); + } catch (Exception exception) { + Logger.getLogger(Example.class.getName()).log(Level.SEVERE, "something went wrong", exception); + } + } +} diff --git a/examples/helpers/mail/Example.java b/examples/helpers/mail/Example.java new file mode 100644 index 00000000..8ff7ed42 --- /dev/null +++ b/examples/helpers/mail/Example.java @@ -0,0 +1,264 @@ +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; +import com.sendgrid.helpers.mail.Mail; +import com.sendgrid.helpers.mail.objects.*; + +import java.io.IOException; + +public class Example { + + // Fully populated Mail object + public static Mail buildKitchenSink() { + Mail mail = new Mail(); + + Email fromEmail = new Email(); + fromEmail.setName("Example User"); + fromEmail.setEmail("test@example.com"); + mail.setFrom(fromEmail); + + mail.setSubject("Hello World from the Twilio SendGrid Java Library"); + + Personalization personalization = new Personalization(); + Email to = new Email(); + to.setName("Example User"); + to.setEmail("test1@example.com"); + personalization.addTo(to); + to.setName("Example User"); + to.setEmail("test2@example.com"); + personalization.addTo(to); + Email cc = new Email(); + cc.setName("Example User"); + cc.setEmail("test3@example.com"); + personalization.addCc(cc); + cc.setName("Example User"); + cc.setEmail("test4@example.com"); + personalization.addCc(cc); + Email bcc = new Email(); + bcc.setName("Example User"); + bcc.setEmail("test5@example.com"); + personalization.addBcc(bcc); + bcc.setName("Example User"); + bcc.setEmail("test6@example.com"); + personalization.addBcc(bcc); + personalization.setSubject("Hello World from the Personalized Twilio SendGrid Java Library"); + personalization.addHeader("X-Test", "test"); + personalization.addHeader("X-Mock", "true"); + personalization.addSubstitution("%name%", "Example User"); + personalization.addSubstitution("%city%", "Riverside"); + personalization.addCustomArg("user_id", "343"); + personalization.addCustomArg("type", "marketing"); + personalization.setSendAt(1443636843); + mail.addPersonalization(personalization); + + Personalization personalization2 = new Personalization(); + Email to2 = new Email(); + to2.setName("Example User"); + to2.setEmail("test1@example.com"); + personalization2.addTo(to2); + to2.setName("Example User"); + to2.setEmail("test2@example.com"); + personalization2.addTo(to2); + Email cc2 = new Email(); + cc2.setName("Example User"); + cc2.setEmail("test3@example.com"); + personalization2.addCc(cc2); + cc2.setName("Example User"); + cc2.setEmail("test4@example.com"); + personalization2.addCc(cc2); + Email bcc2 = new Email(); + bcc2.setName("Example User"); + bcc2.setEmail("test5@example.com"); + personalization2.addBcc(bcc2); + bcc2.setName("Example User"); + bcc2.setEmail("test6@example.com"); + personalization2.addBcc(bcc2); + personalization2.setSubject("Hello World from the Personalized Twilio SendGrid Java Library"); + personalization2.addHeader("X-Test", "test"); + personalization2.addHeader("X-Mock", "true"); + personalization2.addSubstitution("%name%", "Example User"); + personalization2.addSubstitution("%city%", "Denver"); + personalization2.addCustomArg("user_id", "343"); + personalization2.addCustomArg("type", "marketing"); + personalization2.setSendAt(1443636843); + mail.addPersonalization(personalization2); + + Content content = new Content(); + content.setType("text/plain"); + content.setValue("some text here"); + mail.addContent(content); + content.setType("text/html"); + content.setValue("some text here"); + mail.addContent(content); + + Attachments attachments = new Attachments(); + attachments.setContent("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12"); + attachments.setType("application/pdf"); + attachments.setFilename("balance_001.pdf"); + attachments.setDisposition("attachment"); + attachments.setContentId("Balance Sheet"); + mail.addAttachments(attachments); + + Attachments attachments2 = new Attachments(); + attachments2.setContent("BwdW"); + attachments2.setType("image/png"); + attachments2.setFilename("banner.png"); + attachments2.setDisposition("inline"); + attachments2.setContentId("Banner"); + mail.addAttachments(attachments2); + + mail.setTemplateId("13b8f94f-bcae-4ec6-b752-70d6cb59f932"); + + mail.addSection("%section1%", "Substitution Text for Section 1"); + mail.addSection("%section2%", "Substitution Text for Section 2"); + + mail.addHeader("X-Test1", "1"); + mail.addHeader("X-Test2", "2"); + + mail.addCategory("May"); + mail.addCategory("2016"); + + mail.addCustomArg("campaign", "welcome"); + mail.addCustomArg("weekday", "morning"); + + mail.setSendAt(1443636842); + + ASM asm = new ASM(); + asm.setGroupId(99); + asm.setGroupsToDisplay(new int[]{4, 5, 6, 7, 8}); + mail.setASM(asm); + + // This must be a valid [batch ID](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html) to work + // mail.setBatchId("sendgrid_batch_id"); + + mail.setIpPoolId("23"); + + MailSettings mailSettings = new MailSettings(); + BccSettings bccSettings = new BccSettings(); + bccSettings.setEnable(true); + bccSettings.setEmail("test@example.com"); + mailSettings.setBccSettings(bccSettings); + Setting sandBoxMode = new Setting(); + sandBoxMode.setEnable(true); + mailSettings.setSandboxMode(sandBoxMode); + Setting bypassListManagement = new Setting(); + bypassListManagement.setEnable(true); + mailSettings.setBypassListManagement(bypassListManagement); + FooterSetting footerSetting = new FooterSetting(); + footerSetting.setEnable(true); + footerSetting.setText("Footer Text"); + footerSetting.setHtml("Footer Text"); + mailSettings.setFooterSetting(footerSetting); + SpamCheckSetting spamCheckSetting = new SpamCheckSetting(); + spamCheckSetting.setEnable(true); + spamCheckSetting.setSpamThreshold(1); + spamCheckSetting.setPostToUrl("https://spamcatcher.sendgrid.com"); + mailSettings.setSpamCheckSetting(spamCheckSetting); + mail.setMailSettings(mailSettings); + + TrackingSettings trackingSettings = new TrackingSettings(); + ClickTrackingSetting clickTrackingSetting = new ClickTrackingSetting(); + clickTrackingSetting.setEnable(true); + clickTrackingSetting.setEnableText(true); + trackingSettings.setClickTrackingSetting(clickTrackingSetting); + OpenTrackingSetting openTrackingSetting = new OpenTrackingSetting(); + openTrackingSetting.setEnable(true); + openTrackingSetting.setSubstitutionTag("Optional tag to replace with the open image in the body of the message"); + trackingSettings.setOpenTrackingSetting(openTrackingSetting); + SubscriptionTrackingSetting subscriptionTrackingSetting = new SubscriptionTrackingSetting(); + subscriptionTrackingSetting.setEnable(true); + subscriptionTrackingSetting.setText("text to insert into the text/plain portion of the message"); + subscriptionTrackingSetting.setHtml("html to insert into the text/html portion of the message"); + subscriptionTrackingSetting.setSubstitutionTag("Optional tag to replace with the open image in the body of the message"); + trackingSettings.setSubscriptionTrackingSetting(subscriptionTrackingSetting); + GoogleAnalyticsSetting googleAnalyticsSetting = new GoogleAnalyticsSetting(); + googleAnalyticsSetting.setEnable(true); + googleAnalyticsSetting.setCampaignSource("some source"); + googleAnalyticsSetting.setCampaignTerm("some term"); + googleAnalyticsSetting.setCampaignContent("some content"); + googleAnalyticsSetting.setCampaignName("some name"); + googleAnalyticsSetting.setCampaignMedium("some medium"); + trackingSettings.setGoogleAnalyticsSetting(googleAnalyticsSetting); + mail.setTrackingSettings(trackingSettings); + + Email replyTo = new Email(); + replyTo.setName("Example User"); + replyTo.setEmail("test@example.com"); + mail.setReplyTo(replyTo); + + return mail; + } + + // API V3 Dynamic Template implementation + public static Mail buildDynamicTemplate() { + Mail mail = new Mail(); + + Email fromEmail = new Email(); + fromEmail.setName("Example User"); + fromEmail.setEmail("test@example.com"); + mail.setFrom(fromEmail); + + mail.setTemplateId("d-c6dcf1f72bdd4beeb15a9aa6c72fcd2c"); + + Personalization personalization = new Personalization(); + personalization.addDynamicTemplateData("name", "Example User"); + personalization.addDynamicTemplateData("city", "Denver"); + personalization.addTo(new Email("test@example.com")); + mail.addPersonalization(personalization); + + return mail; + } + + // Minimum required to send an email + public static Mail buildHelloEmail() { + Email from = new Email("test@example.com"); + String subject = "Hello World from the Twilio SendGrid Java Library"; + Email to = new Email("test@example.com"); + Content content = new Content("text/plain", "some text here"); + // Note that when you use this constructor an initial personalization object + // is created for you. It can be accessed via + // mail.personalization.get(0) as it is a List object + Mail mail = new Mail(from, subject, to, content); + Email email = new Email("test2@example.com"); + mail.personalization.get(0).addTo(email); + + return mail; + } + + public static void baselineExample() throws IOException { + final Mail helloWorld = buildHelloEmail(); + send(helloWorld); + } + + public static void kitchenSinkExample() throws IOException { + final Mail kitchenSink = buildKitchenSink(); + send(kitchenSink); + } + + public static void dynamicTemplateExample() throws IOException { + final Mail dynamicTemplate = buildDynamicTemplate(); + send(dynamicTemplate); + } + + private static void send(final Mail mail) throws IOException { + final SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + sg.addRequestHeader("X-Mock", "true"); + + final Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("mail/send"); + request.setBody(mail.build()); + + final Response response = sg.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } + + public static void main(String[] args) throws IOException { + baselineExample(); + kitchenSinkExample(); + dynamicTemplateExample(); + } +} diff --git a/examples/helpers/mail/MultipleEmailsMultipleRecipients.java b/examples/helpers/mail/MultipleEmailsMultipleRecipients.java new file mode 100644 index 00000000..35fe03b8 --- /dev/null +++ b/examples/helpers/mail/MultipleEmailsMultipleRecipients.java @@ -0,0 +1,54 @@ +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; +import com.sendgrid.helpers.mail.Mail; +import com.sendgrid.helpers.mail.objects.Content; +import com.sendgrid.helpers.mail.objects.Email; +import com.sendgrid.helpers.mail.objects.Personalization; + +import java.io.IOException; + +public class MultipleEmailsMultipleRecipients { + + public static void main(String[] args) throws IOException { + final Mail mail = new Mail(); + + mail.setFrom(new Email("test@example.com", "Example User")); + mail.setSubject("Sending with Twilio SendGrid is Fun"); + + // Details on how to send an email with dynamic transactional templates: + // https://sendgrid.com/docs/ui/sending-email/how-to-send-an-email-with-dynamic-transactional-templates/ + mail.setTemplateId("d-12345678901234567890123456789012"); + + final Personalization personalization1 = new Personalization(); + personalization1.addTo(new Email("test1@example.com", "Example User1")); + personalization1.addDynamicTemplateData("name", "Example User1"); + personalization1.addDynamicTemplateData("city", "Denver"); + mail.addPersonalization(personalization1); + + final Personalization personalization2 = new Personalization(); + personalization2.addTo(new Email("test2@example.com", "Example User2")); + personalization2.addDynamicTemplateData("name", "Example User2"); + personalization2.addDynamicTemplateData("city", "San Francisco"); + mail.addPersonalization(personalization2); + + mail.addContent(new Content("text/plain", "and easy to do anywhere, even with Java")); + mail.addContent(new Content("text/html", "and easy to do anywhere, even with Java")); + + send(mail); + } + + private static void send(final Mail mail) throws IOException { + final SendGrid client = new SendGrid(System.getenv("SENDGRID_API_KEY")); + final Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("mail/send"); + request.setBody(mail.build()); + + final Response response = client.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } +} diff --git a/examples/helpers/mail/SingleEmailMultipleRecipients.java b/examples/helpers/mail/SingleEmailMultipleRecipients.java new file mode 100644 index 00000000..8829124f --- /dev/null +++ b/examples/helpers/mail/SingleEmailMultipleRecipients.java @@ -0,0 +1,44 @@ +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; +import com.sendgrid.helpers.mail.Mail; +import com.sendgrid.helpers.mail.objects.Content; +import com.sendgrid.helpers.mail.objects.Email; +import com.sendgrid.helpers.mail.objects.Personalization; + +import java.io.IOException; + +public class SingleEmailMultipleRecipients { + + public static void main(String[] args) throws IOException { + final Mail mail = new Mail(); + + mail.setFrom(new Email("test@example.com", "Example User")); + mail.setSubject("Sending with Twilio SendGrid is Fun"); + + final Personalization personalization = new Personalization(); + personalization.addTo(new Email("test1@example.com", "Example User1")); + personalization.addTo(new Email("test2@example.com", "Example User2")); + personalization.addTo(new Email("test3@example.com", "Example User3")); + mail.addPersonalization(personalization); + + mail.addContent(new Content("text/plain", "and easy to do anywhere, even with Java")); + mail.addContent(new Content("text/html", "and easy to do anywhere, even with Java")); + + send(mail); + } + + private static void send(final Mail mail) throws IOException { + final SendGrid client = new SendGrid(System.getenv("SENDGRID_API_KEY")); + final Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("mail/send"); + request.setBody(mail.build()); + + final Response response = client.api(request); + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); + System.out.println(response.getHeaders()); + } +} diff --git a/examples/ips/AddToPool.java b/examples/ips/AddToPool.java new file mode 100644 index 00000000..01e6b16b --- /dev/null +++ b/examples/ips/AddToPool.java @@ -0,0 +1,32 @@ +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; + + +////////////////////////////////////////////////////////////////// +// Add an IP address to a pool +// POST /ips/pools/{pool_name}/ips + + +public class AddIPToPool { + 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("ips/pools/{pool_name}/ips"); + request.setBody("{\"ip\":\"0.0.0.0\"}"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/ips/AddToWarmup.java b/examples/ips/AddToWarmup.java new file mode 100644 index 00000000..89ebaad1 --- /dev/null +++ b/examples/ips/AddToWarmup.java @@ -0,0 +1,33 @@ +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; + + + +////////////////////////////////////////////////////////////////// +// Add an IP to warmup +// POST /ips/warmup + + +public class AddIPToWarmup { + 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("ips/warmup"); + request.setBody("{\"ip\":\"0.0.0.0\"}"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/ips/CreatePool.java b/examples/ips/CreatePool.java new file mode 100644 index 00000000..c91d82f0 --- /dev/null +++ b/examples/ips/CreatePool.java @@ -0,0 +1,32 @@ +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; + + +////////////////////////////////////////////////////////////////// +// Create an IP pool. +// POST /ips/pools + + +public class CreateIPPool { + 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("ips/pools"); + request.setBody("{\"name\":\"marketing\"}"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/ips/DeletePool.java b/examples/ips/DeletePool.java new file mode 100644 index 00000000..51c50249 --- /dev/null +++ b/examples/ips/DeletePool.java @@ -0,0 +1,31 @@ +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; + + +////////////////////////////////////////////////////////////////// +// Delete an IP pool. +// DELETE /ips/pools/{pool_name} + + +public class DeletePool { + 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("ips/pools/{pool_name}"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/ips/README.md b/examples/ips/README.md new file mode 100644 index 00000000..7ded4310 --- /dev/null +++ b/examples/ips/README.md @@ -0,0 +1,18 @@ + + +This folder contains various examples on using the IPs endpoint of SendGrid with Java: + +* [Retrieve all IP addresses (GET /ips)](RetrieveAllIPs.java) +* [Retrieve all assigned IPs (GET /ips/assigned)](RetrieveAssignedIPs.java) +* [Create an IP pool (POST /ips/pools)](CreatePool.java) +* [Retrieve all IP pools (GET /ips/pools)](RetrieveAllPools.java) +* [Update an IP pools name (PUT /ips/pools/{pool_name})](UpdatePoolName.java) +* [Retrieve all IPs in a specified pool (GET /ips/pools/{pool_name})](RetrieveIPsInPool.java) +* [Delete an IP pool. (DELETE /ips/pools/{pool_name})](DeletePool.java) +* [Add an IP address to a pool (POST /ips/pools/{pool_name}/ips)](AddToPool.java) +* [Remove an IP address from a pool (DELETE /ips/pools/{pool_name}/ips/{ip}](RemoveFromPool.java) +* [Add an IP to warmup (POST /ips/warmup)](AddToWarmup.java) +* [Retrieve all IPs currently in warmup (GET /ips/warmup)](RetrieveIPsInWarmup.java) +* [Retrieve warmup status for a specific IP address (GET /ips/warmup/{ip_address})](RetrieveWarmupStatus.java) +* [Remove an IP from warmup (DELETE /ips/warmup/{ip_address})](RemoveFromWarmup.java) +* [Retrieve all IP pools an IP address belongs to (GET /ips/{ip_address})](RetrievePoolsForIP.java) \ No newline at end of file diff --git a/examples/ips/RemoveFromPool.java b/examples/ips/RemoveFromPool.java new file mode 100644 index 00000000..ceb5f2be --- /dev/null +++ b/examples/ips/RemoveFromPool.java @@ -0,0 +1,31 @@ +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + + + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + + +////////////////////////////////////////////////////////////////// +// Remove an IP address from a pool. +// DELETE /ips/pools/{pool_name}/ips/{ip} + + +public class RemoveIPFromPool { + 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("ips/pools/{pool_name}/ips/{ip}"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/ips/RemoveFromWarmup.java b/examples/ips/RemoveFromWarmup.java new file mode 100644 index 00000000..b99229de --- /dev/null +++ b/examples/ips/RemoveFromWarmup.java @@ -0,0 +1,32 @@ +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; + + + +////////////////////////////////////////////////////////////////// +// Remove an IP from warmup +// DELETE /ips/warmup/{ip_address} + + +public class RemoveFromWarmup { + 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("ips/warmup/{ip_address}"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/ips/RetrieveAllIPs.java b/examples/ips/RetrieveAllIPs.java new file mode 100644 index 00000000..14845939 --- /dev/null +++ b/examples/ips/RetrieveAllIPs.java @@ -0,0 +1,34 @@ +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + + +////////////////////////////////////////////////////////////////// +// Retrieve all IP addresses +// GET /ips + + +public class RetrieveAllIPs { + 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("ips"); + request.addQueryParam("subuser", "test_string"); + request.addQueryParam("ip", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("exclude_whitelabels", "true"); + request.addQueryParam("offset", "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; + } + } +} \ No newline at end of file diff --git a/examples/ips/RetrieveAllPools.java b/examples/ips/RetrieveAllPools.java new file mode 100644 index 00000000..93bf78ec --- /dev/null +++ b/examples/ips/RetrieveAllPools.java @@ -0,0 +1,31 @@ +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; + + +////////////////////////////////////////////////////////////////// +// Retrieve all IP pools. +// GET /ips/pools + + +public class RetieveAllIPPools { + 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("ips/pools"); + 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; + } + } +} diff --git a/examples/ips/RetrieveAssignedIPs.java b/examples/ips/RetrieveAssignedIPs.java new file mode 100644 index 00000000..968834cc --- /dev/null +++ b/examples/ips/RetrieveAssignedIPs.java @@ -0,0 +1,31 @@ +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; + + +////////////////////////////////////////////////////////////////// +// Retrieve all assigned IPs +// GET /ips/assigned + + +public class RetrieveAllAssignedIPs { + 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("ips/assigned"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/ips/RetrieveIPsInPool.java b/examples/ips/RetrieveIPsInPool.java new file mode 100644 index 00000000..72330c3f --- /dev/null +++ b/examples/ips/RetrieveIPsInPool.java @@ -0,0 +1,31 @@ +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; + + +////////////////////////////////////////////////////////////////// +// Retrieve all IPs in a specified pool. +// GET /ips/pools/{pool_name} + + +public class RetrieveIPsInPool { + 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("ips/pools/{pool_name}"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/ips/RetrieveIPsInWarmup.java b/examples/ips/RetrieveIPsInWarmup.java new file mode 100644 index 00000000..3767656b --- /dev/null +++ b/examples/ips/RetrieveIPsInWarmup.java @@ -0,0 +1,32 @@ +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; + + + +////////////////////////////////////////////////////////////////// +// Retrieve all IPs currently in warmup +// GET /ips/warmup + + +public class RetrieveIPsInWarmup { + 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("ips/warmup"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/ips/RetrievePoolsForIP.java b/examples/ips/RetrievePoolsForIP.java new file mode 100644 index 00000000..8f19b7a7 --- /dev/null +++ b/examples/ips/RetrievePoolsForIP.java @@ -0,0 +1,33 @@ +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; + + + +////////////////////////////////////////////////////////////////// +// Retrieve all IP pools an IP address belongs to +// GET /ips/{ip_address} + + +public class RetrieveAllPoolsForIP { + 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("ips/{ip_address}"); + 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; + } + } +} + diff --git a/examples/ips/RetrieveWarmupStatus.java b/examples/ips/RetrieveWarmupStatus.java new file mode 100644 index 00000000..5d315b8f --- /dev/null +++ b/examples/ips/RetrieveWarmupStatus.java @@ -0,0 +1,32 @@ +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; + + + +////////////////////////////////////////////////////////////////// +// Retrieve warmup status for a specific IP address +// GET /ips/warmup/{ip_address} + + +public class RetrieveIPsWarmupStatus { + 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("ips/warmup/{ip_address}"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/ips/UpdatePoolName.java b/examples/ips/UpdatePoolName.java new file mode 100644 index 00000000..4e9c2a26 --- /dev/null +++ b/examples/ips/UpdatePoolName.java @@ -0,0 +1,32 @@ +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; + + +////////////////////////////////////////////////////////////////// +// Update an IP pools name. +// PUT /ips/pools/{pool_name} + + +public class UpdateIPPoolName { + 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("ips/pools/{pool_name}"); + request.setBody("{\"name\":\"new_pool_name\"}"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/mail/mail.java b/examples/mail/mail.java new file mode 100644 index 00000000..f35989df --- /dev/null +++ b/examples/mail/mail.java @@ -0,0 +1,77 @@ +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; + +////////////////////////////////////////////////////////////////// +// Create a batch ID +// POST /mail/batch + + +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("mail/batch"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Validate batch ID +// GET /mail/batch/{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("mail/batch/{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; + } + } +} + +////////////////////////////////////////////////////////////////// +// v3 Mail Send +// POST /mail/send + +// This endpoint has a helper, check it out [here](https://github.com/sendgrid/sendgrid-java/blob/master/src/main/java/com/sendgrid/helpers/README.md). + +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("mail/send"); + request.setBody("{\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\"[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"from\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"attachments\":[{\"name\":\"file1\",\"filename\":\"file1.jpg\",\"content\":\"[BASE64 encoded content block here]\",\"disposition\":\"inline\",\"content_id\":\"ii_139db99fdb5c3704\",\"type\":\"jpg\"}],\"personalizations\":[{\"to\":[{\"email\":\"john.doe@example.com\",\"name\":\"John Doe\"}],\"cc\":[{\"email\":\"jane.doe@example.com\",\"name\":\"Jane Doe\"}],\"bcc\":[{\"email\":\"sam.doe@example.com\",\"name\":\"Sam Doe\"}],\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\"[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"headers\":{\"X-Accept-Language\":\"en\",\"X-Mailer\":\"MyApp\"},\"send_at\":1409348513,\"substitutions\":{\"type\":\"object\",\"id\":\"substitutions\"},\"subject\":\"Hello, World!\"}],\"subject\":\"Hello, World!\",\"ip_pool_name\":\"[YOUR POOL NAME GOES HERE]\",\"content\":[{\"type\":\"text/html\",\"value\":\"Hello, world!
ThanksThe Twilio SendGrid Team
\"},\"spam_check\":{\"threshold\":3,\"post_to_url\":\"http://example.com/compliance\",\"enable\":true},\"bypass_list_management\":{\"enable\":true},\"sandbox_mode\":{\"enable\":false},\"bcc\":{\"enable\":true,\"email\":\"ben.doe@example.com\"}},\"reply_to\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"sections\":{\"section\":{\":sectionName2\":\"section 2 text\",\":sectionName1\":\"section 1 text\"}},\"template_id\":\"[YOUR TEMPLATE ID GOES HERE]\",\"categories\":[\"category1\",\"category2\"],\"send_at\":1409348513}"); + 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; + } + } +} + diff --git a/examples/mailboxproviders/mailboxproviders.java b/examples/mailboxproviders/mailboxproviders.java new file mode 100644 index 00000000..4e0c6a06 --- /dev/null +++ b/examples/mailboxproviders/mailboxproviders.java @@ -0,0 +1,37 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve email statistics by mailbox provider. +// GET /mailbox_providers/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("mailbox_providers/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("mailbox_providers", "test_string"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + 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; + } + } +} + diff --git a/examples/mailsettings/GetAddressWhitelistMailSettings.java b/examples/mailsettings/GetAddressWhitelistMailSettings.java new file mode 100644 index 00000000..fdc81c1b --- /dev/null +++ b/examples/mailsettings/GetAddressWhitelistMailSettings.java @@ -0,0 +1,28 @@ +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + +////////////////////////////////////////////////////////////////// +// Retrieve address whitelist mail settings +// GET /mail_settings/address_whitelist + + +public class GetAddressWhitelistMailSettings { + 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("mail_settings/address_whitelist"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/GetAllMailSettings.java b/examples/mailsettings/GetAllMailSettings.java new file mode 100644 index 00000000..e85b6e48 --- /dev/null +++ b/examples/mailsettings/GetAllMailSettings.java @@ -0,0 +1,30 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Retrieve all mail settings +// GET /mail_settings + + +public class GetAllMailSettings { + 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("mail_settings"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "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; + } + } +} diff --git a/examples/mailsettings/GetBCCMailSettings.java b/examples/mailsettings/GetBCCMailSettings.java new file mode 100644 index 00000000..90ab31d9 --- /dev/null +++ b/examples/mailsettings/GetBCCMailSettings.java @@ -0,0 +1,28 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Retrieve all BCC mail settings +// GET /mail_settings/bcc + + +public class GetBCCMailSettings { + 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("mail_settings/bcc"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/GetBouncePurgeMailSettings.java b/examples/mailsettings/GetBouncePurgeMailSettings.java new file mode 100644 index 00000000..2f390764 --- /dev/null +++ b/examples/mailsettings/GetBouncePurgeMailSettings.java @@ -0,0 +1,28 @@ +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + +////////////////////////////////////////////////////////////////// +// Retrieve bounce purge mail settings +// GET /mail_settings/bounce_purge + + +public class GetBouncePurgeMailSettings { + 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("mail_settings/bounce_purge"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/GetFooterMailSettings.java b/examples/mailsettings/GetFooterMailSettings.java new file mode 100644 index 00000000..bea04d0b --- /dev/null +++ b/examples/mailsettings/GetFooterMailSettings.java @@ -0,0 +1,31 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + +////////////////////////////////////////////////////////////////// +// Retrieve footer mail settings +// GET /mail_settings/footer + + +public class GetFooterMailSettings { + 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("mail_settings/footer"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/GetForwardBounceMailSettings.java b/examples/mailsettings/GetForwardBounceMailSettings.java new file mode 100644 index 00000000..33331585 --- /dev/null +++ b/examples/mailsettings/GetForwardBounceMailSettings.java @@ -0,0 +1,31 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + +////////////////////////////////////////////////////////////////// +// Retrieve forward bounce mail settings +// GET /mail_settings/forward_bounce + + +public class GetForwardBounceMailSettings { + 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("mail_settings/forward_bounce"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/GetForwardSpamMailSettings.java b/examples/mailsettings/GetForwardSpamMailSettings.java new file mode 100644 index 00000000..0b890294 --- /dev/null +++ b/examples/mailsettings/GetForwardSpamMailSettings.java @@ -0,0 +1,28 @@ +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +import java.io.IOException; + +////////////////////////////////////////////////////////////////// +// Retrieve forward spam mail settings +// GET /mail_settings/forward_spam + + +public class GetForwardSpamMailSettings { + 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("mail_settings/forward_spam"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/GetPlainContentMailSettings.java b/examples/mailsettings/GetPlainContentMailSettings.java new file mode 100644 index 00000000..38f7cfe4 --- /dev/null +++ b/examples/mailsettings/GetPlainContentMailSettings.java @@ -0,0 +1,28 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Retrieve plain content mail settings +// GET /mail_settings/plain_content + + +public class GetPlainContentMailSettings { + 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("mail_settings/plain_content"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/GetSpamCheckMailSettings.java b/examples/mailsettings/GetSpamCheckMailSettings.java new file mode 100644 index 00000000..9460cac0 --- /dev/null +++ b/examples/mailsettings/GetSpamCheckMailSettings.java @@ -0,0 +1,28 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Retrieve spam check mail settings +// GET /mail_settings/spam_check + + +public class GetSpamCheckMailSettings { + 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("mail_settings/spam_check"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/GetTemplateMailSettings.java b/examples/mailsettings/GetTemplateMailSettings.java new file mode 100644 index 00000000..8b648be4 --- /dev/null +++ b/examples/mailsettings/GetTemplateMailSettings.java @@ -0,0 +1,28 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Retrieve legacy template mail settings +// GET /mail_settings/template + + +public class GetTemplateMailSettings { + 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("mail_settings/template"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/README.md b/examples/mailsettings/README.md new file mode 100644 index 00000000..34e83317 --- /dev/null +++ b/examples/mailsettings/README.md @@ -0,0 +1,23 @@ + + +This folder contains various examples on using the Mail Settings endpoint of SendGrid with Java: + +* [Retrieve all mail settings (GET /mail_settings)](GetAllMailSettings.java) +* [Retrieve address whitelist mail settings (GET /mail_settings/address_whitelist)](GetAddressWhitelistMailSettings.java) +* [Retrieve all BCC mail settings (GET /mail_settings/bcc)](GetBCCMailSettings.java) +* [Retrieve bounce purge mail settings (GET /mail_settings/bounce_purge)](GetBouncePurgeMailSettings.java) +* [Retrieve footer mail settings (GET /mail_settings/footer)](GetFooterMailSettings.java) +* [Retrieve forward bounce mail settings (GET /mail_settings/forward_bounce)](GetForwardBounceMailSettings.java) +* [Retrieve forward spam mail settings (GET /mail_settings/forward_spam)](GetForwardSpamMailSettings.java) +* [Retrieve plain content mail settings (GET /mail_settings/plain_content)](GetPlainContentMailSettings.java) +* [Retrieve spam check mail settings (GET /mail_settings/spam_check)](GetSpamCheckMailSettings.java) +* [Retrieve legacy template mail settings (GET /mail_settings/template)](GetTemplateMailSettings.java) +* [Update address whitelist mail settings (PATCH /mail_settings/address_whitelist)](UpdateAddressWhitelist.java) +* [Update BCC mail settings (PATCH /mail_settings/bcc)](UpdateBCCMailSettings.java) +* [Update bounce purge mail settings (PATCH /mail_settings/bounce_purge)](UpdateBouncePurgeMailSettings.java) +* [Update footer mail settings (PATCH /mail_settings/footer)](UpdateFooterMailSettings.java) +* [Update forward bounce mail settings (PATCH /mail_settings/forward_bounce)](UpdateForwardBounceMailSettings.java) +* [Update forward spam mail settings (PATCH /mail_settings/forward_spam)](UpdateForwardSpamMailSettings.java) +* [Update plain content mail settings (PATCH /mail_settings/plain_content)](UpdatePlainContentMailSettings.java) +* [Update spam check mail settings (PATCH /mail_settings/spam_check)](UpdateSpamCheckMailSettings.java) +* [Update template mail settings (PATCH /mail_settings/template)](UpdateTemplateMailSettings.java) diff --git a/examples/mailsettings/UpdateAddressWhitelist.java b/examples/mailsettings/UpdateAddressWhitelist.java new file mode 100644 index 00000000..db58c282 --- /dev/null +++ b/examples/mailsettings/UpdateAddressWhitelist.java @@ -0,0 +1,29 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Update address whitelist mail settings +// PATCH /mail_settings/address_whitelist + + +public class UpdateAddressWhitelist { + 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("mail_settings/address_whitelist"); + request.setBody("{\"list\":[\"email1@example.com\",\"example.com\"],\"enabled\":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; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/UpdateBCCMailSettings.java b/examples/mailsettings/UpdateBCCMailSettings.java new file mode 100644 index 00000000..33faba1a --- /dev/null +++ b/examples/mailsettings/UpdateBCCMailSettings.java @@ -0,0 +1,29 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Update BCC mail settings +// PATCH /mail_settings/bcc + + +public class UpdateBCCMailSettings { + 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("mail_settings/bcc"); + request.setBody("{\"enabled\":false,\"email\":\"email@example.com\"}"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/UpdateBouncePurgeMailSettings.java b/examples/mailsettings/UpdateBouncePurgeMailSettings.java new file mode 100644 index 00000000..83a53e10 --- /dev/null +++ b/examples/mailsettings/UpdateBouncePurgeMailSettings.java @@ -0,0 +1,29 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Update bounce purge mail settings +// PATCH /mail_settings/bounce_purge + + +public class UpdateBouncePurgeMailSettings { + 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("mail_settings/bounce_purge"); + request.setBody("{\"hard_bounces\":5,\"soft_bounces\":5,\"enabled\":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; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/UpdateFooterMailSettings.java b/examples/mailsettings/UpdateFooterMailSettings.java new file mode 100644 index 00000000..fedf35b0 --- /dev/null +++ b/examples/mailsettings/UpdateFooterMailSettings.java @@ -0,0 +1,29 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Update footer mail settings +// PATCH /mail_settings/footer + + +public class UpdateFooterMailSettings { + 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("mail_settings/footer"); + request.setBody("{\"html_content\":\"...\",\"enabled\":true,\"plain_content\":\"...\"}"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/UpdateForwardBounceMailSettings.java b/examples/mailsettings/UpdateForwardBounceMailSettings.java new file mode 100644 index 00000000..677b94e9 --- /dev/null +++ b/examples/mailsettings/UpdateForwardBounceMailSettings.java @@ -0,0 +1,29 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Update forward bounce mail settings +// PATCH /mail_settings/forward_bounce + + +public class UpdateForwardBounceMailSettings { + 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("mail_settings/forward_bounce"); + request.setBody("{\"enabled\":true,\"email\":\"example@example.com\"}"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/UpdateForwardSpamMailSettings.java b/examples/mailsettings/UpdateForwardSpamMailSettings.java new file mode 100644 index 00000000..3b27f353 --- /dev/null +++ b/examples/mailsettings/UpdateForwardSpamMailSettings.java @@ -0,0 +1,29 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Update forward spam mail settings +// PATCH /mail_settings/forward_spam + + +public class UpdateForwardSpamMailSettings { + 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("mail_settings/forward_spam"); + request.setBody("{\"enabled\":false,\"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; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/UpdatePlainContentMailSettings.java b/examples/mailsettings/UpdatePlainContentMailSettings.java new file mode 100644 index 00000000..4cb680f5 --- /dev/null +++ b/examples/mailsettings/UpdatePlainContentMailSettings.java @@ -0,0 +1,29 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Update plain content mail settings +// PATCH /mail_settings/plain_content + + +public class UpdatePlainContentMailSettings { + 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("mail_settings/plain_content"); + request.setBody("{\"enabled\":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; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/UpdateSpamCheckMailSettings.java b/examples/mailsettings/UpdateSpamCheckMailSettings.java new file mode 100644 index 00000000..e7cf8dc2 --- /dev/null +++ b/examples/mailsettings/UpdateSpamCheckMailSettings.java @@ -0,0 +1,29 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Update spam check mail settings +// PATCH /mail_settings/spam_check + + +public class UpdateSpamCheckMailSettings { + 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("mail_settings/spam_check"); + request.setBody("{\"url\":\"url\",\"max_score\":5,\"enabled\":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; + } + } +} \ No newline at end of file diff --git a/examples/mailsettings/UpdateTemplateMailSettings.java b/examples/mailsettings/UpdateTemplateMailSettings.java new file mode 100644 index 00000000..57e1b22a --- /dev/null +++ b/examples/mailsettings/UpdateTemplateMailSettings.java @@ -0,0 +1,29 @@ +import java.io.IOException; + +import com.sendgrid.Method; +import com.sendgrid.Request; +import com.sendgrid.Response; +import com.sendgrid.SendGrid; + +////////////////////////////////////////////////////////////////// +// Update template mail settings +// PATCH /mail_settings/template + + +public class UpdateTemplateMailSettings { + 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("mail_settings/template"); + request.setBody("{\"html_content\":\"<% body %>\",\"enabled\":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; + } + } +} \ No newline at end of file diff --git a/examples/partnersettings/partnersettings.java b/examples/partnersettings/partnersettings.java new file mode 100644 index 00000000..b4364bb9 --- /dev/null +++ b/examples/partnersettings/partnersettings.java @@ -0,0 +1,78 @@ +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; + +////////////////////////////////////////////////////////////////// +// Returns a list of all partner settings. +// GET /partner_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("partner_settings"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Updates New Relic partner settings. +// PATCH /partner_settings/new_relic + + +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("partner_settings/new_relic"); + request.setBody("{\"enable_subuser_statistics\":true,\"enabled\":true,\"license_key\":\"\"}"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Returns all New Relic partner settings. +// GET /partner_settings/new_relic + + +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("partner_settings/new_relic"); + 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; + } + } +} + diff --git a/examples/scopes/scopes.java b/examples/scopes/scopes.java new file mode 100644 index 00000000..69d2db5d --- /dev/null +++ b/examples/scopes/scopes.java @@ -0,0 +1,31 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve a list of scopes for which this user has access. +// GET /scopes + + +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("scopes"); + 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; + } + } +} + diff --git a/examples/senderauthentication/domains.java b/examples/senderauthentication/domains.java new file mode 100644 index 00000000..2ffe0a7e --- /dev/null +++ b/examples/senderauthentication/domains.java @@ -0,0 +1,281 @@ +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; + +////////////////////////////////////////////////////////////////// +// Create a domain authorization. +// POST /whitelabel/domains + + +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("whitelabel/domains"); + request.setBody("{\"automatic_security\":false,\"username\":\"john@example.com\",\"domain\":\"example.com\",\"default\":true,\"custom_spf\":true,\"ips\":[\"192.168.1.1\",\"192.168.1.2\"],\"subdomain\":\"news\"}"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// List all domain authorization. +// GET /whitelabel/domains + + +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("whitelabel/domains"); + request.addQueryParam("username", "test_string"); + request.addQueryParam("domain", "test_string"); + request.addQueryParam("exclude_subusers", "true"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Get the default domain authorization. +// GET /whitelabel/domains/default + + +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("whitelabel/domains/default"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// List the domain authorization associated with the given user. +// GET /whitelabel/domains/subuser + + +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("whitelabel/domains/subuser"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Disassociate a domain authorization from a given user. +// DELETE /whitelabel/domains/subuser + + +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("whitelabel/domains/subuser"); + 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 domain authorization. +// PATCH /whitelabel/domains/{domain_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("whitelabel/domains/{domain_id}"); + request.setBody("{\"default\":false,\"custom_spf\":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 a domain authorization. +// GET /whitelabel/domains/{domain_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("whitelabel/domains/{domain_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 domain authorization. +// DELETE /whitelabel/domains/{domain_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("whitelabel/domains/{domain_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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Associate a domain authorization with a given user. +// POST /whitelabel/domains/{domain_id}/subuser + + +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("whitelabel/domains/{domain_id}/subuser"); + request.setBody("{\"username\":\"jane@example.com\"}"); + 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 an IP to a domain authorization. +// POST /whitelabel/domains/{id}/ips + + +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("whitelabel/domains/{id}/ips"); + request.setBody("{\"ip\":\"192.168.0.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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Remove an IP from a domain authorization. +// DELETE /whitelabel/domains/{id}/ips/{ip} + + +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("whitelabel/domains/{id}/ips/{ip}"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Validate a domain authorization. +// POST /whitelabel/domains/{id}/validate + + +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("whitelabel/domains/{id}/validate"); + 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; + } + } +} diff --git a/examples/senderauthentication/ips.java b/examples/senderauthentication/ips.java new file mode 100644 index 00000000..c1983608 --- /dev/null +++ b/examples/senderauthentication/ips.java @@ -0,0 +1,127 @@ +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; + +public class CommonExample { + protected SendGrid sg; + protected Request request; + + protected static void init() { + this.sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); + this.request = new Request(); + } +} + +////////////////////////////////////////////////////////////////// +// Create a reverse DNS record +// POST /whitelabel/ips + + +public class Example extends CommonExample { + public static void main(String[] args) throws IOException { + try { + init(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/ips"); + request.setBody("{\"ip\":\"192.168.1.1\",\"domain\":\"example.com\",\"subdomain\":\"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 reverse DNS records +// GET /whitelabel/ips + + +public class Example extends CommonExample { + public static void main(String[] args) throws IOException { + try { + init(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/ips"); + request.addQueryParam("ip", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Retrieve a reverse DNS record +// GET /whitelabel/ips/{id} + + +public class Example extends CommonExample { + public static void main(String[] args) throws IOException { + try { + init(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/ips/{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 reverse DNS record +// DELETE /whitelabel/ips/{id} + + +public class Example extends CommonExample { + public static void main(String[] args) throws IOException { + try { + init(); + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/ips/{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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Validate a reverse DNS record +// POST /whitelabel/ips/{id}/validate + + +public class Example extends CommonExample { + public static void main(String[] args) throws IOException { + try { + init(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/ips/{id}/validate"); + 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; + } + } +} diff --git a/examples/senderauthentication/links.java b/examples/senderauthentication/links.java new file mode 100644 index 00000000..bf661339 --- /dev/null +++ b/examples/senderauthentication/links.java @@ -0,0 +1,238 @@ +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; + +////////////////////////////////////////////////////////////////// +// Create a Branded Link +// POST /whitelabel/links + + +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("whitelabel/links"); + request.setBody("{\"default\":true,\"domain\":\"example.com\",\"subdomain\":\"mail\"}"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Retrieve all link Branding +// GET /whitelabel/links + + +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("whitelabel/links"); + request.addQueryParam("limit", "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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Retrieve a Default Link Branding +// GET /whitelabel/links/default + + +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("whitelabel/links/default"); + request.addQueryParam("domain", "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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Retrieve Associated Link Branding +// GET /whitelabel/links/subuser + + +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("whitelabel/links/subuser"); + request.addQueryParam("username", "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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Disassociate a Link Branding +// DELETE /whitelabel/links/subuser + + +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("whitelabel/links/subuser"); + request.addQueryParam("username", "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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Update a Link Branding +// PATCH /whitelabel/links/{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("whitelabel/links/{id}"); + request.setBody("{\"default\":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 a Link Branding +// GET /whitelabel/links/{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("whitelabel/links/{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 Link Branding +// DELETE /whitelabel/links/{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("whitelabel/links/{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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Validate a Link Branding +// POST /whitelabel/links/{id}/validate + + +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("whitelabel/links/{id}/validate"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Associate a Link Branding +// POST /whitelabel/links/{link_id}/subuser + + +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("whitelabel/links/{link_id}/subuser"); + request.setBody("{\"username\":\"jane@example.com\"}"); + 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; + } + } +} + diff --git a/examples/senders/senders.java b/examples/senders/senders.java new file mode 100644 index 00000000..d81630da --- /dev/null +++ b/examples/senders/senders.java @@ -0,0 +1,143 @@ +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; + +////////////////////////////////////////////////////////////////// +// Create a Sender Identity +// POST /senders + + +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("senders"); + request.setBody("{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Get all Sender Identities +// GET /senders + + +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("senders"); + 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 Sender Identity +// PATCH /senders/{sender_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("senders/{sender_id}"); + request.setBody("{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// View a Sender Identity +// GET /senders/{sender_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("senders/{sender_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 Sender Identity +// DELETE /senders/{sender_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("senders/{sender_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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Resend Sender Identity Verification +// POST /senders/{sender_id}/resend_verification + + +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("senders/{sender_id}/resend_verification"); + 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; + } + } +} + diff --git a/examples/stats/stats.java b/examples/stats/stats.java new file mode 100644 index 00000000..1dbe5c25 --- /dev/null +++ b/examples/stats/stats.java @@ -0,0 +1,36 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve global email statistics +// GET /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("stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("offset", "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; + } + } +} + diff --git a/examples/subusers/CreateMonitorSettings.java b/examples/subusers/CreateMonitorSettings.java new file mode 100644 index 00000000..6fecfaff --- /dev/null +++ b/examples/subusers/CreateMonitorSettings.java @@ -0,0 +1,31 @@ +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; + +////////////////////////////////////////////////////////////////// +// Create monitor settings +// POST /subusers/{subuser_name}/monitor + + +public class CreateMonitorSettings { + 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("subusers/{subuser_name}/monitor"); + request.setBody("{\"frequency\":50000,\"email\":\"example@example.com\"}"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/subusers/CreateSubUser.java b/examples/subusers/CreateSubUser.java new file mode 100644 index 00000000..9cb283c8 --- /dev/null +++ b/examples/subusers/CreateSubUser.java @@ -0,0 +1,31 @@ +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; + +////////////////////////////////////////////////////////////////// +// Create Subuser +// POST /subusers + + +public class CreateSubUser { + 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("subusers"); + request.setBody("{\"username\":\"John@example.com\",\"ips\":[\"1.1.1.1\",\"2.2.2.2\"],\"password\":\"johns_password\",\"email\":\"John@example.com\"}"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/subusers/DeleteMonitorSettings.java b/examples/subusers/DeleteMonitorSettings.java new file mode 100644 index 00000000..ffcc25c8 --- /dev/null +++ b/examples/subusers/DeleteMonitorSettings.java @@ -0,0 +1,31 @@ +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; + + +////////////////////////////////////////////////////////////////// +// Delete monitor settings +// DELETE /subusers/{subuser_name}/monitor + + +public class DeleteMonitorSettings { + 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("subusers/{subuser_name}/monitor"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/subusers/DeleteSubUser.java b/examples/subusers/DeleteSubUser.java new file mode 100644 index 00000000..68207edf --- /dev/null +++ b/examples/subusers/DeleteSubUser.java @@ -0,0 +1,30 @@ +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; + +////////////////////////////////////////////////////////////////// +// Delete a subuser +// DELETE /subusers/{subuser_name} + + +public class DeleteSubUser { + 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("subusers/{subuser_name}"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/subusers/EnableOrDisableUser.java b/examples/subusers/EnableOrDisableUser.java new file mode 100644 index 00000000..107b7def --- /dev/null +++ b/examples/subusers/EnableOrDisableUser.java @@ -0,0 +1,31 @@ +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; + +////////////////////////////////////////////////////////////////// +// Enable/disable a subuser +// PATCH /subusers/{subuser_name} + + +public class EnableOrDisableUser { + 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("subusers/{subuser_name}"); + request.setBody("{\"disabled\":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; + } + } +} \ No newline at end of file diff --git a/examples/subusers/ListAllSubUsers.java b/examples/subusers/ListAllSubUsers.java new file mode 100644 index 00000000..ebc408f3 --- /dev/null +++ b/examples/subusers/ListAllSubUsers.java @@ -0,0 +1,32 @@ +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; + +////////////////////////////////////////////////////////////////// +// List all Subusers +// GET /subusers + +public class ListAllSubUsers { + 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("subusers"); + request.addQueryParam("username", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "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; + } + } +} \ No newline at end of file diff --git a/examples/subusers/RetrieveEmailStatistics.java b/examples/subusers/RetrieveEmailStatistics.java new file mode 100644 index 00000000..479f4f2e --- /dev/null +++ b/examples/subusers/RetrieveEmailStatistics.java @@ -0,0 +1,37 @@ +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; + + +////////////////////////////////////////////////////////////////// +// Retrieve email statistics for your subusers. +// GET /subusers/stats + + +public class RetrieveEmailStatistics { + 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("subusers/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("subusers", "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; + } + } +} diff --git a/examples/subusers/RetrieveMonitorSettings.java b/examples/subusers/RetrieveMonitorSettings.java new file mode 100644 index 00000000..6d219e2f --- /dev/null +++ b/examples/subusers/RetrieveMonitorSettings.java @@ -0,0 +1,31 @@ +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; + + +////////////////////////////////////////////////////////////////// +// Retrieve monitor settings for a subuser +// GET /subusers/{subuser_name}/monitor + + +public class RetrieveMonitorSettings { + 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("subusers/{subuser_name}/monitor"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/subusers/RetrieveMonthlyEmailStatistics.java b/examples/subusers/RetrieveMonthlyEmailStatistics.java new file mode 100644 index 00000000..b7d1c9b2 --- /dev/null +++ b/examples/subusers/RetrieveMonthlyEmailStatistics.java @@ -0,0 +1,36 @@ +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; + + +////////////////////////////////////////////////////////////////// +// Retrieve the monthly email statistics for a single subuser +// GET /subusers/{subuser_name}/stats/monthly + + +public class RetrieveMonthlyEmailStatistics { + 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("subusers/{subuser_name}/stats/monthly"); + request.addQueryParam("date", "test_string"); + request.addQueryParam("sort_by_direction", "asc"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "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; + } + } +} \ No newline at end of file diff --git a/examples/subusers/RetrieveMonthlyStats.java b/examples/subusers/RetrieveMonthlyStats.java new file mode 100644 index 00000000..7310c072 --- /dev/null +++ b/examples/subusers/RetrieveMonthlyStats.java @@ -0,0 +1,36 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve monthly stats for all subusers +// GET /subusers/stats/monthly + + +public class RetrieveMonthlyStats { + 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("subusers/stats/monthly"); + request.addQueryParam("subuser", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); + request.addQueryParam("date", "test_string"); + request.addQueryParam("sort_by_direction", "asc"); + 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; + } + } +} diff --git a/examples/subusers/RetrieveSubUserReputation.java b/examples/subusers/RetrieveSubUserReputation.java new file mode 100644 index 00000000..18664ed2 --- /dev/null +++ b/examples/subusers/RetrieveSubUserReputation.java @@ -0,0 +1,32 @@ +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; + + +////////////////////////////////////////////////////////////////// +// Retrieve Subuser Reputations +// GET /subusers/reputations + + +public class RetrieveSubUserReputation { + 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("subusers/reputations"); + request.addQueryParam("usernames", "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; + } + } +} diff --git a/examples/subusers/RetrieveTotalsForEachEmail.java b/examples/subusers/RetrieveTotalsForEachEmail.java new file mode 100644 index 00000000..de741967 --- /dev/null +++ b/examples/subusers/RetrieveTotalsForEachEmail.java @@ -0,0 +1,37 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve the totals for each email statistic metric for all subusers. +// GET /subusers/stats/sums + + +public class RetrieveTotalsForEachEmail { + 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("subusers/stats/sums"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("sort_by_direction", "asc"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/subusers/UpdateAssignedIPs.java b/examples/subusers/UpdateAssignedIPs.java new file mode 100644 index 00000000..60479769 --- /dev/null +++ b/examples/subusers/UpdateAssignedIPs.java @@ -0,0 +1,31 @@ +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; + +////////////////////////////////////////////////////////////////// +// Update IPs assigned to a subuser +// PUT /subusers/{subuser_name}/ips + + +public class UpdateAssignedIps { + 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("subusers/{subuser_name}/ips"); + request.setBody("[\"127.0.0.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; + } + } +} \ No newline at end of file diff --git a/examples/subusers/UpdateMonitorSettings.java b/examples/subusers/UpdateMonitorSettings.java new file mode 100644 index 00000000..81567982 --- /dev/null +++ b/examples/subusers/UpdateMonitorSettings.java @@ -0,0 +1,31 @@ +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; + +////////////////////////////////////////////////////////////////// +// Update Monitor Settings for a subuser +// PUT /subusers/{subuser_name}/monitor + + +public class UpdateMonitorSetting { + 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("subusers/{subuser_name}/monitor"); + request.setBody("{\"frequency\":500,\"email\":\"example@example.com\"}"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/DeleteBlocks.java b/examples/suppression/DeleteBlocks.java new file mode 100644 index 00000000..484ddc67 --- /dev/null +++ b/examples/suppression/DeleteBlocks.java @@ -0,0 +1,30 @@ +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; + +////////////////////////////////////////////////////////////////// +// Delete blocks +// DELETE /suppression/blocks + +public class DeleteBlocks { + 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("suppression/blocks"); + request.setBody("{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/DeleteBounce.java b/examples/suppression/DeleteBounce.java new file mode 100644 index 00000000..a8a9270d --- /dev/null +++ b/examples/suppression/DeleteBounce.java @@ -0,0 +1,30 @@ +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; + +////////////////////////////////////////////////////////////////// +// Delete a bounce +// DELETE /suppression/bounces/{email} + +public class DeleteBounce { + 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("suppression/bounces/{email}"); + request.addQueryParam("email_address", "example@example.com"); + 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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/DeleteBounces.java b/examples/suppression/DeleteBounces.java new file mode 100644 index 00000000..ec286aec --- /dev/null +++ b/examples/suppression/DeleteBounces.java @@ -0,0 +1,30 @@ +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; + +////////////////////////////////////////////////////////////////// +// Delete bounces +// DELETE /suppression/bounces + +public class DeleteBounces { + 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("suppression/bounces"); + request.setBody("{\"emails\":[\"example@example.com\",\"example2@example.com\"],\"delete_all\":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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/DeleteInvalidEmails.java b/examples/suppression/DeleteInvalidEmails.java new file mode 100644 index 00000000..56e3e25e --- /dev/null +++ b/examples/suppression/DeleteInvalidEmails.java @@ -0,0 +1,30 @@ +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; + +////////////////////////////////////////////////////////////////// +// Delete invalid emails +// DELETE /suppression/invalid_emails + +public class DeleteInvalidEmails { + 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("suppression/invalid_emails"); + request.setBody("{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/DeleteSpamReports.java b/examples/suppression/DeleteSpamReports.java new file mode 100644 index 00000000..c4adb4b3 --- /dev/null +++ b/examples/suppression/DeleteSpamReports.java @@ -0,0 +1,30 @@ +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; + +////////////////////////////////////////////////////////////////// +// Delete spam reports +// DELETE /suppression/spam_reports + +public class DeleteSpamReports { + 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("suppression/spam_reports"); + request.setBody("{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/DeleteSpecificBlock.java b/examples/suppression/DeleteSpecificBlock.java new file mode 100644 index 00000000..4e252c3f --- /dev/null +++ b/examples/suppression/DeleteSpecificBlock.java @@ -0,0 +1,29 @@ +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; + +////////////////////////////////////////////////////////////////// +// Delete a specific block +// DELETE /suppression/blocks/{email} + +public class DeleteSpecificBlock { + 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("suppression/blocks/{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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/DeleteSpecificInvalidEmail.java b/examples/suppression/DeleteSpecificInvalidEmail.java new file mode 100644 index 00000000..03def455 --- /dev/null +++ b/examples/suppression/DeleteSpecificInvalidEmail.java @@ -0,0 +1,29 @@ +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; + +////////////////////////////////////////////////////////////////// +// Delete a specific invalid email +// DELETE /suppression/invalid_emails/{email} + +public class DeleteSpecificInvalidEmail { + 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("suppression/invalid_emails/{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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/DeleteSpecificSpamReport.java b/examples/suppression/DeleteSpecificSpamReport.java new file mode 100644 index 00000000..fcad75bf --- /dev/null +++ b/examples/suppression/DeleteSpecificSpamReport.java @@ -0,0 +1,29 @@ +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; + +////////////////////////////////////////////////////////////////// +// Delete a specific spam report +// DELETE /suppression/spam_report/{email} + +public class DeleteSpecificSpamReport { + 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("suppression/spam_report/{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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/GetAllBlocks.java b/examples/suppression/GetAllBlocks.java new file mode 100644 index 00000000..c653c9be --- /dev/null +++ b/examples/suppression/GetAllBlocks.java @@ -0,0 +1,33 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve all blocks +// GET /suppression/blocks + +public class GetAllBlocks { + 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("suppression/blocks"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "1"); + request.addQueryParam("offset", "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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/GetAllBounces.java b/examples/suppression/GetAllBounces.java new file mode 100644 index 00000000..6c98010d --- /dev/null +++ b/examples/suppression/GetAllBounces.java @@ -0,0 +1,31 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve all bounces +// GET /suppression/bounces + +public class GetAllBounces { + 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("suppression/bounces"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("end_time", "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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/GetAllGlobalSuppressions.java b/examples/suppression/GetAllGlobalSuppressions.java new file mode 100644 index 00000000..f714b2c9 --- /dev/null +++ b/examples/suppression/GetAllGlobalSuppressions.java @@ -0,0 +1,33 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve all global suppressions +// GET /suppression/unsubscribes + +public class GetAllGlobalSuppressions { + 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("suppression/unsubscribes"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "1"); + request.addQueryParam("offset", "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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/GetAllInvalidEmails.java b/examples/suppression/GetAllInvalidEmails.java new file mode 100644 index 00000000..d2b2028b --- /dev/null +++ b/examples/suppression/GetAllInvalidEmails.java @@ -0,0 +1,33 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve all invalid emails +// GET /suppression/invalid_emails + +public class GetAllInvalidEmails { + 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("suppression/invalid_emails"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "1"); + request.addQueryParam("offset", "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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/GetAllSpamReports.java b/examples/suppression/GetAllSpamReports.java new file mode 100644 index 00000000..03795c45 --- /dev/null +++ b/examples/suppression/GetAllSpamReports.java @@ -0,0 +1,33 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve all spam reports +// GET /suppression/spam_reports + +public class GetAllSpamReports { + 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("suppression/spam_reports"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "1"); + request.addQueryParam("offset", "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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/GetBounce.java b/examples/suppression/GetBounce.java new file mode 100644 index 00000000..fe3259f5 --- /dev/null +++ b/examples/suppression/GetBounce.java @@ -0,0 +1,29 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve a Bounce +// GET /suppression/bounces/{email} + +public class GetBounce { + 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("suppression/bounces/{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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/GetSpecificBlock.java b/examples/suppression/GetSpecificBlock.java new file mode 100644 index 00000000..1c9b8dee --- /dev/null +++ b/examples/suppression/GetSpecificBlock.java @@ -0,0 +1,29 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve a specific block +// GET /suppression/blocks/{email} + +public class GetSpecificBlock { + 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("suppression/blocks/{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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/GetSpecificInvalidEmail.java b/examples/suppression/GetSpecificInvalidEmail.java new file mode 100644 index 00000000..54f8f8a4 --- /dev/null +++ b/examples/suppression/GetSpecificInvalidEmail.java @@ -0,0 +1,29 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve a specific invalid email +// GET /suppression/invalid_emails/{email} + +public class GetSpecificInvalidEmail { + 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("suppression/invalid_emails/{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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/GetSpecificSpamReport.java b/examples/suppression/GetSpecificSpamReport.java new file mode 100644 index 00000000..bd5d3826 --- /dev/null +++ b/examples/suppression/GetSpecificSpamReport.java @@ -0,0 +1,29 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve a specific spam report +// GET /suppression/spam_report/{email} + +public class GetSpecificSpamReport { + 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("suppression/spam_report/{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; + } + } +} \ No newline at end of file diff --git a/examples/suppression/README.md b/examples/suppression/README.md new file mode 100644 index 00000000..ca686a4b --- /dev/null +++ b/examples/suppression/README.md @@ -0,0 +1,21 @@ + + +This folder contains various examples on using the SUPPRESSION endpoint of SendGrid with Java: + +* [Retrieve all blocks (GET /suppression/blocks)](GetAllBlocks.java) +* [Delete blocks (DELETE /suppression/blocks)](DeleteBlocks.java) +* [Retrieve a specific block (GET /suppression/blocks/{email})](GetSpecificBlock.java) +* [Delete a specific block (DELETE /suppression/blocks/{email})](DeleteSpecificBlock.java) +* [Retrieve all bounces (GET /suppression/bounces)](GetAllBounces.java) +* [Delete bounces (DELETE /suppression/bounces)](DeleteBounces.java) +* [Retrieve a Bounce (GET /suppression/bounces/{email})](GetBounce.java) +* [Delete a bounce (DELETE /suppression/bounces/{email})](DeleteBounce.java) +* [Retrieve all invalid emails (GET /suppression/invalid_emails)](GetAllInvalidEmails.java) +* [Delete invalid emails (DELETE /suppression/invalid_emails)](DeleteInvalidEmails.java) +* [Retrieve a specific invalid email (GET /suppression/invalid_emails/{email})](GetSpecificInvalidEmail.java) +* [Delete a specific invalid email (DELETE /suppression/invalid_emails/{email})](DeleteSpecificInvalidEmail.java) +* [Retrieve a specific spam report (GET /suppression/spam_report/{email})](GetSpecificSpamReport.java) +* [Delete a specific spam report (DELETE /suppression/spam_report/{email})](DeleteSpecificSpamReport.java) +* [Retrieve all spam reports (GET /suppression/spam_reports)](GetAllSpamReports.java) +* [Delete spam reports (DELETE /suppression/spam_reports)](DeleteSpamReports.java) +* [Retrieve all global suppressions (GET /suppression/unsubscribes)](GetAllGlobalSuppressions.java) \ No newline at end of file diff --git a/examples/templates/templates.java b/examples/templates/templates.java new file mode 100644 index 00000000..a16c4bed --- /dev/null +++ b/examples/templates/templates.java @@ -0,0 +1,233 @@ +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; + +////////////////////////////////////////////////////////////////// +// Create a transactional template. +// POST /templates + + +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("templates"); + request.setBody("{\"name\":\"example_name\"}"); + 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 transactional templates. +// GET /templates + + +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("templates"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Edit a transactional template. +// PATCH /templates/{template_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("templates/{template_id}"); + request.setBody("{\"name\":\"new_example_name\"}"); + 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 single transactional template. +// GET /templates/{template_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("templates/{template_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 template. +// DELETE /templates/{template_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("templates/{template_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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Create a new transactional template version. +// POST /templates/{template_id}/versions + + +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("templates/{template_id}/versions"); + request.setBody("{\"name\":\"example_version_name\",\"html_content\":\"<%body%>\",\"plain_content\":\"<%body%>\",\"active\":1,\"template_id\":\"ddb96bbc-9b92-425e-8979-99464621b543\",\"subject\":\"<%subject%>\"}"); + 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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Edit a transactional template version. +// PATCH /templates/{template_id}/versions/{version_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("templates/{template_id}/versions/{version_id}"); + request.setBody("{\"active\":1,\"html_content\":\"<%body%>\",\"subject\":\"<%subject%>\",\"name\":\"updated_example_name\",\"plain_content\":\"<%body%>\"}"); + 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 transactional template version. +// GET /templates/{template_id}/versions/{version_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("templates/{template_id}/versions/{version_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 transactional template version. +// DELETE /templates/{template_id}/versions/{version_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("templates/{template_id}/versions/{version_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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Activate a transactional template version. +// POST /templates/{template_id}/versions/{version_id}/activate + + +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("templates/{template_id}/versions/{version_id}/activate"); + 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; + } + } +} + diff --git a/examples/trackingsettings/trackingsettings.java b/examples/trackingsettings/trackingsettings.java new file mode 100644 index 00000000..17b8d0d0 --- /dev/null +++ b/examples/trackingsettings/trackingsettings.java @@ -0,0 +1,213 @@ +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; + +////////////////////////////////////////////////////////////////// +// Retrieve Tracking Settings +// GET /tracking_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("tracking_settings"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "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 Click Tracking Settings +// PATCH /tracking_settings/click + + +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("tracking_settings/click"); + request.setBody("{\"enabled\":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 Click Track Settings +// GET /tracking_settings/click + + +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("tracking_settings/click"); + 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 Google Analytics Settings +// PATCH /tracking_settings/google_analytics + + +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("tracking_settings/google_analytics"); + request.setBody("{\"utm_campaign\":\"website\",\"utm_term\":\"\",\"utm_content\":\"\",\"enabled\":true,\"utm_source\":\"sendgrid.com\",\"utm_medium\":\"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 Google Analytics Settings +// GET /tracking_settings/google_analytics + + +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("tracking_settings/google_analytics"); + 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 Open Tracking Settings +// PATCH /tracking_settings/open + + +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("tracking_settings/open"); + request.setBody("{\"enabled\":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; + } + } +} + +////////////////////////////////////////////////////////////////// +// Get Open Tracking Settings +// GET /tracking_settings/open + + +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("tracking_settings/open"); + 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 Subscription Tracking Settings +// PATCH /tracking_settings/subscription + + +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("tracking_settings/subscription"); + request.setBody("{\"url\":\"url\",\"html_content\":\"html content\",\"enabled\":true,\"landing\":\"landing page html\",\"replace\":\"replacement tag\",\"plain_content\":\"text content\"}"); + 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 Subscription Tracking Settings +// GET /tracking_settings/subscription + + +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("tracking_settings/subscription"); + 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; + } + } +} + diff --git a/examples/user/user.java b/examples/user/user.java new file mode 100644 index 00000000..9c5ff95c --- /dev/null +++ b/examples/user/user.java @@ -0,0 +1,575 @@ +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\":\"example@example.com\"}"); + 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; + } + } +} + diff --git a/gradle.properties.example b/gradle.properties.example deleted file mode 100644 index cde593ea..00000000 --- a/gradle.properties.example +++ /dev/null @@ -1,6 +0,0 @@ -signing.keyId= -signing.password= -signing.secretKeyRingFile=/Users/yourusername/.gnupg/secring.gpg - -sonatypeUsername= -sonatypePassword= diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 0087cd3b..00000000 Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index b0c3cf1e..00000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Mon May 26 17:38:02 PDT 2014 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-1.8-bin.zip diff --git a/gradlew b/gradlew deleted file mode 100755 index 91a7e269..00000000 --- a/gradlew +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/env bash - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; -esac - -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat deleted file mode 100644 index aec99730..00000000 --- a/gradlew.bat +++ /dev/null @@ -1,90 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/maven-help.png b/maven-help.png deleted file mode 100644 index fe475a04..00000000 Binary files a/maven-help.png and /dev/null differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..5c5249a7 --- /dev/null +++ b/pom.xml @@ -0,0 +1,312 @@ + +Check out our spring line!
\",\"list_ids\":[110,124],\"sender_id\":124451,\"subject\":\"New Products for Spring!\",\"plain_content\":\"Check out our spring line!\",\"suppression_group_id\":42,\"title\":\"March Newsletter\",\"segment_ids\":[110],\"categories\":[\"spring line\"],\"ip_pool\":\"marketing\"}"); + Response response = sg.api(request); + Assert.assertEquals(201, response.getStatusCode()); + } + + @Test + public void test_campaigns_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("campaigns"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_campaigns__campaign_id__patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("campaigns/{campaign_id}"); + request.setBody("{\"html_content\":\"Check out our summer line!
\",\"subject\":\"New Products for Summer!\",\"title\":\"May Newsletter\",\"categories\":[\"summer line\"],\"plain_content\":\"Check out our summer line!\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_campaigns__campaign_id__get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("campaigns/{campaign_id}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_campaigns__campaign_id__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("campaigns/{campaign_id}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_campaigns__campaign_id__schedules_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("campaigns/{campaign_id}/schedules"); + request.setBody("{\"send_at\":1489451436}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_campaigns__campaign_id__schedules_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "201"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("campaigns/{campaign_id}/schedules"); + request.setBody("{\"send_at\":1489771528}"); + Response response = sg.api(request); + Assert.assertEquals(201, response.getStatusCode()); + } + + @Test + public void test_campaigns__campaign_id__schedules_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("campaigns/{campaign_id}/schedules"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_campaigns__campaign_id__schedules_delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("campaigns/{campaign_id}/schedules"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_campaigns__campaign_id__schedules_now_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "201"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("campaigns/{campaign_id}/schedules/now"); + Response response = sg.api(request); + Assert.assertEquals(201, response.getStatusCode()); + } + + @Test + public void test_campaigns__campaign_id__schedules_test_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("campaigns/{campaign_id}/schedules/test"); + request.setBody("{\"to\":\"your.email@example.com\"}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_categories_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("categories"); + request.addQueryParam("category", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_categories_stats_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("categories/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("categories", "test_string"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_categories_stats_sums_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("categories/stats/sums"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("sort_by_direction", "asc"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_clients_stats_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("clients/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_clients__client_type__stats_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("clients/{client_type}/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_contactdb_custom_fields_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "201"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("contactdb/custom_fields"); + request.setBody("{\"type\":\"text\",\"name\":\"pet\"}"); + Response response = sg.api(request); + Assert.assertEquals(201, response.getStatusCode()); + } + + @Test + public void test_contactdb_custom_fields_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/custom_fields"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_contactdb_custom_fields__custom_field_id__get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/custom_fields/{custom_field_id}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_contactdb_custom_fields__custom_field_id__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "202"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/custom_fields/{custom_field_id}"); + Response response = sg.api(request); + Assert.assertEquals(202, response.getStatusCode()); + } - String address = "email@example.com"; - String address2 = "email2@example.com"; - email.addTo(address); - email.addTo(address2); + @Test + public void test_contactdb_lists_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "201"); - String[] correct = {address, address2}; + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("contactdb/lists"); + request.setBody("{\"name\":\"your list name\"}"); + Response response = sg.api(request); + Assert.assertEquals(201, response.getStatusCode()); + } + + @Test + public void test_contactdb_lists_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/lists"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_contactdb_lists_delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/lists"); + request.setBody("[1,2,3,4]"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_contactdb_lists__list_id__patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("contactdb/lists/{list_id}"); + request.setBody("{\"name\":\"newlistname\"}"); + request.addQueryParam("list_id", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_contactdb_lists__list_id__get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/lists/{list_id}"); + request.addQueryParam("list_id", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_contactdb_lists__list_id__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "202"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/lists/{list_id}"); + request.addQueryParam("delete_contacts", "true"); + Response response = sg.api(request); + Assert.assertEquals(202, response.getStatusCode()); + } + + @Test + public void test_contactdb_lists__list_id__recipients_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "201"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("contactdb/lists/{list_id}/recipients"); + request.setBody("[\"recipient_id1\",\"recipient_id2\"]"); + Response response = sg.api(request); + Assert.assertEquals(201, response.getStatusCode()); + } + + @Test + public void test_contactdb_lists__list_id__recipients_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/lists/{list_id}/recipients"); + request.addQueryParam("page", "1"); + request.addQueryParam("page_size", "1"); + request.addQueryParam("list_id", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_contactdb_lists__list_id__recipients__recipient_id__post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "201"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("contactdb/lists/{list_id}/recipients/{recipient_id}"); + Response response = sg.api(request); + Assert.assertEquals(201, response.getStatusCode()); + } + + @Test + public void test_contactdb_lists__list_id__recipients__recipient_id__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/lists/{list_id}/recipients/{recipient_id}"); + request.addQueryParam("recipient_id", "1"); + request.addQueryParam("list_id", "1"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_contactdb_recipients_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "201"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("contactdb/recipients"); + request.setBody("[{\"first_name\":\"Guy\",\"last_name\":\"Jones\",\"email\":\"jones@example.com\"}]"); + Response response = sg.api(request); + Assert.assertEquals(201, response.getStatusCode()); + } + + @Test + public void test_contactdb_recipients_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "201"); - assertArrayEquals(correct, email.getTos()); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("contactdb/recipients"); + request.setBody("[{\"age\":25,\"last_name\":\"User\",\"email\":\"example@example.com\",\"first_name\":\"\"},{\"age\":25,\"last_name\":\"User\",\"email\":\"example2@example.com\",\"first_name\":\"Example\"}]"); + Response response = sg.api(request); + Assert.assertEquals(201, response.getStatusCode()); } - @Test public void testAddToWithAFrom() { - email = new SendGrid.Email(); + @Test + public void test_contactdb_recipients_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); - String address = "email@example.com"; - String fromaddress = "from@mailinator.com"; - email.addTo(address); - email.setFrom(fromaddress); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients"); + request.addQueryParam("page", "1"); + request.addQueryParam("page_size", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_contactdb_recipients_delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/recipients"); + request.setBody("[\"recipient_id1\",\"recipient_id2\"]"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_contactdb_recipients_billable_count_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/billable_count"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_contactdb_recipients_count_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); - String[] correct = {address}; + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/count"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_contactdb_recipients_search_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/search"); + request.addQueryParam("{field_name}", "test_string"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } - assertArrayEquals(correct, email.getTos()); - assertEquals(fromaddress, email.getFrom()); + @Test + public void test_contactdb_recipients__recipient_id__get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/{recipient_id}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); } - @Test public void testAddToName() { - email = new SendGrid.Email(); + @Test + public void test_contactdb_recipients__recipient_id__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); - String name = "John"; - email.addToName(name); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/recipients/{recipient_id}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_contactdb_recipients__recipient_id__lists_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/recipients/{recipient_id}/lists"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } - String[] correct = {name}; + @Test + public void test_contactdb_reserved_fields_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); - assertArrayEquals(correct, email.getToNames()); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/reserved_fields"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); } - @Test public void testAddCc() { - email = new SendGrid.Email(); + @Test + public void test_contactdb_segments_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); - String address = "email@example.com"; - email.addCc(address); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("contactdb/segments"); + request.setBody("{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and_or\":\"\",\"value\":\"Miller\"},{\"operator\":\"gt\",\"field\":\"last_clicked\",\"and_or\":\"and\",\"value\":\"01/02/2015\"},{\"operator\":\"eq\",\"field\":\"clicks.campaign_identifier\",\"and_or\":\"or\",\"value\":\"513\"}],\"name\":\"Last Name Miller\",\"list_id\":4}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } - String[] correct = {address}; + @Test + public void test_contactdb_segments_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); - assertArrayEquals(correct, email.getCcs()); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/segments"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); } - @Test public void testSetFrom() { - email = new SendGrid.Email(); + @Test + public void test_contactdb_segments__segment_id__patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("contactdb/segments/{segment_id}"); + request.setBody("{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and_or\":\"\",\"value\":\"Miller\"}],\"name\":\"The Millers\",\"list_id\":5}"); + request.addQueryParam("segment_id", "test_string"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } - String address = "email@example.com"; - email.setFrom(address); + @Test + public void test_contactdb_segments__segment_id__get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); - assertEquals(address, email.getFrom()); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/segments/{segment_id}"); + request.addQueryParam("segment_id", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); } - @Test public void testSetFromName() { - email = new SendGrid.Email(); + @Test + public void test_contactdb_segments__segment_id__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("contactdb/segments/{segment_id}"); + request.addQueryParam("delete_contacts", "true"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } - String fromname = "Uncle Bob"; - email.setFromName(fromname); + @Test + public void test_contactdb_segments__segment_id__recipients_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); - assertEquals(fromname, email.getFromName()); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("contactdb/segments/{segment_id}/recipients"); + request.addQueryParam("page", "1"); + request.addQueryParam("page_size", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); } - @Test public void testSetReplyTo() { - email = new SendGrid.Email(); + @Test + public void test_devices_stats_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("devices/stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("offset", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } - String address = "email@example.com"; - email.setReplyTo(address); + @Test + public void test_geo_stats_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); - assertEquals(address, email.getReplyTo()); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("geo/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("country", "US"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); } - @Test public void testAddBcc() { - email = new SendGrid.Email(); + @Test + public void test_ips_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); - String address = "email@example.com"; - email.addBcc(address); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("ips"); + request.addQueryParam("subuser", "test_string"); + request.addQueryParam("ip", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("exclude_whitelabels", "true"); + request.addQueryParam("offset", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } - String[] correct = {address}; + @Test + public void test_ips_assigned_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); - assertArrayEquals(correct, email.getBccs()); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("ips/assigned"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); } - @Test public void testSetSubject() { - email = new SendGrid.Email(); + @Test + public void test_ips_pools_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); - String subject = "This is a subject"; - email.setSubject(subject); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("ips/pools"); + request.setBody("{\"name\":\"marketing\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_ips_pools_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); - assertEquals(subject, email.getSubject()); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("ips/pools"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); } - @Test public void testSetText() { - email = new SendGrid.Email(); + @Test + public void test_ips_pools__pool_name__put() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PUT); + request.setEndpoint("ips/pools/{pool_name}"); + request.setBody("{\"name\":\"new_pool_name\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } - String text = "This is some email text."; - email.setText(text); + @Test + public void test_ips_pools__pool_name__get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); - assertEquals(text, email.getText()); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("ips/pools/{pool_name}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); } - @Test public void testSetHtml() { - email = new SendGrid.Email(); + @Test + public void test_ips_pools__pool_name__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); - String html = "This is some email text."; - email.setHtml(html); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("ips/pools/{pool_name}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_ips_pools__pool_name__ips_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "201"); - assertEquals(html, email.getHtml()); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("ips/pools/{pool_name}/ips"); + request.setBody("{\"ip\":\"0.0.0.0\"}"); + Response response = sg.api(request); + Assert.assertEquals(201, response.getStatusCode()); } - @Test public void testAddHeader() { - email = new SendGrid.Email(); + @Test + public void test_ips_pools__pool_name__ips__ip__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); - email.addHeader("key", "value"); - email.addHeader("other", "other-value"); + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("ips/pools/{pool_name}/ips/{ip}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } - MapHello, world!
ThanksThe SendGrid Team
\"},\"spam_check\":{\"threshold\":3,\"post_to_url\":\"http://example.com/compliance\",\"enable\":true},\"bypass_list_management\":{\"enable\":true},\"sandbox_mode\":{\"enable\":false},\"bcc\":{\"enable\":true,\"email\":\"ben.doe@example.com\"}},\"reply_to\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"sections\":{\"section\":{\":sectionName2\":\"section 2 text\",\":sectionName1\":\"section 1 text\"}},\"template_id\":\"[YOUR TEMPLATE ID GOES HERE]\",\"categories\":[\"category1\",\"category2\"],\"send_at\":1409348513}"); + Response response = sg.api(request); + Assert.assertEquals(202, response.getStatusCode()); + } + + @Test + public void test_mail_settings_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mail_settings_address_whitelist_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/address_whitelist"); + request.setBody("{\"list\":[\"email1@example.com\",\"example.com\"],\"enabled\":true}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mail_settings_address_whitelist_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/address_whitelist"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mail_settings_bcc_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/bcc"); + request.setBody("{\"enabled\":false,\"email\":\"email@example.com\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mail_settings_bcc_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/bcc"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mail_settings_bounce_purge_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/bounce_purge"); + request.setBody("{\"hard_bounces\":5,\"soft_bounces\":5,\"enabled\":true}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mail_settings_bounce_purge_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/bounce_purge"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mail_settings_footer_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/footer"); + request.setBody("{\"html_content\":\"...\",\"enabled\":true,\"plain_content\":\"...\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mail_settings_footer_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/footer"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mail_settings_forward_bounce_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/forward_bounce"); + request.setBody("{\"enabled\":true,\"email\":\"example@example.com\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mail_settings_forward_bounce_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/forward_bounce"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mail_settings_forward_spam_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/forward_spam"); + request.setBody("{\"enabled\":false,\"email\":\"\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mail_settings_forward_spam_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/forward_spam"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mail_settings_plain_content_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/plain_content"); + request.setBody("{\"enabled\":false}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mail_settings_plain_content_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/plain_content"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mail_settings_spam_check_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/spam_check"); + request.setBody("{\"url\":\"url\",\"max_score\":5,\"enabled\":true}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mail_settings_spam_check_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/spam_check"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mail_settings_template_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("mail_settings/template"); + request.setBody("{\"html_content\":\"<% body %>\",\"enabled\":true}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mail_settings_template_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mail_settings/template"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_mailbox_providers_stats_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("mailbox_providers/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("mailbox_providers", "test_string"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_partner_settings_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("partner_settings"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_partner_settings_new_relic_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("partner_settings/new_relic"); + request.setBody("{\"enable_subuser_statistics\":true,\"enabled\":true,\"license_key\":\"\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_partner_settings_new_relic_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("partner_settings/new_relic"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_scopes_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("scopes"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_senders_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "201"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("senders"); + request.setBody("{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender ID\"}"); + Response response = sg.api(request); + Assert.assertEquals(201, response.getStatusCode()); + } + + @Test + public void test_senders_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("senders"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_senders__sender_id__patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("senders/{sender_id}"); + request.setBody("{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender ID\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_senders__sender_id__get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("senders/{sender_id}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_senders__sender_id__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("senders/{sender_id}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_senders__sender_id__resend_verification_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("senders/{sender_id}/resend_verification"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_stats_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("stats"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("offset", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_subusers_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("subusers"); + request.setBody("{\"username\":\"John@example.com\",\"ips\":[\"1.1.1.1\",\"2.2.2.2\"],\"password\":\"johns_password\",\"email\":\"John@example.com\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_subusers_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("subusers"); + request.addQueryParam("username", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_subusers_reputations_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("subusers/reputations"); + request.addQueryParam("usernames", "test_string"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_subusers_stats_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("subusers/stats"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("subusers", "test_string"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_subusers_stats_monthly_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("subusers/stats/monthly"); + request.addQueryParam("subuser", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); + request.addQueryParam("date", "test_string"); + request.addQueryParam("sort_by_direction", "asc"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_subusers_stats_sums_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("subusers/stats/sums"); + request.addQueryParam("end_date", "2016-04-01"); + request.addQueryParam("aggregated_by", "day"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); + request.addQueryParam("start_date", "2016-01-01"); + request.addQueryParam("sort_by_direction", "asc"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_subusers__subuser_name__patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("subusers/{subuser_name}"); + request.setBody("{\"disabled\":false}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_subusers__subuser_name__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("subusers/{subuser_name}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_subusers__subuser_name__ips_put() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PUT); + request.setEndpoint("subusers/{subuser_name}/ips"); + request.setBody("[\"127.0.0.1\"]"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_subusers__subuser_name__monitor_put() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PUT); + request.setEndpoint("subusers/{subuser_name}/monitor"); + request.setBody("{\"frequency\":500,\"email\":\"example@example.com\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_subusers__subuser_name__monitor_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("subusers/{subuser_name}/monitor"); + request.setBody("{\"frequency\":50000,\"email\":\"example@example.com\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_subusers__subuser_name__monitor_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("subusers/{subuser_name}/monitor"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_subusers__subuser_name__monitor_delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("subusers/{subuser_name}/monitor"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_subusers__subuser_name__stats_monthly_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("subusers/{subuser_name}/stats/monthly"); + request.addQueryParam("date", "test_string"); + request.addQueryParam("sort_by_direction", "asc"); + request.addQueryParam("limit", "1"); + request.addQueryParam("sort_by_metric", "test_string"); + request.addQueryParam("offset", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_suppression_blocks_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("suppression/blocks"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "1"); + request.addQueryParam("offset", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_suppression_blocks_delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/blocks"); + request.setBody("{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_suppression_blocks__email__get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("suppression/blocks/{email}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_suppression_blocks__email__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/blocks/{email}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_suppression_bounces_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("suppression/bounces"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("end_time", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_suppression_bounces_delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/bounces"); + request.setBody("{\"emails\":[\"example@example.com\",\"example2@example.com\"],\"delete_all\":true}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_suppression_bounces__email__get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("suppression/bounces/{email}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_suppression_bounces__email__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/bounces/{email}"); + request.addQueryParam("email_address", "example@example.com"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_suppression_invalid_emails_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("suppression/invalid_emails"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "1"); + request.addQueryParam("offset", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_suppression_invalid_emails_delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/invalid_emails"); + request.setBody("{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_suppression_invalid_emails__email__get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("suppression/invalid_emails/{email}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_suppression_invalid_emails__email__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/invalid_emails/{email}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_suppression_spam_report__email__get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("suppression/spam_report/{email}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_suppression_spam_report__email__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/spam_report/{email}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_suppression_spam_reports_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("suppression/spam_reports"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "1"); + request.addQueryParam("offset", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_suppression_spam_reports_delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("suppression/spam_reports"); + request.setBody("{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_suppression_unsubscribes_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("suppression/unsubscribes"); + request.addQueryParam("start_time", "1"); + request.addQueryParam("limit", "1"); + request.addQueryParam("end_time", "1"); + request.addQueryParam("offset", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_templates_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "201"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("templates"); + request.setBody("{\"name\":\"example_name\"}"); + Response response = sg.api(request); + Assert.assertEquals(201, response.getStatusCode()); + } + + @Test + public void test_templates_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("templates"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_templates__template_id__patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("templates/{template_id}"); + request.setBody("{\"name\":\"new_example_name\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_templates__template_id__get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("templates/{template_id}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_templates__template_id__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("templates/{template_id}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_templates__template_id__versions_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "201"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("templates/{template_id}/versions"); + request.setBody("{\"name\":\"example_version_name\",\"html_content\":\"<%body%>\",\"plain_content\":\"<%body%>\",\"active\":1,\"template_id\":\"ddb96bbc-9b92-425e-8979-99464621b543\",\"subject\":\"<%subject%>\"}"); + Response response = sg.api(request); + Assert.assertEquals(201, response.getStatusCode()); + } + + @Test + public void test_templates__template_id__versions__version_id__patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("templates/{template_id}/versions/{version_id}"); + request.setBody("{\"active\":1,\"html_content\":\"<%body%>\",\"subject\":\"<%subject%>\",\"name\":\"updated_example_name\",\"plain_content\":\"<%body%>\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_templates__template_id__versions__version_id__get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("templates/{template_id}/versions/{version_id}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_templates__template_id__versions__version_id__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("templates/{template_id}/versions/{version_id}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_templates__template_id__versions__version_id__activate_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("templates/{template_id}/versions/{version_id}/activate"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_tracking_settings_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_tracking_settings_click_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("tracking_settings/click"); + request.setBody("{\"enabled\":true}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_tracking_settings_click_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings/click"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_tracking_settings_google_analytics_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("tracking_settings/google_analytics"); + request.setBody("{\"utm_campaign\":\"website\",\"utm_term\":\"\",\"utm_content\":\"\",\"enabled\":true,\"utm_source\":\"sendgrid.com\",\"utm_medium\":\"email\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_tracking_settings_google_analytics_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings/google_analytics"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_tracking_settings_open_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("tracking_settings/open"); + request.setBody("{\"enabled\":true}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_tracking_settings_open_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings/open"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_tracking_settings_subscription_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("tracking_settings/subscription"); + request.setBody("{\"url\":\"url\",\"html_content\":\"html content\",\"enabled\":true,\"landing\":\"landing page html\",\"replace\":\"replacement tag\",\"plain_content\":\"text content\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_tracking_settings_subscription_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("tracking_settings/subscription"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_account_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("user/account"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_credits_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("user/credits"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_email_put() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PUT); + request.setEndpoint("user/email"); + request.setBody("{\"email\":\"example@example.com\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_email_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("user/email"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_password_put() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + 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); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_profile_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + 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); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_profile_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("user/profile"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_scheduled_sends_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "201"); + + 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); + Assert.assertEquals(201, response.getStatusCode()); + } + + @Test + public void test_user_scheduled_sends_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("user/scheduled_sends"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_scheduled_sends__batch_id__patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("user/scheduled_sends/{batch_id}"); + request.setBody("{\"status\":\"pause\"}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_user_scheduled_sends__batch_id__get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("user/scheduled_sends/{batch_id}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_scheduled_sends__batch_id__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("user/scheduled_sends/{batch_id}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_user_settings_enforced_tls_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + 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); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_settings_enforced_tls_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("user/settings/enforced_tls"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_username_put() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PUT); + request.setEndpoint("user/username"); + request.setBody("{\"username\":\"test_username\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_username_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("user/username"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_webhooks_event_settings_patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + 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); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_webhooks_event_settings_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("user/webhooks/event/settings"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_webhooks_event_test_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("user/webhooks/event/test"); + request.setBody("{\"url\":\"url\"}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_user_webhooks_parse_settings_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "201"); + + 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); + Assert.assertEquals(201, response.getStatusCode()); + } + + @Test + public void test_user_webhooks_parse_settings_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("user/webhooks/parse/settings"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_webhooks_parse_settings__hostname__patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + 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); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_webhooks_parse_settings__hostname__get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("user/webhooks/parse/settings/{hostname}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_webhooks_parse_settings__hostname__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("user/webhooks/parse/settings/{hostname}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_user_webhooks_parse_stats_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + 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); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_whitelabel_domains_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "201"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/domains"); + request.setBody("{\"automatic_security\":false,\"username\":\"john@example.com\",\"domain\":\"example.com\",\"default\":true,\"custom_spf\":true,\"ips\":[\"192.168.1.1\",\"192.168.1.2\"],\"subdomain\":\"news\"}"); + Response response = sg.api(request); + Assert.assertEquals(201, response.getStatusCode()); + } + + @Test + public void test_whitelabel_domains_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/domains"); + request.addQueryParam("username", "test_string"); + request.addQueryParam("domain", "test_string"); + request.addQueryParam("exclude_subusers", "true"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_whitelabel_domains_default_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/domains/default"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_whitelabel_domains_subuser_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/domains/subuser"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_whitelabel_domains_subuser_delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/domains/subuser"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_whitelabel_domains__domain_id__patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("whitelabel/domains/{domain_id}"); + request.setBody("{\"default\":false,\"custom_spf\":true}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_whitelabel_domains__domain_id__get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/domains/{domain_id}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_whitelabel_domains__domain_id__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/domains/{domain_id}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_whitelabel_domains__domain_id__subuser_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "201"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/domains/{domain_id}/subuser"); + request.setBody("{\"username\":\"jane@example.com\"}"); + Response response = sg.api(request); + Assert.assertEquals(201, response.getStatusCode()); + } + + @Test + public void test_whitelabel_domains__id__ips_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/domains/{id}/ips"); + request.setBody("{\"ip\":\"192.168.0.1\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_whitelabel_domains__id__ips__ip__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/domains/{id}/ips/{ip}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_whitelabel_domains__id__validate_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/domains/{id}/validate"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_whitelabel_ips_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "201"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/ips"); + request.setBody("{\"ip\":\"192.168.1.1\",\"domain\":\"example.com\",\"subdomain\":\"email\"}"); + Response response = sg.api(request); + Assert.assertEquals(201, response.getStatusCode()); + } + + @Test + public void test_whitelabel_ips_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/ips"); + request.addQueryParam("ip", "test_string"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_whitelabel_ips__id__get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/ips/{id}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_whitelabel_ips__id__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/ips/{id}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_whitelabel_ips__id__validate_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/ips/{id}/validate"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_whitelabel_links_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "201"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/links"); + request.setBody("{\"default\":true,\"domain\":\"example.com\",\"subdomain\":\"mail\"}"); + request.addQueryParam("limit", "1"); + request.addQueryParam("offset", "1"); + Response response = sg.api(request); + Assert.assertEquals(201, response.getStatusCode()); + } + + @Test + public void test_whitelabel_links_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/links"); + request.addQueryParam("limit", "1"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_whitelabel_links_default_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/links/default"); + request.addQueryParam("domain", "test_string"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_whitelabel_links_subuser_get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/links/subuser"); + request.addQueryParam("username", "test_string"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_whitelabel_links_subuser_delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/links/subuser"); + request.addQueryParam("username", "test_string"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_whitelabel_links__id__patch() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("whitelabel/links/{id}"); + request.setBody("{\"default\":true}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_whitelabel_links__id__get() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("whitelabel/links/{id}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_whitelabel_links__id__delete() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + + Request request = new Request(); + request.setMethod(Method.DELETE); + request.setEndpoint("whitelabel/links/{id}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_whitelabel_links__id__validate_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/links/{id}/validate"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_whitelabel_links__link_id__subuser_post() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("whitelabel/links/{link_id}/subuser"); + request.setBody("{\"username\":\"jane@example.com\"}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_add_impersonate_subuser() { + SendGrid sg = new SendGrid(SENDGRID_API_KEY); + + sg.addImpersonateSubuser("subusername"); + Assert.assertEquals(sg.getRequestHeaders().get("on-behalf-of"), "subusername"); + } + + @Test + public void test_remove_impersonate_subuser() { + SendGrid sg = new SendGrid(SENDGRID_API_KEY); + + sg.addImpersonateSubuser("subusername"); + Assert.assertEquals(sg.getRequestHeaders().get("on-behalf-of"), "subusername"); + + sg.removeImpersonateSubuser(); + Assert.assertEquals(sg.getRequestHeaders().get("on-behalf-of"), null); + } + + @Test + public void test_get_impersonate_subuser() { + SendGrid sg = new SendGrid(SENDGRID_API_KEY); + + sg.addImpersonateSubuser("subusername"); + Assert.assertEquals(sg.getImpersonateSubuser(), "subusername"); + + sg.removeImpersonateSubuser(); + Assert.assertEquals(sg.getImpersonateSubuser(), null); + } } diff --git a/src/test/java/com/sendgrid/TestRequiredFilesExist.java b/src/test/java/com/sendgrid/TestRequiredFilesExist.java new file mode 100644 index 00000000..bb5dd46c --- /dev/null +++ b/src/test/java/com/sendgrid/TestRequiredFilesExist.java @@ -0,0 +1,94 @@ +package com.sendgrid; + +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertTrue; + +public class TestRequiredFilesExist { + + // ./Docker or docker/Docker + @Test public void checkDockerExists() { + boolean dockerExists = new File("./Dockerfile").exists() || + new File("./docker/Dockerfile").exists(); + assertTrue(dockerExists); + } + + // // ./docker-compose.yml or ./docker/docker-compose.yml + // @Test public void checkDockerComposeExists() { + // boolean dockerComposeExists = new File("./docker-compose.yml").exists() || + // new File("./docker/docker-compose.yml").exists(); + // assertTrue(dockerComposeExists); + // } + + // ./.env_sample + @Test public void checkEnvSampleExists() { + assertTrue(new File("./.env_sample").exists()); + } + + // ./.gitignore + @Test public void checkGitIgnoreExists() { + assertTrue(new File("./.gitignore").exists()); + } + + // ./.travis.yml + @Test public void checkTravisExists() { + assertTrue(new File("./.travis.yml").exists()); + } + + // ./.codeclimate.yml + @Test public void checkCodeClimateExists() { + assertTrue(new File("./.codeclimate.yml").exists()); + } + + // ./CHANGELOG.md + @Test public void checkChangelogExists() { + assertTrue(new File("./CHANGELOG.md").exists()); + } + + // ./CODE_OF_CONDUCT.md + @Test public void checkCodeOfConductExists() { + assertTrue(new File("./CODE_OF_CONDUCT.md").exists()); + } + + // ./CONTRIBUTING.md + @Test public void checkContributingGuideExists() { + assertTrue(new File("./CONTRIBUTING.md").exists()); + } + + // ./ISSUE_TEMPLATE.md + @Test public void checkIssuesTemplateExists() { + assertTrue(new File("./ISSUE_TEMPLATE.md").exists()); + } + + // ./LICENSE.md + @Test public void checkLicenseExists() { + assertTrue(new File("./LICENSE.md").exists()); + } + + // ./PULL_REQUEST_TEMPLATE.md + @Test public void checkPullRequestExists() { + assertTrue(new File("./PULL_REQUEST_TEMPLATE.md").exists()); + } + + // ./README.md + @Test public void checkReadMeExists() { + assertTrue(new File("./README.md").exists()); + } + + // ./TROUBLESHOOTING.md + @Test public void checkTroubleShootingGuideExists() { + assertTrue(new File("./TROUBLESHOOTING.md").exists()); + } + + // ./USAGE.md + @Test public void checkUsageGuideExists() { + assertTrue(new File("./USAGE.md").exists()); + } + + // ./USE_CASES.md + @Test public void checkUseCases() { + assertTrue(new File("./USE_CASES.md").exists()); + } +} diff --git a/src/test/java/com/sendgrid/TwilioEmailTest.java b/src/test/java/com/sendgrid/TwilioEmailTest.java new file mode 100644 index 00000000..e07c2ca5 --- /dev/null +++ b/src/test/java/com/sendgrid/TwilioEmailTest.java @@ -0,0 +1,29 @@ +package com.sendgrid; + +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +public class TwilioEmailTest { + + @Test + public void testInitialization() { + final TwilioEmail sg = new TwilioEmail("username", "password"); + Assert.assertEquals("email.twilio.com", sg.getHost()); + Assert.assertEquals("Basic dXNlcm5hbWU6cGFzc3dvcmQ=", sg.getRequestHeaders().get("Authorization")); + } + + @Test + public void testConstructWithClient() throws IOException { + final Client client = mock(Client.class); + final TwilioEmail sg = new TwilioEmail("username", "password", client); + final Request request = new Request(); + + sg.makeCall(request); + verify(client).api(request); + } +} diff --git a/src/test/java/com/sendgrid/helpers/AttachmentBuilderTest.java b/src/test/java/com/sendgrid/helpers/AttachmentBuilderTest.java new file mode 100644 index 00000000..3ea3f379 --- /dev/null +++ b/src/test/java/com/sendgrid/helpers/AttachmentBuilderTest.java @@ -0,0 +1,49 @@ +package com.sendgrid.helpers; + +import com.sendgrid.helpers.mail.objects.Attachments; +import org.apache.commons.codec.binary.Base64; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.nio.charset.Charset; + +public class AttachmentBuilderTest { + + @Test + public void testCreateAttachments() { + String fileName = "book.txt"; + String type = "text/plain"; + String content = "This test checks if the builder works fine"; + InputStream contentStream = new ByteArrayInputStream(content.getBytes(Charset.forName("UTF-8"))); + String contentId = "someId"; + String dispositon = "someDisposition"; + + Attachments attachments = new Attachments.Builder(fileName, contentStream) + .withType(type) + .withContentId(contentId) + .withDisposition(dispositon) + .build(); + + Assert.assertEquals(attachments.getType(), type); + Assert.assertEquals(attachments.getFilename(), fileName); + Assert.assertEquals(attachments.getContentId(), contentId); + Assert.assertEquals(attachments.getDisposition(), dispositon); + Assert.assertEquals(attachments.getContent(), Base64.encodeBase64String(content.getBytes(Charset.forName("UTF-8")))); + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateAttachmentsMissingRequiredFileNameParam() { + String content = "This test checks if the builder works fine"; + InputStream contentStream = new ByteArrayInputStream(content.getBytes(Charset.forName("UTF-8"))); + Attachments attachments = new Attachments.Builder(null, contentStream).build(); + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateAttachmentsMissingRequiredContentParam() { + String type = "text"; + String content = null; + Attachments attachments = new Attachments.Builder(type, content).build(); + } +} diff --git a/src/test/java/com/sendgrid/helpers/MailTest.java b/src/test/java/com/sendgrid/helpers/MailTest.java new file mode 100644 index 00000000..bc49a197 --- /dev/null +++ b/src/test/java/com/sendgrid/helpers/MailTest.java @@ -0,0 +1,275 @@ +package com.sendgrid.helpers; + +import com.sendgrid.helpers.mail.Mail; +import com.sendgrid.helpers.mail.objects.*; +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import java.io.IOException; + +public class MailTest { + + @Test + public void testHelloWorld() throws IOException { + Email from = new Email("test@example.com"); + String subject = "Sending with SendGrid is Fun"; + Email to = new Email("test@example.com"); + Content content = new Content("text/plain", "and easy to do anywhere, even with Java"); + Mail mail = new Mail(from, subject, to, content); + + Assert.assertEquals(mail.build(), "{\"from\":{\"email\":\"test@example.com\"},\"subject\":\"Sending with SendGrid is Fun\",\"personalizations\":[{\"to\":[{\"email\":\"test@example.com\"}]}],\"content\":[{\"type\":\"text/plain\",\"value\":\"and easy to do anywhere, even with Java\"}]}"); + } + + @Test + public void testKitchenSink() throws IOException { + Mail mail = new Mail(); + + Email fromEmail = new Email(); + fromEmail.setName("Example User"); + fromEmail.setEmail("test@example.com"); + mail.setFrom(fromEmail); + + mail.setSubject("Hello World from the SendGrid Java Library"); + + Personalization personalization = new Personalization(); + Email to = new Email(); + to.setName("Example User"); + to.setEmail("test@example.com"); + personalization.addTo(to); + to.setName("Example User"); + to.setEmail("test@example.com"); + personalization.addTo(to); + Email cc = new Email(); + cc.setName("Example User"); + cc.setEmail("test@example.com"); + personalization.addCc(cc); + cc.setName("Example User"); + cc.setEmail("test@example.com"); + personalization.addCc(cc); + Email bcc = new Email(); + bcc.setName("Example User"); + bcc.setEmail("test@example.com"); + personalization.addBcc(bcc); + bcc.setName("Example User"); + bcc.setEmail("test@example.com"); + personalization.addBcc(bcc); + personalization.setSubject("Hello World from the Personalized SendGrid Java Library"); + personalization.addHeader("X-Test", "test"); + personalization.addHeader("X-Mock", "true"); + personalization.addSubstitution("%name%", "Example User"); + personalization.addSubstitution("%city%", "Denver"); + personalization.addCustomArg("user_id", "343"); + personalization.addCustomArg("type", "marketing"); + personalization.setSendAt(1443636843); + mail.addPersonalization(personalization); + + Personalization personalization2 = new Personalization(); + Email to2 = new Email(); + to2.setName("Example User"); + to2.setEmail("test@example.com"); + personalization2.addTo(to2); + to2.setName("Example User"); + to2.setEmail("test@example.com"); + personalization2.addTo(to2); + Email cc2 = new Email(); + cc2.setName("Example User"); + cc2.setEmail("test@example.com"); + personalization2.addCc(cc2); + cc2.setName("Example User"); + cc2.setEmail("test@example.com"); + personalization2.addCc(cc2); + Email bcc2 = new Email(); + bcc2.setName("Example User"); + bcc2.setEmail("test@example.com"); + personalization2.addBcc(bcc2); + bcc2.setName("Example User"); + bcc2.setEmail("test@example.com"); + personalization2.addBcc(bcc2); + personalization2.setSubject("Hello World from the Personalized SendGrid Java Library"); + personalization2.addHeader("X-Test", "test"); + personalization2.addHeader("X-Mock", "true"); + personalization2.addSubstitution("%name%", "Example User"); + personalization2.addSubstitution("%city%", "Denver"); + personalization2.addCustomArg("user_id", "343"); + personalization2.addCustomArg("type", "marketing"); + personalization2.setSendAt(1443636843); + mail.addPersonalization(personalization2); + + Personalization personalization3 = new Personalization(); + Email to3 = new Email(); + to3.setName("Example User"); + to3.setEmail("test@example.com"); + personalization3.addTo(to3); + to3.setName("Example User"); + to3.setEmail("test@example.com"); + personalization3.addTo(to3); + Email cc3 = new Email(); + cc3.setName("Example User"); + cc3.setEmail("test@example.com"); + personalization3.addCc(cc3); + cc3.setName("Example User"); + cc3.setEmail("test@example.com"); + personalization3.addCc(cc3); + Email bcc3 = new Email(); + bcc3.setName("Example User"); + bcc3.setEmail("test@example.com"); + personalization3.addBcc(bcc3); + bcc3.setName("Example User"); + bcc3.setEmail("test@example.com"); + personalization3.addBcc(bcc3); + personalization3.setSubject("Hello World from the Personalized SendGrid Java Library"); + personalization3.addHeader("X-Test", "test"); + personalization3.addHeader("X-Mock", "true"); + List