Node.js
import { MailChannels } from "mailchannels-sdk";
const { PARENT_API_KEY, SUB_ACCOUNT_HANDLE } = process.env;
if (!PARENT_API_KEY) throw new Error("Set PARENT_API_KEY (a parent-account API key) before running");
if (!SUB_ACCOUNT_HANDLE) throw new Error("Set SUB_ACCOUNT_HANDLE (the sub-account to create a key for)");
const mailchannels = new MailChannels(PARENT_API_KEY);
const { data, error } = await mailchannels.subAccounts.createApiKey(SUB_ACCOUNT_HANDLE);
if (error) {
console.error("Create sub-account API key failed:", error);
process.exit(1);
}
// data.key is shown only once. Store it securely.
console.log(data);import os
import sys
import mailchannels
parent_api_key = os.environ.get("PARENT_API_KEY")
handle = os.environ.get("SUB_ACCOUNT_HANDLE")
if not parent_api_key:
sys.exit("Set PARENT_API_KEY (a parent-account API key) before running")
if not handle:
sys.exit("Set SUB_ACCOUNT_HANDLE (the sub-account to create a key for)")
mailchannels.api_key = parent_api_key
response = mailchannels.SubAccounts.ApiKeys.create(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");
$sub_account_handle = getenv('SUB_ACCOUNT_HANDLE') or exit("Error: SUB_ACCOUNT_HANDLE is not set\n");
$client = new Client(apiKey: $parent_api_key);
$response = $client->subAccounts->apiKeys->create($sub_account_handle);
print_r($response->toArray());curl --request POST \
--url https://api.mailchannels.net/tx/v1/sub-account/{handle}/api-key \
--header 'X-Api-Key: <x-api-key>'{
"id": 123,
"key": "<string>"
}Create Sub-account API Key
Creates a new API key for the specified sub-account.
POST
/
sub-account
/
{handle}
/
api-key
Node.js
import { MailChannels } from "mailchannels-sdk";
const { PARENT_API_KEY, SUB_ACCOUNT_HANDLE } = process.env;
if (!PARENT_API_KEY) throw new Error("Set PARENT_API_KEY (a parent-account API key) before running");
if (!SUB_ACCOUNT_HANDLE) throw new Error("Set SUB_ACCOUNT_HANDLE (the sub-account to create a key for)");
const mailchannels = new MailChannels(PARENT_API_KEY);
const { data, error } = await mailchannels.subAccounts.createApiKey(SUB_ACCOUNT_HANDLE);
if (error) {
console.error("Create sub-account API key failed:", error);
process.exit(1);
}
// data.key is shown only once. Store it securely.
console.log(data);import os
import sys
import mailchannels
parent_api_key = os.environ.get("PARENT_API_KEY")
handle = os.environ.get("SUB_ACCOUNT_HANDLE")
if not parent_api_key:
sys.exit("Set PARENT_API_KEY (a parent-account API key) before running")
if not handle:
sys.exit("Set SUB_ACCOUNT_HANDLE (the sub-account to create a key for)")
mailchannels.api_key = parent_api_key
response = mailchannels.SubAccounts.ApiKeys.create(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");
$sub_account_handle = getenv('SUB_ACCOUNT_HANDLE') or exit("Error: SUB_ACCOUNT_HANDLE is not set\n");
$client = new Client(apiKey: $parent_api_key);
$response = $client->subAccounts->apiKeys->create($sub_account_handle);
print_r($response->toArray());curl --request POST \
--url https://api.mailchannels.net/tx/v1/sub-account/{handle}/api-key \
--header 'X-Api-Key: <x-api-key>'{
"id": 123,
"key": "<string>"
}Was this page helpful?
⌘I

