Skip to content

Commit 57819f3

Browse files
authored
feat: create/delete/enable/disable API keys (#372)
# Description <!-- Please provide a general summary of your PR changes and link any related issues or other pull requests. --> # Testing <!-- Please provide details on how you tested this code. See below. - All pull requests must be tested (unit tests where possible with accompanying cassettes, or provide a screenshot of end-to-end testing when unit tests are not possible) - New features must get a new unit test - Bug fixes/refactors must re-record existing cassettes --> # Pull Request Type Please select the option(s) that are relevant to this PR. - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Improvement (fixing a typo, updating readme, renaming a variable name, etc)
1 parent a5098e4 commit 57819f3

10 files changed

Lines changed: 862 additions & 75 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# CHANGELOG
22

3+
## v8.6.0 (2026-02-03)
4+
5+
- Adds the following functions usable by child and referral customer users:
6+
- `apiKey.create`
7+
- `apiKey.delete`
8+
- `apiKey.enable`
9+
- `apiKey.disable`
10+
311
## v8.5.1 (2026-01-08)
412

513
- Corrects `StatelessRateDeserializer` and `WebhookDeserializer` to treat all camelCase fields like all other models to properly deserialize JSON fields containing underscors

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Add this to your project's POM:
1616
<dependency>
1717
<groupId>com.easypost</groupId>
1818
<artifactId>easypost-api-client</artifactId>
19-
<version>8.5.1</version>
19+
<version>8.6.0</version>
2020
</dependency>
2121
```
2222

@@ -25,7 +25,7 @@ Add this to your project's POM:
2525
Add this to your project's build file:
2626

2727
```groovy
28-
implementation "com.easypost:easypost-api-client:8.5.1"
28+
implementation "com.easypost:easypost-api-client:8.6.0"
2929
```
3030

3131
**NOTE:** [Google Gson](http://code.google.com/p/google-gson/) is required.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.5.1
1+
8.6.0

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>com.easypost</groupId>
77
<artifactId>easypost-api-client</artifactId>
88

9-
<version>8.5.1</version>
9+
<version>8.6.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>com.easypost:easypost-api-client</name>

src/main/java/com/easypost/model/ApiKey.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
@Getter
66
public final class ApiKey extends EasyPostResource {
77
private String key;
8+
private Boolean active;
89
}

src/main/java/com/easypost/service/ApiKeyService.java

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,6 @@ public class ApiKeyService {
2323
this.client = client;
2424
}
2525

26-
/**
27-
* Get all API keys.
28-
*
29-
* @return ApiKeys object.
30-
* @throws EasyPostException when the request fails.
31-
*/
32-
public ApiKeys all() throws EasyPostException {
33-
String endpoint = "api_keys";
34-
35-
return Requestor.request(RequestMethod.GET, endpoint, null, ApiKeys.class, client);
36-
}
37-
3826
/**
3927
* Get this User's API keys.
4028
*
@@ -57,4 +45,70 @@ public List<ApiKey> retrieveApiKeysForUser(final String id) throws EasyPostExcep
5745

5846
throw new FilteringError(String.format(Constants.ErrorMessages.NO_OBJECT_FOUND, "API keys"));
5947
}
48+
49+
/**
50+
* Get all API keys.
51+
*
52+
* @return ApiKeys object.
53+
* @throws EasyPostException when the request fails.
54+
*/
55+
public ApiKeys all() throws EasyPostException {
56+
String endpoint = "api_keys";
57+
58+
return Requestor.request(RequestMethod.GET, endpoint, null, ApiKeys.class, client);
59+
}
60+
61+
/**
62+
* Create an API key for a child or referral customer user.
63+
*
64+
* @param mode The mode of the API key (production or test).
65+
* @return ApiKey object.
66+
* @throws EasyPostException when the request fails.
67+
*/
68+
public ApiKey create(final String mode) throws EasyPostException {
69+
String endpoint = "api_keys";
70+
71+
java.util.Map<String, Object> params = new java.util.HashMap<>();
72+
params.put("mode", mode);
73+
74+
return Requestor.request(RequestMethod.POST, endpoint, params, ApiKey.class, client);
75+
}
76+
77+
/**
78+
* Delete an API key for a child or referral customer user.
79+
*
80+
* @param id The ID of the API key to delete.
81+
* @throws EasyPostException when the request fails.
82+
*/
83+
public void delete(final String id) throws EasyPostException {
84+
String endpoint = String.format("api_keys/%s", id);
85+
86+
Requestor.request(RequestMethod.DELETE, endpoint, null, ApiKey.class, client);
87+
}
88+
89+
/**
90+
* Enable a child or referral customer API key.
91+
*
92+
* @param id The ID of the API key to enable.
93+
* @return ApiKey object.
94+
* @throws EasyPostException when the request fails.
95+
*/
96+
public ApiKey enable(final String id) throws EasyPostException {
97+
String endpoint = String.format("api_keys/%s/enable", id);
98+
99+
return Requestor.request(RequestMethod.POST, endpoint, null, ApiKey.class, client);
100+
}
101+
102+
/**
103+
* Disable a child or referral customer API key.
104+
*
105+
* @param id The ID of the API key to disable.
106+
* @return ApiKey object.
107+
* @throws EasyPostException when the request fails.
108+
*/
109+
public ApiKey disable(final String id) throws EasyPostException {
110+
String endpoint = String.format("api_keys/%s/disable", id);
111+
112+
return Requestor.request(RequestMethod.POST, endpoint, null, ApiKey.class, client);
113+
}
60114
}

src/test/cassettes/api_key/api_keys.json

Lines changed: 37 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)