Node.js
import { MailChannels } from "mailchannels-sdk";
const { PARENT_API_KEY, COMPANY_NAME, SUB_ACCOUNT_HANDLE } = process.env;
if (!PARENT_API_KEY) throw new Error("Set PARENT_API_KEY (a parent-account API key) before running");
if (!COMPANY_NAME) throw new Error("Set COMPANY_NAME (display name for the sub-account)");
const mailchannels = new MailChannels(PARENT_API_KEY);
// SUB_ACCOUNT_HANDLE is optional. If omitted, MailChannels generates a random handle.
const { data, error } = await mailchannels.subAccounts.create(COMPANY_NAME, SUB_ACCOUNT_HANDLE);
if (error) {
console.error("Create sub-account failed:", error);
process.exit(1);
}
console.log(data);import os
import sys
import mailchannels
parent_api_key = os.environ.get("PARENT_API_KEY")
company_name = os.environ.get("COMPANY_NAME")
if not parent_api_key:
sys.exit("Set PARENT_API_KEY (a parent-account API key) before running")
if not company_name:
sys.exit("Set COMPANY_NAME (display name for the sub-account)")
mailchannels.api_key = parent_api_key
# SUB_ACCOUNT_HANDLE is optional. If omitted, MailChannels generates a random handle.
response = mailchannels.SubAccounts.create(
company_name=company_name,
handle=os.environ.get("SUB_ACCOUNT_HANDLE"),
)
print(response)<?php
require_once __DIR__ . '/vendor/autoload.php';
use MailChannels\Client;
$parent_api_key = getenv('PARENT_API_KEY') or exit("Error: PARENT_API_KEY is not set\n");
$company_name = getenv('COMPANY_NAME') or exit("Error: COMPANY_NAME is not set\n");
$client = new Client(apiKey: $parent_api_key);
// SUB_ACCOUNT_HANDLE is optional. If omitted, MailChannels generates a random handle.
$response = $client->subAccounts->create(
companyName: $company_name,
handle: getenv('SUB_ACCOUNT_HANDLE') ?: null,
);
print_r($response->toArray());curl --request POST \
--url https://api.mailchannels.net/tx/v1/sub-account \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <x-api-key>' \
--data '
{
"company_name": "<string>",
"handle": "<string>"
}
'{
"enabled": true,
"handle": "<string>",
"company_name": "<string>"
}Create Sub-account
Creates a new sub-account under the parent account. Each sub-account must have a unique handle composed solely of lowercase alphanumeric characters. If no handle is provided, a random handle will be generated.
POST
/
sub-account
Node.js
import { MailChannels } from "mailchannels-sdk";
const { PARENT_API_KEY, COMPANY_NAME, SUB_ACCOUNT_HANDLE } = process.env;
if (!PARENT_API_KEY) throw new Error("Set PARENT_API_KEY (a parent-account API key) before running");
if (!COMPANY_NAME) throw new Error("Set COMPANY_NAME (display name for the sub-account)");
const mailchannels = new MailChannels(PARENT_API_KEY);
// SUB_ACCOUNT_HANDLE is optional. If omitted, MailChannels generates a random handle.
const { data, error } = await mailchannels.subAccounts.create(COMPANY_NAME, SUB_ACCOUNT_HANDLE);
if (error) {
console.error("Create sub-account failed:", error);
process.exit(1);
}
console.log(data);import os
import sys
import mailchannels
parent_api_key = os.environ.get("PARENT_API_KEY")
company_name = os.environ.get("COMPANY_NAME")
if not parent_api_key:
sys.exit("Set PARENT_API_KEY (a parent-account API key) before running")
if not company_name:
sys.exit("Set COMPANY_NAME (display name for the sub-account)")
mailchannels.api_key = parent_api_key
# SUB_ACCOUNT_HANDLE is optional. If omitted, MailChannels generates a random handle.
response = mailchannels.SubAccounts.create(
company_name=company_name,
handle=os.environ.get("SUB_ACCOUNT_HANDLE"),
)
print(response)<?php
require_once __DIR__ . '/vendor/autoload.php';
use MailChannels\Client;
$parent_api_key = getenv('PARENT_API_KEY') or exit("Error: PARENT_API_KEY is not set\n");
$company_name = getenv('COMPANY_NAME') or exit("Error: COMPANY_NAME is not set\n");
$client = new Client(apiKey: $parent_api_key);
// SUB_ACCOUNT_HANDLE is optional. If omitted, MailChannels generates a random handle.
$response = $client->subAccounts->create(
companyName: $company_name,
handle: getenv('SUB_ACCOUNT_HANDLE') ?: null,
);
print_r($response->toArray());curl --request POST \
--url https://api.mailchannels.net/tx/v1/sub-account \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <x-api-key>' \
--data '
{
"company_name": "<string>",
"handle": "<string>"
}
'{
"enabled": true,
"handle": "<string>",
"company_name": "<string>"
}Headers
Body
application/json
The details of the sub-account to create.
The name of the company associated with the sub-account. 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.
A unique name for the sub-account to be created. The length must be between 3 and 128 characters, and it may contain only lowercase letters and numbers. If not provided, a random handle will be generated.
Was this page helpful?

