The Accounts resource provides methods to manage Cloudflare accounts, their members, roles, subscriptions, and API tokens.
Main methods
create
Create a new account (available for tenant admins).
const account = await client.accounts.create({
name: 'My New Account',
type: 'standard'
});
type
'standard' | 'enterprise'
Account type (defaults to ‘standard’)
type
'standard' | 'enterprise'
Account type
Timestamp for the creation of the account
update
Update an existing account.
const account = await client.accounts.update({
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
id: '023e105f4ecef8ad9ca31a8372d0c353',
name: 'Updated Account Name',
type: 'standard'
});
type
'standard' | 'enterprise'
required
Account type
Account settingssettings.abuse_contact_email
Email to notify for abuse reports
settings.enforce_twofactor
Whether Two-Factor Authentication is required for account members
list
List all accounts you have ownership or verified access to.
// Automatically fetches more pages as needed
for await (const account of client.accounts.list()) {
console.log(account.name);
}
Direction to order results
Page number of paginated results
Number of items per page (max 50)
delete
Delete a specific account (available for tenant admins). This is a permanent operation that will delete any zones or other resources under the account.
const result = await client.accounts.delete({
account_id: '023e105f4ecef8ad9ca31a8372d0c353'
});
get
Get information about a specific account that you are a member of.
const account = await client.accounts.get({
account_id: '023e105f4ecef8ad9ca31a8372d0c353'
});
Account type
interface Account {
id: string;
name: string;
type: 'standard' | 'enterprise';
created_on?: string;
managed_by?: {
parent_org_id?: string;
parent_org_name?: string;
};
settings?: {
abuse_contact_email?: string;
enforce_twofactor?: boolean;
};
}
Sub-resources
The Accounts resource provides access to several sub-resources:
- members - Manage account members and their roles
- roles - List available roles for an account
- subscriptions - Manage account subscriptions
- tokens - Manage API tokens for an account
- logs - Access account audit logs
Example usage
import Cloudflare from 'cloudflare';
const client = new Cloudflare({
apiToken: process.env.CLOUDFLARE_API_TOKEN
});
// Create a new account
const newAccount = await client.accounts.create({
name: 'My Company Account',
type: 'standard'
});
// List all accounts
const accounts = await client.accounts.list();
// Get specific account details
const account = await client.accounts.get({
account_id: newAccount.id
});
// Update account settings
const updatedAccount = await client.accounts.update({
account_id: account.id,
id: account.id,
name: account.name,
type: account.type,
settings: {
enforce_twofactor: true
}
});
// Add a member to the account
const member = await client.accounts.members.create({
account_id: account.id,
email: '[email protected]',
roles: ['Administrator']
});