Skip to content

Node.js

No SDK needed — use native fetch (Node 18+) or axios.

const EMBOUX_URL = "https://api.emboux.com";
const API_KEY = "your-api-key-here";
const headers = {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
};
const resp = await fetch(`${EMBOUX_URL}/domains/`, {
method: "POST",
headers,
body: JSON.stringify({ name: "mycompany.com" }),
});
const domain = await resp.json();
console.log(`Domain created: ${domain.name}`);
const resp = await fetch(`${EMBOUX_URL}/users/`, {
method: "POST",
headers,
body: JSON.stringify({
domain_name: "mycompany.com",
email: "hello@mycompany.com",
password: "secure-password-123",
}),
});
const mailbox = await resp.json();
console.log(`Mailbox created: ${mailbox.email}`);
await fetch(`${EMBOUX_URL}/aliases/`, {
method: "POST",
headers,
body: JSON.stringify({
domain_name: "mycompany.com",
source: "info@mycompany.com",
destination: "hello@mycompany.com",
}),
});
const resp = await fetch(
`${EMBOUX_URL}/users/hello@mycompany.com/quota`,
{
method: "PUT",
headers,
body: JSON.stringify({ quota_mb: 2048 }),
}
);
const quota = await resp.json();
console.log(`Quota: ${quota.quota_mb} MB`);
async function provisionCustomer(domainName, adminEmail, password) {
// 1. Create domain
await fetch(`${EMBOUX_URL}/domains/`, {
method: "POST",
headers,
body: JSON.stringify({ name: domainName }),
});
// 2. Create admin mailbox
await fetch(`${EMBOUX_URL}/users/`, {
method: "POST",
headers,
body: JSON.stringify({
domain_name: domainName,
email: adminEmail,
password,
}),
});
// 3. Catch-all → admin
await fetch(`${EMBOUX_URL}/aliases/`, {
method: "POST",
headers,
body: JSON.stringify({
domain_name: domainName,
source: `@${domainName}`,
destination: adminEmail,
}),
});
console.log(`Customer ${domainName} provisioned!`);
}
await provisionCustomer("acme.com", "admin@acme.com", "super-secure");
const resp = await fetch(`${EMBOUX_URL}/domains/`, {
method: "POST",
headers,
body: JSON.stringify({ name: "mycompany.com" }),
});
if (!resp.ok) {
const error = await resp.json();
switch (resp.status) {
case 400:
console.error(`Already exists: ${error.detail}`);
break;
case 403:
console.error(`Quota exceeded: ${error.detail}`);
break;
default:
console.error(`Error ${resp.status}: ${error.detail}`);
}
}