Skip to content

Commit d12ab70

Browse files
authored
feat: create/delete/enable/disable API keys (#533)
# 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 65921d3 commit d12ab70

File tree

6 files changed

+757
-24
lines changed

6 files changed

+757
-24
lines changed

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.5.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.4.0 (2025-11-24)
412

513
- Adds the following functions:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@easypost/api",
33
"description": "EasyPost Node Client Library",
4-
"version": "8.4.0",
4+
"version": "8.5.0",
55
"author": "Easypost Engineering <[email protected]>",
66
"homepage": "https://easypost.com",
77
"exports": {

src/services/api_key_service.js

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@ export default (easypostClient) =>
1010
* @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service.
1111
*/
1212
class ApiKeyService extends baseService(easypostClient) {
13-
/**
14-
* Retrieve all {@link ApiKey API keys} associated with the current authenticated user.
15-
* See {@link https://docs.easypost.com/docs/api-keys#retrieve-an-api-key EasyPost API Documentation} for more information.
16-
* @returns {Object} - An object containing the API keys associated with the current authenticated user and its child users.
17-
*/
18-
static async all(params = {}) {
19-
const url = 'api_keys';
20-
21-
return this._all(url, params);
22-
}
23-
2413
/**
2514
* Retrieve API Keys for a specified {@link User user}.
2615
* See {@link https://docs.easypost.com/docs/api-keys#retrieve-an-api-key EasyPost API Documentation} for more information.
@@ -50,4 +39,82 @@ export default (easypostClient) =>
5039

5140
throw new FilteringError({ message: util.format(Constants.NO_OBJECT_FOUND, 'child') });
5241
}
42+
43+
/**
44+
* Retrieve all {@link ApiKey API keys} associated with the current authenticated user.
45+
* See {@link https://docs.easypost.com/docs/api-keys#retrieve-an-api-key EasyPost API Documentation} for more information.
46+
* @returns {Object} - An object containing the API keys associated with the current authenticated user and its child users.
47+
*/
48+
static async all(params = {}) {
49+
const url = 'api_keys';
50+
51+
return this._all(url, params);
52+
}
53+
54+
/**
55+
* Create an API key for a child or referral customer user.
56+
* See {@link https://docs.easypost.com/docs/api-keys#create-an-api-key EasyPost API Documentation} for more information.
57+
* @param {string} mode - The mode for the API key (either "production" or "test").
58+
* @returns {ApiKey} - The created API key.
59+
*/
60+
static async create(mode) {
61+
const url = 'api_keys';
62+
const params = { mode };
63+
64+
return this._create(url, params);
65+
}
66+
67+
/**
68+
* Delete an API key for a child or referral customer user.
69+
* See {@link https://docs.easypost.com/docs/api-keys#delete-an-api-key EasyPost API Documentation} for more information.
70+
* @param {string} id - The ID of the API key to delete.
71+
* @returns {Promise|Promise<never>} - A promise that resolves if the API key was successfully deleted.
72+
*/
73+
static async delete(id) {
74+
const url = `api_keys/${id}`;
75+
76+
try {
77+
await easypostClient._delete(url);
78+
79+
return Promise.resolve();
80+
} catch (e) {
81+
return Promise.reject(e);
82+
}
83+
}
84+
85+
/**
86+
* Enable a child or referral customer API key.
87+
* See {@link https://docs.easypost.com/docs/api-keys#enable-an-api-key EasyPost API Documentation} for more information.
88+
* @param {string} id - The ID of the API key to enable.
89+
* @returns {ApiKey} - The enabled API key.
90+
*/
91+
static async enable(id) {
92+
const url = `api_keys/${id}/enable`;
93+
94+
try {
95+
const response = await easypostClient._post(url);
96+
97+
return this._convertToEasyPostObject(response.body);
98+
} catch (e) {
99+
return Promise.reject(e);
100+
}
101+
}
102+
103+
/**
104+
* Disable a child or referral customer API key.
105+
* See {@link https://docs.easypost.com/docs/api-keys#disable-an-api-key EasyPost API Documentation} for more information.
106+
* @param {string} id - The ID of the API key to disable.
107+
* @returns {ApiKey} - The disabled API key.
108+
*/
109+
static async disable(id) {
110+
const url = `api_keys/${id}/disable`;
111+
112+
try {
113+
const response = await easypostClient._post(url);
114+
115+
return this._convertToEasyPostObject(response.body);
116+
} catch (e) {
117+
return Promise.reject(e);
118+
}
119+
}
53120
};

0 commit comments

Comments
 (0)