🪪 Sub-Accounts module Email API
Manage your sub-accounts associated with your MailChannels account.
IMPORTANT
Sub-accounts are only available to parent accounts on 100K and higher plans.
Create method
Creates a new sub-account under the parent account.
Usage
import { MailChannelsClient, SubAccounts } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const subAccounts = new SubAccounts(mailchannels)
const { data, error } = await subAccounts.create('My Company', 'validhandle123')import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { data, error } = await mailchannels.subAccounts.create('My Company', 'validhandle123')Params
companyNamestringrequired: The name of the company associated with the sub-account.TIP
This name is used for display purposes only and does not affect the functionality of the sub-account. The length must be between 3 and 128 characters.
handlestringoptional: The handle of the sub-account to create.TIP
The length must be between 3 and 128 characters, and it may contain only lowercase letters and numbers.
If no handle is provided, a random handle will be generated.
Response
dataSubAccountsAccount | nullnullablecompanyNamestringguaranteed: The name of the company associated with the sub-account.enabledbooleanguaranteed: If the sub-account is enabled.handlestringguaranteed: The handle for the sub-account.
errorstring | nullnullable
List method
Retrieves all sub-accounts associated with the parent account.
Usage
import { MailChannelsClient, SubAccounts } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const subAccounts = new SubAccounts(mailchannels)
const { data, error } = await subAccounts.list()import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { data, error } = await mailchannels.subAccounts.list()Params
optionsSubAccountsListOptionsoptional: List sub-accounts options.limitnumberoptional: The number of sub-accounts to return. Possible values are 1 to 1000.offsetnumberoptional: The offset number to start returning sub-accounts from.
TIP
If no options are provided, the default limit is
1000and the offset is0.
Response
dataSubAccountsAccount[] | nullnullablecompanyNamestringguaranteed: The name of the company associated with the sub-account.enabledbooleanguaranteed: If the sub-account is enabled.handlestringguaranteed: The handle for the sub-account.
errorstring | nullnullable
Delete method
Deletes the sub-account identified by its handle.
Usage
import { MailChannelsClient, SubAccounts } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const subAccounts = new SubAccounts(mailchannels)
const { success, error } = await subAccounts.delete('validhandle123')import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { success, error } = await mailchannels.subAccounts.delete('validhandle123')Params
handlestringrequired: The handle of the sub-account to be deleted.
Response
successbooleanguaranteed: Whether the operation was successful.errorstring | nullnullable
Suspend method
Suspends the sub-account identified by its handle. This action disables the account, preventing it from sending any emails until it is reactivated.
Usage
import { MailChannelsClient, SubAccounts } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const subAccounts = new SubAccounts(mailchannels)
const { success, error } = await subAccounts.suspend('validhandle123')import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { success, error } = await mailchannels.subAccounts.suspend('validhandle123')Params
handlestringrequired: The handle of the sub-account to be suspended.
Response
successbooleanguaranteed: Whether the operation was successful.errorstring | nullnullable
Activate method
Activates a suspended sub-account identified by its handle, restoring its ability to send emails.
Usage
import { MailChannelsClient, SubAccounts } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const subAccounts = new SubAccounts(mailchannels)
const { success, error } = await subAccounts.activate('validhandle123')import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { success, error } = await mailchannels.subAccounts.activate('validhandle123')Params
handlestringrequired: The handle of the sub-account to be activated.
Response
successbooleanguaranteed: Whether the operation was successful.errorstring | nullnullable
Create API Key method
Creates a new API key for the specified sub-account.
Usage
import { MailChannelsClient, SubAccounts } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const subAccounts = new SubAccounts(mailchannels)
const { data, error } = await subAccounts.createApiKey('validhandle123')import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { data, error } = await mailchannels.subAccounts.createApiKey('validhandle123')Params
handlestringrequired: The handle of the sub-account to create API key for.
Response
dataSubAccountsApiKey | nullnullableidnumberguaranteed: The API key ID for the sub-account.valuestringguaranteed: API key for the sub-account.
errorstring | nullnullable
List API Keys method
Retrieves details of all API keys associated with the specified sub-account. For security reasons, the full API key is not returned; only the key ID and a partially redacted version are provided.
Usage
import { MailChannelsClient, SubAccounts } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const subAccounts = new SubAccounts(mailchannels)
const { data, error } = await subAccounts.listApiKeys('validhandle123')import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { data, error } = await mailchannels.subAccounts.listApiKeys('validhandle123')Params
handlestringrequired: The handle of the sub-account to retrieve the API keys for.optionsSubAccountsListApiKeyOptionsoptional: List API keys options.limitnumberoptional: The maximum number of API keys included in the response. Possible values are1to1000.offsetnumberoptional: Offset into the list of API keys to return.
TIP
If no options are provided, the default limit is
100and the offset is0.
Response
dataSubAccountsApiKey[] | nullnullableidnumberguaranteed: The API key ID for the sub-account.valuestringguaranteed: API key for the sub-account.
errorstring | nullnullable
Delete API Key method
Deletes the API key identified by its ID for the specified sub-account.
Usage
import { MailChannelsClient, SubAccounts } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const subAccounts = new SubAccounts(mailchannels)
const { success, error } = await subAccounts.deleteApiKey('validhandle123', 1)import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { success, error } = await mailchannels.subAccounts.deleteApiKey('validhandle123', 1)Params
handlestringrequired: The handle of the sub-account for which the API key should be deleted.idnumberrequired: The ID of the API key to delete.
Response
successbooleanguaranteed: Whether the operation was successful.errorstring | nullnullable
Create SMTP Password method
Creates a new API key for the specified sub-account.
Usage
import { MailChannelsClient, SubAccounts } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const subAccounts = new SubAccounts(mailchannels)
const { data, error } = await subAccounts.createSmtpPassword('validhandle123')import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { data, error } = await mailchannels.subAccounts.createSmtpPassword('validhandle123')Params
handlestringrequired: The handle of the sub-account to create SMTP password for.
Response
dataSubAccountsSmtpPassword | nullnullableenabledbooleanguaranteed: Whether the SMTP password is enabled.idnumberguaranteed: The SMTP password ID for the sub-account.valuestringguaranteed: SMTP password for the sub-account.
errorstring | nullnullable
List SMTP Passwords method
Retrieves details of all API keys associated with the specified sub-account. For security reasons, the full API key is not returned; only the key ID and a partially redacted version are provided.
Usage
import { MailChannelsClient, SubAccounts } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const subAccounts = new SubAccounts(mailchannels)
const { data, error } = await subAccounts.listSmtpPasswords('validhandle123')import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { data, error } = await mailchannels.subAccounts.listSmtpPasswords('validhandle123')Params
handlestringrequired: The handle of the sub-account to retrieve the SMTP passwords for.
Response
dataSubAccountsSmtpPassword[] | nullnullableenabledbooleanguaranteed: Whether the SMTP password is enabled.idnumberguaranteed: The SMTP password ID for the sub-account.valuestringguaranteed: SMTP password for the sub-account.
errorstring | nullnullable
Delete SMTP Password method
Deletes the SMTP password identified by its ID for the specified sub-account.
Usage
import { MailChannelsClient, SubAccounts } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const subAccounts = new SubAccounts(mailchannels)
const { success, error } = await subAccounts.deleteSmtpPassword('validhandle123', 1)import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { success, error } = await mailchannels.subAccounts.deleteSmtpPassword('validhandle123', 1)Params
handlestringrequired: The handle of the sub-account for which the SMTP password should be deleted.idnumberrequired: The ID of the SMTP password to delete.
Response
successbooleanguaranteed: Whether the operation was successful.errorstring | nullnullable
Get Limit method
Retrieves the limit of a specified sub-account.
TIP
A value of -1 indicates that the sub-account inherits the parent account's limit, allowing the sub-account to utilize any remaining capacity within the parent account's allocation.
Usage
import { MailChannelsClient, SubAccounts } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const subAccounts = new SubAccounts(mailchannels)
const { data, error } = await subAccounts.getLimit('validhandle123')import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { data, error } = await mailchannels.subAccounts.getLimit('validhandle123')Params
handlestringrequired: The handle of the sub-account to retrieve the limit for.
Response
dataSubAccountsLimit | nullnullablesendsnumberguaranteed
errorstring | nullnullable
Set Limit method
Sets the limit for the specified sub-account.
Usage
import { MailChannelsClient, SubAccounts } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const subAccounts = new SubAccounts(mailchannels)
const { success, error } = await subAccounts.setLimit('validhandle123', { sends: 1000 })import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { success, error } = await mailchannels.subAccounts.setLimit('validhandle123', { sends: 1000 })Params
handlestringrequired: The handle of the sub-account to set the limit for.limitsobjectrequired: The limits to set for the sub-account.sendsnumberrequired
TIP
The minimum allowed sends is
0.
Response
successbooleanguaranteed: Whether the operation was successful.errorstring | nullnullable
Delete Limit method
Deletes the limit for the specified sub-account. After a successful deletion, the specified sub-account will be limited to the parent account's limit.
Usage
import { MailChannelsClient, SubAccounts } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const subAccounts = new SubAccounts(mailchannels)
const { success, error } = await subAccounts.deleteLimit('validhandle123')import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { success, error } = await mailchannels.subAccounts.deleteLimit('validhandle123')Params
handlestringrequired: The handle of the sub-account to delete the limit for.
Response
successbooleanguaranteed: Whether the operation was successful.errorstring | nullnullable
Get Usage method
Retrieves usage statistics for the specified sub-account during the current billing period.
Usage
import { MailChannelsClient, SubAccounts } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const subAccounts = new SubAccounts(mailchannels)
const { data, error } = await subAccounts.getUsage('validhandle123')import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { data, error } = await mailchannels.subAccounts.getUsage('validhandle123')Params
handlestringrequired: The handle of the sub-account to query usage stats for.
Response
dataSubAccountsUsage | nullnullableendDatestringoptional: The end date of the current billing period (ISO 8601 format).startDatestringoptional: The start date of the current billing period (ISO 8601 format).totalnumberguaranteed: The total usage for the current billing period.
errorstring | nullnullable
Type declarations
class SubAccounts {
constructor (protected mailchannels: MailChannelsClient);
async create (companyName: string, handle?: string): Promise<SubAccountsCreateResponse>;
async list (options?: SubAccountsListOptions): Promise<SubAccountsListResponse>;
async delete (handle: string): Promise<SuccessResponse>;
async suspend (handle: string): Promise<SuccessResponse>;
async activate (handle: string): Promise<SuccessResponse>;
async createApiKey (handle: string): Promise<SubAccountsCreateApiKeyResponse>;
async listApiKeys (handle: string, options?: SubAccountsListApiKeyOptions): Promise<SubAccountsListApiKeyResponse>;
async deleteApiKey (handle: string, id: number): Promise<SuccessResponse>;
async createSmtpPassword (handle: string): Promise<SubAccountsCreateSmtpPasswordResponse>;
async listSmtpPasswords (handle: string): Promise<SubAccountsListSmtpPasswordResponse>;
async deleteSmtpPassword (handle: string, id: number): Promise<SuccessResponse>;
async getLimit (handle: string): Promise<SubAccountsLimitResponse>;
async setLimit (handle: string, limit: SubAccountsLimit): Promise<SuccessResponse>;
async deleteLimit (handle: string): Promise<SuccessResponse>;
async getUsage (handle: string): Promise<SubAccountsUsageResponse>;
}All type declarations
Responses
interface DataResponse<T> {
data: T | null;
error: string | null;
}interface SuccessResponse {
success: boolean;
error: string | null;
}Account type declarations
interface SubAccountsAccount {
companyName: string;
enabled: boolean;
handle: string;
}type SubAccountsCreateResponse = DataResponse<SubAccountsAccount>;interface SubAccountsListOptions {
limit?: number;
offset?: number;
}type SubAccountsListResponse = DataResponse<SubAccountsAccount[]>;API Key type declarations
interface SubAccountsApiKey {
id: number;
value: string;
}type SubAccountsCreateApiKeyResponse = DataResponse<SubAccountsApiKey>;type SubAccountsListApiKeyResponse = DataResponse<SubAccountsApiKey[]>;SMTP Password type declarations
interface SubAccountsSmtpPassword {
enabled: boolean;
id: number;
value: string;
}type SubAccountsCreateSmtpPasswordResponse = DataResponse<SubAccountsSmtpPassword>;type SubAccountsListSmtpPasswordResponse = DataResponse<SubAccountsSmtpPassword[]>;Limit type declaration
interface SubAccountsLimit {
sends: number;
}type SubAccountsLimitResponse = DataResponse<SubAccountsLimit>;Usage type declarations
interface SubAccountsUsage {
endDate?: string;
startDate?: string;
total: number;
}type SubAccountsUsageResponse = DataResponse<SubAccountsUsage>;Source
Source • Playground • Docs