Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

## v8.5.0 (2026-02-03)

- Adds the following functions usable by child and referral customer users:
- `ApiKey.create`
- `ApiKey.delete`
- `ApiKey.enable`
- `ApiKey.disable`

## v8.4.0 (2025-11-24)

- Adds the following functions:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@easypost/api",
"description": "EasyPost Node Client Library",
"version": "8.4.0",
"version": "8.5.0",
"author": "Easypost Engineering <[email protected]>",
"homepage": "https://easypost.com",
"exports": {
Expand Down
89 changes: 78 additions & 11 deletions src/services/api_key_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@ export default (easypostClient) =>
* @param {EasyPostClient} easypostClient - The pre-configured EasyPostClient instance to use for API requests with this service.
*/
class ApiKeyService extends baseService(easypostClient) {
/**
* Retrieve all {@link ApiKey API keys} associated with the current authenticated user.
* See {@link https://docs.easypost.com/docs/api-keys#retrieve-an-api-key EasyPost API Documentation} for more information.
* @returns {Object} - An object containing the API keys associated with the current authenticated user and its child users.
*/
static async all(params = {}) {
const url = 'api_keys';

return this._all(url, params);
}

/**
* Retrieve API Keys for a specified {@link User user}.
* See {@link https://docs.easypost.com/docs/api-keys#retrieve-an-api-key EasyPost API Documentation} for more information.
Expand Down Expand Up @@ -50,4 +39,82 @@ export default (easypostClient) =>

throw new FilteringError({ message: util.format(Constants.NO_OBJECT_FOUND, 'child') });
}

/**
* Retrieve all {@link ApiKey API keys} associated with the current authenticated user.
* See {@link https://docs.easypost.com/docs/api-keys#retrieve-an-api-key EasyPost API Documentation} for more information.
* @returns {Object} - An object containing the API keys associated with the current authenticated user and its child users.
*/
static async all(params = {}) {
const url = 'api_keys';

return this._all(url, params);
}

/**
* Create an API key for a child or referral customer user.
* See {@link https://docs.easypost.com/docs/api-keys#create-an-api-key EasyPost API Documentation} for more information.
* @param {string} mode - The mode for the API key (either "production" or "test").
* @returns {ApiKey} - The created API key.
*/
static async create(mode) {
const url = 'api_keys';
const params = { mode };

return this._create(url, params);
}

/**
* Delete an API key for a child or referral customer user.
* See {@link https://docs.easypost.com/docs/api-keys#delete-an-api-key EasyPost API Documentation} for more information.
* @param {string} id - The ID of the API key to delete.
* @returns {Promise|Promise<never>} - A promise that resolves if the API key was successfully deleted.
*/
static async delete(id) {
const url = `api_keys/${id}`;

try {
await easypostClient._delete(url);

return Promise.resolve();
} catch (e) {
return Promise.reject(e);
}
}

/**
* Enable a child or referral customer API key.
* See {@link https://docs.easypost.com/docs/api-keys#enable-an-api-key EasyPost API Documentation} for more information.
* @param {string} id - The ID of the API key to enable.
* @returns {ApiKey} - The enabled API key.
*/
static async enable(id) {
const url = `api_keys/${id}/enable`;

try {
const response = await easypostClient._post(url);

return this._convertToEasyPostObject(response.body);
} catch (e) {
return Promise.reject(e);
}
}

/**
* Disable a child or referral customer API key.
* See {@link https://docs.easypost.com/docs/api-keys#disable-an-api-key EasyPost API Documentation} for more information.
* @param {string} id - The ID of the API key to disable.
* @returns {ApiKey} - The disabled API key.
*/
static async disable(id) {
const url = `api_keys/${id}/disable`;

try {
const response = await easypostClient._post(url);

return this._convertToEasyPostObject(response.body);
} catch (e) {
return Promise.reject(e);
}
}
};
Loading