diff --git a/README.md b/README.md
index 3fd361a..7f017ea 100644
--- a/README.md
+++ b/README.md
@@ -162,6 +162,8 @@ MailerSend Java SDK
- [Create a blocklist monitor](#create-a-blocklist-monitor)
- [Update a blocklist monitor](#update-a-blocklist-monitor)
- [Delete a blocklist monitor](#delete-a-blocklist-monitor)
+ - [Account](#account)
+ - [Get account](#get-account)
- [WhatsApp](#whatsapp)
- [Send a WhatsApp message](#send-a-whatsapp-message)
@@ -4795,6 +4797,42 @@ public void deleteInvite() {
}
```
+## Account
+
+### Get account
+
+Returns the plan, usage, API rate limits and resource limits of the account the API token belongs to. A `limit` of `-1` means unlimited. `addons.whatsapp` is `null` when the account has no WhatsApp add-on, and `resources.webhooks.limit` can be `null`.
+
+```java
+import com.mailersend.sdk.MailerSend;
+import com.mailersend.sdk.account.AccountDetails;
+import com.mailersend.sdk.exceptions.MailerSendException;
+
+public void getAccount() {
+
+ MailerSend ms = new MailerSend();
+ ms.setToken("Your API token");
+
+ try {
+
+ AccountDetails account = ms.account().getAccount();
+
+ System.out.println(account.name);
+ System.out.println(account.status);
+ System.out.println(account.planType);
+ System.out.println(account.emails.sent);
+ System.out.println(account.emails.limit);
+ System.out.println(account.rateLimits.general);
+ System.out.println(account.resources.domains.used);
+ System.out.println(account.resources.domains.limit);
+
+ } catch (MailerSendException e) {
+
+ e.printStackTrace();
+ }
+}
+```
+
# WhatsApp
`from` takes a connected WhatsApp sender, either as its phone number in E.164 format or as its MailerSend sender ID. A sender connected with a Meta virtual number has no phone number, so it can only be addressed by its sender ID. Recipients are phone numbers in E.164 format, or a BSUID taken from an inbound message. Sending requires a token with the `whatsapp_full` scope.
diff --git a/src/main/java/com/mailersend/sdk/MailerSend.java b/src/main/java/com/mailersend/sdk/MailerSend.java
index 25017ff..109d304 100644
--- a/src/main/java/com/mailersend/sdk/MailerSend.java
+++ b/src/main/java/com/mailersend/sdk/MailerSend.java
@@ -7,6 +7,7 @@
**************************************************/
package com.mailersend.sdk;
+import com.mailersend.sdk.account.Account;
import com.mailersend.sdk.activities.Activities;
import com.mailersend.sdk.analytics.Analytics;
import com.mailersend.sdk.domains.Domains;
@@ -56,6 +57,7 @@ public class MailerSend {
private SmtpUsers smtpUsers = null;
private SenderIdentities senderIdentities = null;
private Users users = null;
+ private Account account = null;
/**
*
Constructor for MailerSend.
@@ -81,6 +83,7 @@ public MailerSend() {
smtpUsers = new SmtpUsers(this);
senderIdentities = new SenderIdentities(this);
users = new Users(this);
+ account = new Account(this);
}
@@ -275,6 +278,15 @@ public Users users() {
return users;
}
+ /**
+ * Get the account access object
+ *
+ * @return the Account object
+ */
+ public Account account() {
+ return account;
+ }
+
/**
* Sets the MailerSend token
*
diff --git a/src/main/java/com/mailersend/sdk/account/Account.java b/src/main/java/com/mailersend/sdk/account/Account.java
new file mode 100644
index 0000000..629b433
--- /dev/null
+++ b/src/main/java/com/mailersend/sdk/account/Account.java
@@ -0,0 +1,50 @@
+/*************************************************
+ * MailerSend Java SDK
+ * https://github.com/mailersend/mailersend-java
+ *
+ * @author MailerSend
+ * https://mailersend.com
+ **************************************************/
+package com.mailersend.sdk.account;
+
+import com.mailersend.sdk.MailerSend;
+import com.mailersend.sdk.MailerSendApi;
+import com.mailersend.sdk.exceptions.MailerSendException;
+
+/**
+ * Provides access to the Account endpoint of the MailerSend API.
+ *
+ * Do not instantiate directly — access via {@code MailerSend.account()}.
+ */
+public class Account {
+
+ private final MailerSend apiObjectReference;
+
+
+ /**
+ * Do not initialize directly. This should only be accessed from MailerSend.account().
+ *
+ * @param apiObjectRef a {@link com.mailersend.sdk.MailerSend} object.
+ */
+ public Account(MailerSend apiObjectRef) {
+
+ apiObjectReference = apiObjectRef;
+ }
+
+
+ /**
+ * Gets the plan, usage, rate limits and resource limits of the account the API token belongs to.
+ *
+ * @throws com.mailersend.sdk.exceptions.MailerSendException
+ * @return an {@link AccountDetails} object
+ */
+ public AccountDetails getAccount() throws MailerSendException {
+
+ MailerSendApi api = new MailerSendApi();
+ api.setToken(apiObjectReference.getToken());
+
+ AccountResponse response = api.getRequest("/account", AccountResponse.class);
+
+ return response.account;
+ }
+}
diff --git a/src/main/java/com/mailersend/sdk/account/AccountAddons.java b/src/main/java/com/mailersend/sdk/account/AccountAddons.java
new file mode 100644
index 0000000..e3d6eb2
--- /dev/null
+++ b/src/main/java/com/mailersend/sdk/account/AccountAddons.java
@@ -0,0 +1,37 @@
+/*************************************************
+ * MailerSend Java SDK
+ * https://github.com/mailersend/mailersend-java
+ *
+ * @author MailerSend
+ * https://mailersend.com
+ **************************************************/
+package com.mailersend.sdk.account;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * Add-ons of the account.
+ */
+public class AccountAddons {
+
+ @SerializedName("sms")
+ public AccountUsage sms;
+
+ /**
+ * {@code null} when the account has no WhatsApp add-on.
+ */
+ @SerializedName("whatsapp")
+ public AccountWhatsAppUsage whatsapp;
+
+ @SerializedName("phone_numbers")
+ public int phoneNumbers;
+
+ @SerializedName("domain_spaces")
+ public int domainSpaces;
+
+ @SerializedName("data_retention_days")
+ public int dataRetentionDays;
+
+ @SerializedName("dedicated_ips")
+ public int dedicatedIps;
+}
diff --git a/src/main/java/com/mailersend/sdk/account/AccountDetails.java b/src/main/java/com/mailersend/sdk/account/AccountDetails.java
new file mode 100644
index 0000000..2301a9c
--- /dev/null
+++ b/src/main/java/com/mailersend/sdk/account/AccountDetails.java
@@ -0,0 +1,43 @@
+/*************************************************
+ * MailerSend Java SDK
+ * https://github.com/mailersend/mailersend-java
+ *
+ * @author MailerSend
+ * https://mailersend.com
+ **************************************************/
+package com.mailersend.sdk.account;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * Represents the account the API token belongs to.
+ */
+public class AccountDetails {
+
+ @SerializedName("name")
+ public String name;
+
+ /**
+ * One of {@code pending}, {@code approved}, {@code rejected} or {@code suspended}.
+ */
+ @SerializedName("status")
+ public String status;
+
+ @SerializedName("plan_type")
+ public String planType;
+
+ @SerializedName("data_retention_days")
+ public int dataRetentionDays;
+
+ @SerializedName("emails")
+ public AccountUsage emails;
+
+ @SerializedName("rate_limits")
+ public AccountRateLimits rateLimits;
+
+ @SerializedName("resources")
+ public AccountResources resources;
+
+ @SerializedName("addons")
+ public AccountAddons addons;
+}
diff --git a/src/main/java/com/mailersend/sdk/account/AccountRateLimits.java b/src/main/java/com/mailersend/sdk/account/AccountRateLimits.java
new file mode 100644
index 0000000..6e550ed
--- /dev/null
+++ b/src/main/java/com/mailersend/sdk/account/AccountRateLimits.java
@@ -0,0 +1,28 @@
+/*************************************************
+ * MailerSend Java SDK
+ * https://github.com/mailersend/mailersend-java
+ *
+ * @author MailerSend
+ * https://mailersend.com
+ **************************************************/
+package com.mailersend.sdk.account;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * API rate limits of the account, in requests per minute.
+ */
+public class AccountRateLimits {
+
+ @SerializedName("general")
+ public int general;
+
+ @SerializedName("email")
+ public int email;
+
+ @SerializedName("bulk_email")
+ public int bulkEmail;
+
+ @SerializedName("activity")
+ public int activity;
+}
diff --git a/src/main/java/com/mailersend/sdk/account/AccountResourceUsage.java b/src/main/java/com/mailersend/sdk/account/AccountResourceUsage.java
new file mode 100644
index 0000000..73a77c3
--- /dev/null
+++ b/src/main/java/com/mailersend/sdk/account/AccountResourceUsage.java
@@ -0,0 +1,23 @@
+/*************************************************
+ * MailerSend Java SDK
+ * https://github.com/mailersend/mailersend-java
+ *
+ * @author MailerSend
+ * https://mailersend.com
+ **************************************************/
+package com.mailersend.sdk.account;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * How many of a resource the account uses, against how many its plan allows.
+ * The limit can be {@code null}.
+ */
+public class AccountResourceUsage {
+
+ @SerializedName("used")
+ public int used;
+
+ @SerializedName("limit")
+ public Integer limit;
+}
diff --git a/src/main/java/com/mailersend/sdk/account/AccountResources.java b/src/main/java/com/mailersend/sdk/account/AccountResources.java
new file mode 100644
index 0000000..b6dffaa
--- /dev/null
+++ b/src/main/java/com/mailersend/sdk/account/AccountResources.java
@@ -0,0 +1,37 @@
+/*************************************************
+ * MailerSend Java SDK
+ * https://github.com/mailersend/mailersend-java
+ *
+ * @author MailerSend
+ * https://mailersend.com
+ **************************************************/
+package com.mailersend.sdk.account;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * Resource usage and limits of the account.
+ */
+public class AccountResources {
+
+ @SerializedName("domains")
+ public AccountResourceUsage domains;
+
+ @SerializedName("users")
+ public AccountResourceUsage users;
+
+ @SerializedName("free_accountant_seat")
+ public AccountResourceUsage freeAccountantSeat;
+
+ @SerializedName("templates")
+ public AccountResourceUsage templates;
+
+ @SerializedName("smtp_users")
+ public AccountResourceUsage smtpUsers;
+
+ @SerializedName("api_tokens")
+ public AccountResourceUsage apiTokens;
+
+ @SerializedName("webhooks")
+ public AccountResourceUsage webhooks;
+}
diff --git a/src/main/java/com/mailersend/sdk/account/AccountResponse.java b/src/main/java/com/mailersend/sdk/account/AccountResponse.java
new file mode 100644
index 0000000..67513ca
--- /dev/null
+++ b/src/main/java/com/mailersend/sdk/account/AccountResponse.java
@@ -0,0 +1,20 @@
+/*************************************************
+ * MailerSend Java SDK
+ * https://github.com/mailersend/mailersend-java
+ *
+ * @author MailerSend
+ * https://mailersend.com
+ **************************************************/
+package com.mailersend.sdk.account;
+
+import com.google.gson.annotations.SerializedName;
+import com.mailersend.sdk.MailerSendResponse;
+
+/**
+ * Wraps the account response from the API.
+ */
+public class AccountResponse extends MailerSendResponse {
+
+ @SerializedName("data")
+ public AccountDetails account;
+}
diff --git a/src/main/java/com/mailersend/sdk/account/AccountUsage.java b/src/main/java/com/mailersend/sdk/account/AccountUsage.java
new file mode 100644
index 0000000..c342785
--- /dev/null
+++ b/src/main/java/com/mailersend/sdk/account/AccountUsage.java
@@ -0,0 +1,25 @@
+/*************************************************
+ * MailerSend Java SDK
+ * https://github.com/mailersend/mailersend-java
+ *
+ * @author MailerSend
+ * https://mailersend.com
+ **************************************************/
+package com.mailersend.sdk.account;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * Sent and received messages in the current usage cycle, against the limit in force.
+ */
+public class AccountUsage {
+
+ @SerializedName("sent")
+ public int sent;
+
+ @SerializedName("received")
+ public int received;
+
+ @SerializedName("limit")
+ public int limit;
+}
diff --git a/src/main/java/com/mailersend/sdk/account/AccountWhatsAppUsage.java b/src/main/java/com/mailersend/sdk/account/AccountWhatsAppUsage.java
new file mode 100644
index 0000000..85bdaf1
--- /dev/null
+++ b/src/main/java/com/mailersend/sdk/account/AccountWhatsAppUsage.java
@@ -0,0 +1,22 @@
+/*************************************************
+ * MailerSend Java SDK
+ * https://github.com/mailersend/mailersend-java
+ *
+ * @author MailerSend
+ * https://mailersend.com
+ **************************************************/
+package com.mailersend.sdk.account;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * WhatsApp messages sent in the add-on cycle, against the messages the add-on includes.
+ */
+public class AccountWhatsAppUsage {
+
+ @SerializedName("sent")
+ public int sent;
+
+ @SerializedName("limit")
+ public int limit;
+}
diff --git a/src/test/java/com/mailersend/sdk/tests/AccountTest.java b/src/test/java/com/mailersend/sdk/tests/AccountTest.java
new file mode 100644
index 0000000..945bb09
--- /dev/null
+++ b/src/test/java/com/mailersend/sdk/tests/AccountTest.java
@@ -0,0 +1,162 @@
+/*************************************************
+ * MailerSend Java SDK
+ * https://github.com/mailersend/mailersend-java
+ *
+ * @author MailerSend
+ * https://mailersend.com
+ **************************************************/
+package com.mailersend.sdk.tests;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+
+import com.mailersend.sdk.MailerSend;
+import com.mailersend.sdk.account.AccountDetails;
+import com.mailersend.sdk.exceptions.MailerSendException;
+import com.mailersend.sdk.vcr.VcrRecorder;
+
+public class AccountTest {
+
+ private static final String ACCOUNT_RESPONSE = CapturingHttpClient.json("{'data':{"
+ + "'name':'Acme Inc','status':'approved','plan_type':'starter','data_retention_days':7,"
+ + "'emails':{'sent':12000,'received':430,'limit':-1},"
+ + "'rate_limits':{'general':60,'email':120,'bulk_email':10,'activity':10},"
+ + "'resources':{"
+ + "'domains':{'used':3,'limit':10},'users':{'used':2,'limit':5},"
+ + "'free_accountant_seat':{'used':0,'limit':0},'templates':{'used':41,'limit':250},"
+ + "'smtp_users':{'used':1,'limit':50},'api_tokens':{'used':4,'limit':50},"
+ + "'webhooks':{'used':2,'limit':50}},"
+ + "'addons':{"
+ + "'sms':{'sent':120,'received':30,'limit':-1},'whatsapp':{'sent':800,'limit':1000},"
+ + "'phone_numbers':1,'domain_spaces':2,'data_retention_days':30,'dedicated_ips':0}"
+ + "}}").toString();
+
+ @BeforeEach
+ public void setupEach(TestInfo info) throws IOException {
+ VcrRecorder.useRecording("AccountTest_" + info.getDisplayName());
+ }
+
+ @AfterEach
+ public void afterEach() throws IOException {
+ VcrRecorder.stopRecording();
+ }
+
+
+ /**
+ * Test that the account is requested with GET /account
+ */
+ @Test
+ public void testGetAccountRequest() throws MailerSendException {
+
+ MailerSend ms = new MailerSend();
+ ms.setToken(TestHelper.validToken);
+
+ CapturingHttpClient client = CapturingHttpClient.install(200, ACCOUNT_RESPONSE);
+
+ ms.account().getAccount();
+
+ assertEquals("GET", client.lastRequest().method());
+ assertEquals("https://api.mailersend.com/v1/account", client.lastUrl());
+ assertEquals("Bearer " + TestHelper.validToken, client.lastRequest().headers().firstValue("Authorization").orElse(null));
+ }
+
+
+ /**
+ * Test that the whole account response is read
+ */
+ @Test
+ public void testGetAccountReadsTheResponse() throws MailerSendException {
+
+ MailerSend ms = new MailerSend();
+ ms.setToken(TestHelper.validToken);
+
+ CapturingHttpClient.install(200, ACCOUNT_RESPONSE);
+
+ AccountDetails account = ms.account().getAccount();
+
+ assertEquals("Acme Inc", account.name);
+ assertEquals("approved", account.status);
+ assertEquals("starter", account.planType);
+ assertEquals(7, account.dataRetentionDays);
+
+ assertEquals(12000, account.emails.sent);
+ assertEquals(430, account.emails.received);
+ assertEquals(-1, account.emails.limit);
+
+ assertEquals(60, account.rateLimits.general);
+ assertEquals(120, account.rateLimits.email);
+ assertEquals(10, account.rateLimits.bulkEmail);
+ assertEquals(10, account.rateLimits.activity);
+
+ assertEquals(3, account.resources.domains.used);
+ assertEquals(10, account.resources.domains.limit);
+ assertEquals(2, account.resources.users.used);
+ assertEquals(5, account.resources.users.limit);
+ assertEquals(0, account.resources.freeAccountantSeat.used);
+ assertEquals(0, account.resources.freeAccountantSeat.limit);
+ assertEquals(41, account.resources.templates.used);
+ assertEquals(250, account.resources.templates.limit);
+ assertEquals(1, account.resources.smtpUsers.used);
+ assertEquals(50, account.resources.smtpUsers.limit);
+ assertEquals(4, account.resources.apiTokens.used);
+ assertEquals(50, account.resources.apiTokens.limit);
+ assertEquals(2, account.resources.webhooks.used);
+ assertEquals(50, account.resources.webhooks.limit);
+
+ assertEquals(120, account.addons.sms.sent);
+ assertEquals(30, account.addons.sms.received);
+ assertEquals(-1, account.addons.sms.limit);
+ assertEquals(800, account.addons.whatsapp.sent);
+ assertEquals(1000, account.addons.whatsapp.limit);
+ assertEquals(1, account.addons.phoneNumbers);
+ assertEquals(2, account.addons.domainSpaces);
+ assertEquals(30, account.addons.dataRetentionDays);
+ assertEquals(0, account.addons.dedicatedIps);
+ }
+
+
+ /**
+ * Test that a missing WhatsApp add-on and an unset webhooks limit are read as null
+ */
+ @Test
+ public void testGetAccountReadsNullValues() throws MailerSendException {
+
+ MailerSend ms = new MailerSend();
+ ms.setToken(TestHelper.validToken);
+
+ CapturingHttpClient.install(200, ACCOUNT_RESPONSE
+ .replace("\"whatsapp\":{\"sent\":800,\"limit\":1000}", "\"whatsapp\":null")
+ .replace("\"webhooks\":{\"used\":2,\"limit\":50}", "\"webhooks\":{\"used\":2,\"limit\":null}"));
+
+ AccountDetails account = ms.account().getAccount();
+
+ assertNull(account.addons.whatsapp);
+ assertNull(account.resources.webhooks.limit);
+ assertEquals(2, account.resources.webhooks.used);
+ }
+
+
+ /**
+ * Test that an invalid token fails with a 401
+ */
+ @Test
+ public void testGetAccountWithInvalidTokenFails() {
+
+ MailerSend ms = new MailerSend();
+ ms.setToken(TestHelper.invalidToken);
+
+ CapturingHttpClient.install(401, "{\"message\":\"Unauthenticated.\"}");
+
+ MailerSendException ex = assertThrows(MailerSendException.class, () -> ms.account().getAccount());
+
+ assertEquals(401, ex.code);
+ }
+}