Accounts
Accounts represent your customers in DialStack. Each account is isolated and can have multiple users, phone numbers, and devices.
Create an Account
TypeScript
const account = await dialstack.accounts.create({
email: 'customer@example.com',
primary_contact_name: 'Jane Doe',
address: {
street: '123 Main St',
city: 'New York',
state: 'NY',
postal_code: '10001',
country: 'US',
},
pricing: {
per_user_rate: 1999,
per_did_rate: 299,
per_voiceai_location_rate: 4999,
},
});
console.log(account.id);
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
email | string | Yes | Account owner's email address |
primary_contact_name | string | Yes | Account owner's name |
address | BillingAddress | Yes | The account's main location, used for E911 and for taxes and fees. billing_address is a deprecated alias: send one or the other |
pricing | AccountPricingParams | Yes | Agreed monthly rates, in cents: per_user_rate, per_did_rate, per_voiceai_location_rate |
config | AccountConfig | No | Account settings such as timezone and extension_length |
tos_variant | TosVariant | No | Which Service Subscription Agreement the account signs. Defaults to your platform's setting |
Response
TypeScript
interface Account {
id: string;
email: string | null;
created_at: string;
updated_at: string;
}
Retrieve an Account
TypeScript
const account = await dialstack.accounts.retrieve(accountId);
console.log(account.email);
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Account ID |
Update an Account
TypeScript
const account = await dialstack.accounts.update(accountId, {
email: 'newemail@example.com',
});
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Account ID |
email | string | No | New email address |
Delete an Account
TypeScript
await dialstack.accounts.del(accountId);
Destructive Action
Deleting an account removes all associated users, devices, and data. This action cannot be undone.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Account ID |
List Accounts
TypeScript
const response = await dialstack.accounts.list({
limit: 20,
});
for (const account of response.data) {
console.log(account.id, account.email);
}
if (response.next_page_url) {
// More accounts: use autoPagingEach() below, or follow next_page_url
}
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
limit | number | 10 | Results per page (max 100) |
Response
TypeScript
interface ListResponse<Account> {
object: 'list';
url: string;
next_page_url: string | null;
previous_page_url: string | null;
data: Account[];
}
See Pagination for following the page URLs.
Auto-Pagination
Iterate All Accounts
TypeScript
for await (const account of dialstack.accounts.list().autoPagingEach()) {
console.log(account.id);
}
Collect to Array
TypeScript
const allAccounts = await dialstack.accounts.list().autoPagingToArray({ limit: 1000 });
console.log(`Total accounts: ${allAccounts.length}`);
Examples
Create Account with Error Handling
TypeScript
import {
DialStack,
DialStackValidationError,
type AccountCreateParams,
} from '@dialstack/sdk-server';
async function createAccount(params: AccountCreateParams) {
try {
const account = await dialstack.accounts.create(params);
return { success: true, account };
} catch (error) {
if (error instanceof DialStackValidationError) {
return { success: false, error: error.message };
}
throw error;
}
}
Sync Accounts from External System
TypeScript
async function syncAccounts(externalAccounts: ExternalAccount[]) {
const results = [];
for (const ext of externalAccounts) {
// Check if account exists
let account: Account | null = null;
try {
account = await dialstack.accounts.retrieve(ext.dialstackId);
} catch (error) {
if (!(error instanceof DialStackNotFoundError)) {
throw error;
}
}
if (account) {
// Update existing
account = await dialstack.accounts.update(ext.dialstackId, {
email: ext.email,
});
} else {
// Create new
account = await dialstack.accounts.create({
email: ext.email,
primary_contact_name: ext.contactName,
address: ext.address,
pricing: ext.pricing,
});
}
results.push(account);
}
return results;
}
Collect Every Account
TypeScript
async function getAllAccounts() {
return dialstack.accounts.list({ limit: 100 }).autoPagingToArray({ limit: 100000 });
}