From c7bf8195a72ac17d43c76e7973752a66945519d8 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Mon, 2 Feb 2026 15:22:21 -0700 Subject: [PATCH 1/3] feat: create/delete/enable/disable API keys --- CHANGELOG.md | 8 + pom.xml | 2 +- src/main/java/com/easypost/model/ApiKey.java | 1 + .../com/easypost/service/ApiKeyService.java | 78 +++- src/test/cassettes/api_key/api_keys.json | 74 ++-- src/test/cassettes/api_key/lifecycle.json | 349 ++++++++++++++++++ .../api_key/retrieve_child_user_api_keys.json | 343 +++++++++++++++++ src/test/java/com/easypost/ApiKeyTest.java | 76 ++-- 8 files changed, 859 insertions(+), 72 deletions(-) create mode 100644 src/test/cassettes/api_key/lifecycle.json create mode 100644 src/test/cassettes/api_key/retrieve_child_user_api_keys.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 09824dbfa..c5cd3c90a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # CHANGELOG +## v8.6.0 (2026-02-03) + +- Adds the following functions usable by child and referral customer users: + - `apiKey.create` + - `apiKey.delete` + - `apiKey.enable` + - `apiKey.disable` + ## v8.5.1 (2026-01-08) - Corrects `StatelessRateDeserializer` and `WebhookDeserializer` to treat all camelCase fields like all other models to properly deserialize JSON fields containing underscors diff --git a/pom.xml b/pom.xml index 710fe76a3..643345c3b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.easypost easypost-api-client - 8.5.1 + 8.6.0 jar com.easypost:easypost-api-client diff --git a/src/main/java/com/easypost/model/ApiKey.java b/src/main/java/com/easypost/model/ApiKey.java index 9377f38d1..f02f808c2 100644 --- a/src/main/java/com/easypost/model/ApiKey.java +++ b/src/main/java/com/easypost/model/ApiKey.java @@ -5,4 +5,5 @@ @Getter public final class ApiKey extends EasyPostResource { private String key; + private Boolean active; } diff --git a/src/main/java/com/easypost/service/ApiKeyService.java b/src/main/java/com/easypost/service/ApiKeyService.java index c18464e8e..20ca357a3 100644 --- a/src/main/java/com/easypost/service/ApiKeyService.java +++ b/src/main/java/com/easypost/service/ApiKeyService.java @@ -23,18 +23,6 @@ public class ApiKeyService { this.client = client; } - /** - * Get all API keys. - * - * @return ApiKeys object. - * @throws EasyPostException when the request fails. - */ - public ApiKeys all() throws EasyPostException { - String endpoint = "api_keys"; - - return Requestor.request(RequestMethod.GET, endpoint, null, ApiKeys.class, client); - } - /** * Get this User's API keys. * @@ -57,4 +45,70 @@ public List retrieveApiKeysForUser(final String id) throws EasyPostExcep throw new FilteringError(String.format(Constants.ErrorMessages.NO_OBJECT_FOUND, "API keys")); } + + /** + * Get all API keys. + * + * @return ApiKeys object. + * @throws EasyPostException when the request fails. + */ + public ApiKeys all() throws EasyPostException { + String endpoint = "api_keys"; + + return Requestor.request(RequestMethod.GET, endpoint, null, ApiKeys.class, client); + } + + /** + * Create an API key for a child or referral customer user. + * + * @param mode The mode of the API key (production or test). + * @return ApiKey object. + * @throws EasyPostException when the request fails. + */ + public ApiKey create(final String mode) throws EasyPostException { + String endpoint = "api_keys"; + + java.util.Map params = new java.util.HashMap<>(); + params.put("mode", mode); + + return Requestor.request(RequestMethod.POST, endpoint, params, ApiKey.class, client); + } + + /** + * Delete an API key for a child or referral customer user. + * + * @param id The ID of the API key to delete. + * @throws EasyPostException when the request fails. + */ + public void delete(final String id) throws EasyPostException { + String endpoint = String.format("api_keys/%s", id); + + Requestor.request(RequestMethod.DELETE, endpoint, null, ApiKey.class, client); + } + + /** + * Enable a child or referral customer API key. + * + * @param id The ID of the API key to enable. + * @return ApiKey object. + * @throws EasyPostException when the request fails. + */ + public ApiKey enable(final String id) throws EasyPostException { + String endpoint = String.format("api_keys/%s/enable", id); + + return Requestor.request(RequestMethod.POST, endpoint, null, ApiKey.class, client); + } + + /** + * Disable a child or referral customer API key. + * + * @param id The ID of the API key to disable. + * @return ApiKey object. + * @throws EasyPostException when the request fails. + */ + public ApiKey disable(final String id) throws EasyPostException { + String endpoint = String.format("api_keys/%s/disable", id); + + return Requestor.request(RequestMethod.POST, endpoint, null, ApiKey.class, client); + } } diff --git a/src/test/cassettes/api_key/api_keys.json b/src/test/cassettes/api_key/api_keys.json index 15e43e09a..61e64abf1 100644 --- a/src/test/cassettes/api_key/api_keys.json +++ b/src/test/cassettes/api_key/api_keys.json @@ -1,6 +1,6 @@ [ { - "recordedAt": 1723823854, + "recordedAt": 1770070890, "request": { "body": "{\n \"user\": {\n \"name\": \"Test User\"\n }\n}", "method": "POST", @@ -18,7 +18,7 @@ "uri": "https://api.easypost.com/v2/users" }, "response": { - "body": "{\n \"children\": [],\n \"parent_id\": \"user_04ad194774a54f6c97d1385715721091\",\n \"name\": \"Test User\",\n \"verified\": true,\n \"created_at\": \"2024-08-16T15:57:34Z\",\n \"default_carbon_offset\": false,\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_be3e8e064b094079b60311d3b310f738\",\n \"api_keys\": [],\n \"has_elevate_access\": false,\n \"object\": \"User\"\n}", + "body": "{\n \"children\": [],\n \"parent_id\": \"user_04ad194774a54f6c97d1385715721091\",\n \"name\": \"Test User\",\n \"verified\": true,\n \"created_at\": \"2026-02-02T22:21:30Z\",\n \"default_carbon_offset\": false,\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_ff4fd488b4e545c98a14a4caa598b41e\",\n \"api_keys\": [],\n \"has_elevate_access\": false,\n \"object\": \"User\"\n}", "httpVersion": null, "headers": { "null": [ @@ -58,23 +58,23 @@ "nosniff" ], "x-ep-request-uuid": [ - "8a4bf43d66bf76eee786bca40035c092" + "2e56ccec6981236ae2bcd1da02e3ef84" ], "x-proxied": [ - "intlb4nuq c0f5e722d1", - "extlb1nuq b6e1b5034c" + "intlb5nuq d9379ca146", + "extlb2nuq cbbd141214" ], "referrer-policy": [ "strict-origin-when-cross-origin" ], "x-runtime": [ - "0.554784" + "0.456456" ], "content-type": [ "application/json; charset\u003dutf-8" ], "x-version-label": [ - "easypost-202408152333-48cda4a73e-master" + "easypost-202602022023-e2aafa4ad5-master" ], "cache-control": [ "private, no-cache, no-store" @@ -86,10 +86,10 @@ }, "uri": "https://api.easypost.com/v2/users" }, - "duration": 771 + "duration": 571 }, { - "recordedAt": 1723823855, + "recordedAt": 1770070890, "request": { "body": "", "method": "GET", @@ -104,7 +104,7 @@ "uri": "https://api.easypost.com/v2/api_keys" }, "response": { - "body": "{\n \"children\": [\n {\n \"children\": [],\n \"keys\": [],\n \"id\": \"user_af930e9bd27a4445bc2741fac37850cc\"\n },\n {\n \"children\": [],\n \"keys\": [],\n \"id\": \"user_be3e8e064b094079b60311d3b310f738\"\n }\n ],\n \"keys\": [],\n \"id\": \"user_04ad194774a54f6c97d1385715721091\"\n}", + "body": "{\n \"children\": [\n {\n \"children\": [],\n \"keys\": [],\n \"id\": \"user_af930e9bd27a4445bc2741fac37850cc\"\n },\n {\n \"children\": [],\n \"keys\": [],\n \"id\": \"user_ff4fd488b4e545c98a14a4caa598b41e\"\n }\n ],\n \"keys\": [],\n \"id\": \"user_04ad194774a54f6c97d1385715721091\"\n}", "httpVersion": null, "headers": { "null": [ @@ -117,7 +117,7 @@ "0" ], "x-node": [ - "bigweb53nuq" + "bigweb66nuq" ], "x-frame-options": [ "SAMEORIGIN" @@ -144,23 +144,23 @@ "nosniff" ], "x-ep-request-uuid": [ - "8a4bf44066bf76efe786bcbd0035c19d" + "2e56ccf06981236ae2bcd1df02e3f0a2" ], "x-proxied": [ - "intlb4nuq c0f5e722d1", - "extlb1nuq b6e1b5034c" + "intlb5nuq d9379ca146", + "extlb2nuq cbbd141214" ], "referrer-policy": [ "strict-origin-when-cross-origin" ], "x-runtime": [ - "0.082161" + "0.036304" ], "content-type": [ "application/json; charset\u003dutf-8" ], "x-version-label": [ - "easypost-202408152333-48cda4a73e-master" + "easypost-202602022023-e2aafa4ad5-master" ], "cache-control": [ "private, no-cache, no-store" @@ -172,10 +172,10 @@ }, "uri": "https://api.easypost.com/v2/api_keys" }, - "duration": 277 + "duration": 143 }, { - "recordedAt": 1723823855, + "recordedAt": 1770070891, "request": { "body": "", "method": "GET", @@ -187,10 +187,10 @@ "REDACTED" ] }, - "uri": "https://api.easypost.com/v2/users/user_be3e8e064b094079b60311d3b310f738" + "uri": "https://api.easypost.com/v2/users/user_ff4fd488b4e545c98a14a4caa598b41e" }, "response": { - "body": "{\n \"children\": [],\n \"parent_id\": \"user_04ad194774a54f6c97d1385715721091\",\n \"name\": \"Test User\",\n \"verified\": true,\n \"created_at\": \"2024-08-16T15:57:34Z\",\n \"default_carbon_offset\": false,\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_be3e8e064b094079b60311d3b310f738\",\n \"has_elevate_access\": false,\n \"object\": \"User\"\n}", + "body": "{\n \"children\": [],\n \"parent_id\": \"user_04ad194774a54f6c97d1385715721091\",\n \"name\": \"Test User\",\n \"verified\": true,\n \"created_at\": \"2026-02-02T22:21:30Z\",\n \"default_carbon_offset\": false,\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_ff4fd488b4e545c98a14a4caa598b41e\",\n \"has_elevate_access\": false,\n \"object\": \"User\"\n}", "httpVersion": null, "headers": { "null": [ @@ -203,7 +203,7 @@ "0" ], "x-node": [ - "bigweb35nuq" + "bigweb59nuq" ], "x-frame-options": [ "SAMEORIGIN" @@ -230,23 +230,23 @@ "nosniff" ], "x-ep-request-uuid": [ - "8a4bf43f66bf76efe786bcbe0035c1d4" + "2e56cced6981236be2bcd1f702e3f0d9" ], "x-proxied": [ - "intlb4nuq c0f5e722d1", - "extlb1nuq b6e1b5034c" + "intlb3nuq d9379ca146", + "extlb2nuq cbbd141214" ], "referrer-policy": [ "strict-origin-when-cross-origin" ], "x-runtime": [ - "0.241655" + "0.047953" ], "content-type": [ "application/json; charset\u003dutf-8" ], "x-version-label": [ - "easypost-202408152333-48cda4a73e-master" + "easypost-202602022023-e2aafa4ad5-master" ], "cache-control": [ "private, no-cache, no-store" @@ -256,12 +256,12 @@ "code": 200, "message": "OK" }, - "uri": "https://api.easypost.com/v2/users/user_be3e8e064b094079b60311d3b310f738" + "uri": "https://api.easypost.com/v2/users/user_ff4fd488b4e545c98a14a4caa598b41e" }, - "duration": 444 + "duration": 152 }, { - "recordedAt": 1723823856, + "recordedAt": 1770070891, "request": { "body": "", "method": "DELETE", @@ -273,7 +273,7 @@ "REDACTED" ] }, - "uri": "https://api.easypost.com/v2/users/user_be3e8e064b094079b60311d3b310f738" + "uri": "https://api.easypost.com/v2/users/user_ff4fd488b4e545c98a14a4caa598b41e" }, "response": { "body": "", @@ -313,20 +313,20 @@ "nosniff" ], "x-ep-request-uuid": [ - "8a4bf43f66bf76f0e786bcbf0035c241" + "2e56ccef6981236be2bcd1f802e3f120" ], "x-proxied": [ - "intlb4nuq c0f5e722d1", - "extlb1nuq b6e1b5034c" + "intlb3nuq d9379ca146", + "extlb2nuq cbbd141214" ], "referrer-policy": [ "strict-origin-when-cross-origin" ], "x-runtime": [ - "0.137383" + "0.100315" ], "x-version-label": [ - "easypost-202408152333-48cda4a73e-master" + "easypost-202602022023-e2aafa4ad5-master" ], "cache-control": [ "private, no-cache, no-store" @@ -336,8 +336,8 @@ "code": 204, "message": "No Content" }, - "uri": "https://api.easypost.com/v2/users/user_be3e8e064b094079b60311d3b310f738" + "uri": "https://api.easypost.com/v2/users/user_ff4fd488b4e545c98a14a4caa598b41e" }, - "duration": 351 + "duration": 207 } ] \ No newline at end of file diff --git a/src/test/cassettes/api_key/lifecycle.json b/src/test/cassettes/api_key/lifecycle.json new file mode 100644 index 000000000..32de0f860 --- /dev/null +++ b/src/test/cassettes/api_key/lifecycle.json @@ -0,0 +1,349 @@ +[ + { + "recordedAt": 1738528358, + "request": { + "body": "{\n \"mode\": \"production\"\n}", + "method": "POST", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ], + "Content-Type": [ + "application/json" + ] + }, + "uri": "https://api.easypost.com/v2/api_keys" + }, + "response": { + "body": "{\"object\":\"ApiKey\",\"key\":\"REDACTED\",\"mode\":\"production\",\"created_at\":\"2026-02-02T20:32:38Z\",\"active\":true,\"id\":\"ak_2df46e55f8434c3882b40f7c99c8b64f\"}", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 201 Created" + ], + "content-length": [ + "199" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb66nuq" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-download-options": [ + "noopen" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-backend": [ + "easypost" + ], + "pragma": [ + "no-cache" + ], + "strict-transport-security": [ + "max-age=31536000; includeSubDomains; preload" + ], + "x-xss-protection": [ + "1; mode=block" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-ep-request-uuid": [ + "cfd5bd42698109e6e2b988370270e6e6" + ], + "x-proxied": [ + "intlb5nuq d9379ca146", + "extlb1nuq cbbd141214" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.119875" + ], + "content-type": [ + "application/json; charset=utf-8" + ], + "x-version-label": [ + "easypost-202602021944-8c5966c6f9-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 201, + "message": "Created" + }, + "uri": "https://api.easypost.com/v2/api_keys" + }, + "duration": 295 + }, + { + "recordedAt": 1738528359, + "request": { + "body": "", + "method": "POST", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ], + "Content-Type": [ + "application/json" + ] + }, + "uri": "https://api.easypost.com/v2/api_keys/ak_2df46e55f8434c3882b40f7c99c8b64f/disable" + }, + "response": { + "body": "{\"object\":\"ApiKey\",\"key\":\"REDACTED\",\"mode\":\"production\",\"created_at\":\"2026-02-02T20:32:38Z\",\"active\":false,\"id\":\"ak_2df46e55f8434c3882b40f7c99c8b64f\"}", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 200 OK" + ], + "content-length": [ + "200" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb33nuq" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-download-options": [ + "noopen" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-backend": [ + "easypost" + ], + "pragma": [ + "no-cache" + ], + "strict-transport-security": [ + "max-age=31536000; includeSubDomains; preload" + ], + "x-xss-protection": [ + "1; mode=block" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-ep-request-uuid": [ + "cfd5bd41698109e6e2b988380270e748" + ], + "x-proxied": [ + "intlb4nuq d9379ca146", + "extlb1nuq cbbd141214" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.143682" + ], + "content-type": [ + "application/json; charset=utf-8" + ], + "x-version-label": [ + "easypost-202602021944-8c5966c6f9-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "uri": "https://api.easypost.com/v2/api_keys/ak_2df46e55f8434c3882b40f7c99c8b64f/disable" + }, + "duration": 258 + }, + { + "recordedAt": 1738528360, + "request": { + "body": "", + "method": "POST", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ], + "Content-Type": [ + "application/json" + ] + }, + "uri": "https://api.easypost.com/v2/api_keys/ak_2df46e55f8434c3882b40f7c99c8b64f/enable" + }, + "response": { + "body": "{\"object\":\"ApiKey\",\"key\":\"REDACTED\",\"mode\":\"production\",\"created_at\":\"2026-02-02T20:32:38Z\",\"active\":true,\"id\":\"ak_2df46e55f8434c3882b40f7c99c8b64f\"}", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 200 OK" + ], + "content-length": [ + "199" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb42nuq" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-download-options": [ + "noopen" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-backend": [ + "easypost" + ], + "pragma": [ + "no-cache" + ], + "strict-transport-security": [ + "max-age=31536000; includeSubDomains; preload" + ], + "x-xss-protection": [ + "1; mode=block" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-ep-request-uuid": [ + "cfd5bd41698109e6e2b988390270e7ae" + ], + "x-proxied": [ + "intlb5nuq d9379ca146", + "extlb1nuq cbbd141214" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.116097" + ], + "content-type": [ + "application/json; charset=utf-8" + ], + "x-version-label": [ + "easypost-202602021944-8c5966c6f9-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "uri": "https://api.easypost.com/v2/api_keys/ak_2df46e55f8434c3882b40f7c99c8b64f/enable" + }, + "duration": 227 + }, + { + "recordedAt": 1738528361, + "request": { + "body": "", + "method": "DELETE", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ] + }, + "uri": "https://api.easypost.com/v2/api_keys/ak_2df46e55f8434c3882b40f7c99c8b64f" + }, + "response": { + "body": "", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 204 No Content" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb39nuq" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-download-options": [ + "noopen" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-backend": [ + "easypost" + ], + "pragma": [ + "no-cache" + ], + "strict-transport-security": [ + "max-age=31536000; includeSubDomains; preload" + ], + "x-xss-protection": [ + "1; mode=block" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-ep-request-uuid": [ + "cfd5bd44698109e6e2b9883a0270e816" + ], + "x-proxied": [ + "intlb3nuq d9379ca146", + "extlb1nuq cbbd141214" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.259319" + ], + "x-version-label": [ + "easypost-202602021944-8c5966c6f9-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 204, + "message": "No Content" + }, + "uri": "https://api.easypost.com/v2/api_keys/ak_2df46e55f8434c3882b40f7c99c8b64f" + }, + "duration": 359 + } +] diff --git a/src/test/cassettes/api_key/retrieve_child_user_api_keys.json b/src/test/cassettes/api_key/retrieve_child_user_api_keys.json new file mode 100644 index 000000000..15e43e09a --- /dev/null +++ b/src/test/cassettes/api_key/retrieve_child_user_api_keys.json @@ -0,0 +1,343 @@ +[ + { + "recordedAt": 1723823854, + "request": { + "body": "{\n \"user\": {\n \"name\": \"Test User\"\n }\n}", + "method": "POST", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ], + "Content-Type": [ + "application/json" + ] + }, + "uri": "https://api.easypost.com/v2/users" + }, + "response": { + "body": "{\n \"children\": [],\n \"parent_id\": \"user_04ad194774a54f6c97d1385715721091\",\n \"name\": \"Test User\",\n \"verified\": true,\n \"created_at\": \"2024-08-16T15:57:34Z\",\n \"default_carbon_offset\": false,\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_be3e8e064b094079b60311d3b310f738\",\n \"api_keys\": [],\n \"has_elevate_access\": false,\n \"object\": \"User\"\n}", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 201 Created" + ], + "content-length": [ + "691" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb38nuq" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-download-options": [ + "noopen" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-backend": [ + "easypost" + ], + "pragma": [ + "no-cache" + ], + "strict-transport-security": [ + "max-age\u003d31536000; includeSubDomains; preload" + ], + "x-xss-protection": [ + "1; mode\u003dblock" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-ep-request-uuid": [ + "8a4bf43d66bf76eee786bca40035c092" + ], + "x-proxied": [ + "intlb4nuq c0f5e722d1", + "extlb1nuq b6e1b5034c" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.554784" + ], + "content-type": [ + "application/json; charset\u003dutf-8" + ], + "x-version-label": [ + "easypost-202408152333-48cda4a73e-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 201, + "message": "Created" + }, + "uri": "https://api.easypost.com/v2/users" + }, + "duration": 771 + }, + { + "recordedAt": 1723823855, + "request": { + "body": "", + "method": "GET", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ] + }, + "uri": "https://api.easypost.com/v2/api_keys" + }, + "response": { + "body": "{\n \"children\": [\n {\n \"children\": [],\n \"keys\": [],\n \"id\": \"user_af930e9bd27a4445bc2741fac37850cc\"\n },\n {\n \"children\": [],\n \"keys\": [],\n \"id\": \"user_be3e8e064b094079b60311d3b310f738\"\n }\n ],\n \"keys\": [],\n \"id\": \"user_04ad194774a54f6c97d1385715721091\"\n}", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 200 OK" + ], + "content-length": [ + "1390" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb53nuq" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-download-options": [ + "noopen" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-backend": [ + "easypost" + ], + "pragma": [ + "no-cache" + ], + "strict-transport-security": [ + "max-age\u003d31536000; includeSubDomains; preload" + ], + "x-xss-protection": [ + "1; mode\u003dblock" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-ep-request-uuid": [ + "8a4bf44066bf76efe786bcbd0035c19d" + ], + "x-proxied": [ + "intlb4nuq c0f5e722d1", + "extlb1nuq b6e1b5034c" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.082161" + ], + "content-type": [ + "application/json; charset\u003dutf-8" + ], + "x-version-label": [ + "easypost-202408152333-48cda4a73e-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "uri": "https://api.easypost.com/v2/api_keys" + }, + "duration": 277 + }, + { + "recordedAt": 1723823855, + "request": { + "body": "", + "method": "GET", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ] + }, + "uri": "https://api.easypost.com/v2/users/user_be3e8e064b094079b60311d3b310f738" + }, + "response": { + "body": "{\n \"children\": [],\n \"parent_id\": \"user_04ad194774a54f6c97d1385715721091\",\n \"name\": \"Test User\",\n \"verified\": true,\n \"created_at\": \"2024-08-16T15:57:34Z\",\n \"default_carbon_offset\": false,\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_be3e8e064b094079b60311d3b310f738\",\n \"has_elevate_access\": false,\n \"object\": \"User\"\n}", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 200 OK" + ], + "content-length": [ + "284" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb35nuq" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-download-options": [ + "noopen" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-backend": [ + "easypost" + ], + "pragma": [ + "no-cache" + ], + "strict-transport-security": [ + "max-age\u003d31536000; includeSubDomains; preload" + ], + "x-xss-protection": [ + "1; mode\u003dblock" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-ep-request-uuid": [ + "8a4bf43f66bf76efe786bcbe0035c1d4" + ], + "x-proxied": [ + "intlb4nuq c0f5e722d1", + "extlb1nuq b6e1b5034c" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.241655" + ], + "content-type": [ + "application/json; charset\u003dutf-8" + ], + "x-version-label": [ + "easypost-202408152333-48cda4a73e-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "uri": "https://api.easypost.com/v2/users/user_be3e8e064b094079b60311d3b310f738" + }, + "duration": 444 + }, + { + "recordedAt": 1723823856, + "request": { + "body": "", + "method": "DELETE", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ] + }, + "uri": "https://api.easypost.com/v2/users/user_be3e8e064b094079b60311d3b310f738" + }, + "response": { + "body": "", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 204 No Content" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb40nuq" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-download-options": [ + "noopen" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-backend": [ + "easypost" + ], + "pragma": [ + "no-cache" + ], + "strict-transport-security": [ + "max-age\u003d31536000; includeSubDomains; preload" + ], + "x-xss-protection": [ + "1; mode\u003dblock" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-ep-request-uuid": [ + "8a4bf43f66bf76f0e786bcbf0035c241" + ], + "x-proxied": [ + "intlb4nuq c0f5e722d1", + "extlb1nuq b6e1b5034c" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.137383" + ], + "x-version-label": [ + "easypost-202408152333-48cda4a73e-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 204, + "message": "No Content" + }, + "uri": "https://api.easypost.com/v2/users/user_be3e8e064b094079b60311d3b310f738" + }, + "duration": 351 + } +] \ No newline at end of file diff --git a/src/test/java/com/easypost/ApiKeyTest.java b/src/test/java/com/easypost/ApiKeyTest.java index 8fff27c65..06748cfe7 100644 --- a/src/test/java/com/easypost/ApiKeyTest.java +++ b/src/test/java/com/easypost/ApiKeyTest.java @@ -1,21 +1,25 @@ package com.easypost; -import com.easypost.exception.EasyPostException; -import com.easypost.exception.General.FilteringError; -import com.easypost.model.ApiKey; -import com.easypost.model.ApiKeys; -import com.easypost.model.User; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import com.easypost.exception.EasyPostException; +import com.easypost.exception.General.FilteringError; +import com.easypost.model.ApiKey; +import com.easypost.model.ApiKeys; +import com.easypost.model.User; public final class ApiKeyTest { private static String testUserId = null; @@ -60,6 +64,24 @@ private static User createUser() throws EasyPostException { return user; } + /** + * Test retrieving all API keys for a user. + * + * @throws EasyPostException when the request fails. + */ + @Test + public void testApiKeys() throws EasyPostException { + vcr.setUpTest("api_keys"); + + User user = createUser(); + + List apiKeys = vcr.client.apiKey.retrieveApiKeysForUser(user.getId()); + + assertNotNull(apiKeys); + + assertThrows(FilteringError.class, () -> vcr.client.apiKey.retrieveApiKeysForUser("invalid_id")); + } + /** * Test retrieving all API keys. * @@ -79,20 +101,30 @@ public void testAllApiKeys() throws EasyPostException { } /** - * Test retrieving all API keys for a user. + * Test creating an API key for a child user. * * @throws EasyPostException when the request fails. */ @Test - public void testApiKeys() throws EasyPostException { - vcr.setUpTest("api_keys"); - - User user = createUser(); - - List apiKeys = vcr.client.apiKey.retrieveApiKeysForUser(user.getId()); - - assertNotNull(apiKeys); - - assertThrows(FilteringError.class, () -> vcr.client.apiKey.retrieveApiKeysForUser("invalid_id")); + public void testApiKeyLifecycle() throws EasyPostException { + vcr.setUpTest("lifecycle"); + + // Create an API key + TestUtils.VCR referralVcr = new TestUtils.VCR("api_key", TestUtils.ApiKey.REFERRAL); + ApiKey apiKey = referralVcr.client.apiKey.create("production"); + assertInstanceOf(ApiKey.class, apiKey); + assertTrue(apiKey.getId().startsWith("ak_")); + assertEquals("production", apiKey.getMode()); + + // Disable the API key + apiKey = referralVcr.client.apiKey.disable(apiKey.getId()); + assertFalse(apiKey.getActive()); + + // Enable the API key + apiKey = referralVcr.client.apiKey.enable(apiKey.getId()); + assertTrue(apiKey.getActive()); + + // Delete the API key + referralVcr.client.apiKey.delete(apiKey.getId()); } } From 3772a1220483be189f6b698db5530ae632724f08 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Mon, 2 Feb 2026 15:24:01 -0700 Subject: [PATCH 2/3] chore: bump versions --- README.md | 4 ++-- VERSION | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 05ecd327b..98a5ceefb 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Add this to your project's POM: com.easypost easypost-api-client - 8.5.1 + 8.6.0 ``` @@ -25,7 +25,7 @@ Add this to your project's POM: Add this to your project's build file: ```groovy -implementation "com.easypost:easypost-api-client:8.5.1" +implementation "com.easypost:easypost-api-client:8.6.0" ``` **NOTE:** [Google Gson](http://code.google.com/p/google-gson/) is required. diff --git a/VERSION b/VERSION index f9c71a52e..acd405b1d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -8.5.1 +8.6.0 From 5f54d4fa55bf4fc486bf8ab0fdfd7fd4fde5f9ba Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Tue, 3 Feb 2026 09:53:43 -0700 Subject: [PATCH 3/3] chore: trigger GitHub Actions