telnyx-account-javascript
Original:🇺🇸 English
Translated
Manage account balance, payments, invoices, webhooks, and view audit logs and detail records. This skill provides JavaScript SDK examples.
59installs
Sourceteam-telnyx/skills
Added on
NPX Install
npx skill4agent add team-telnyx/skills telnyx-account-javascriptTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →<!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. -->
— Required:
Telnyx Account - JavaScript
Installation
bash
npm install telnyxSetup
javascript
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});All examples below assume is already initialized as shown above.
clientError Handling
All API calls can fail with network errors, rate limits (429), validation errors (422),
or authentication errors (401). Always handle errors in production code:
javascript
try {
const result = await client.messages.send({ to: '+13125550001', from: '+13125550002', text: 'Hello' });
} catch (err) {
if (err instanceof Telnyx.APIConnectionError) {
console.error('Network error — check connectivity and retry');
} else if (err instanceof Telnyx.RateLimitError) {
// 429: rate limited — wait and retry with exponential backoff
const retryAfter = err.headers?.['retry-after'] || 1;
await new Promise(r => setTimeout(r, retryAfter * 1000));
} else if (err instanceof Telnyx.APIError) {
console.error(`API error ${err.status}: ${err.message}`);
if (err.status === 422) {
console.error('Validation error — check required fields and formats');
}
}
}Common error codes: invalid API key, insufficient permissions,
resource not found, validation error (check field formats),
rate limited (retry with exponential backoff).
401403404422429Important Notes
- Pagination: List methods return an auto-paginating iterator. Use to iterate through all pages automatically.
for await (const item of result) { ... }
List Audit Logs
Retrieve a list of audit log entries. Audit logs are a best-effort, eventually consistent record of significant account-related changes.
GET /audit_eventsjavascript
// Automatically fetches more pages as needed.
for await (const auditEventListResponse of client.auditEvents.list()) {
console.log(auditEventListResponse.id);
}Returns: (string | null), (enum: telnyx, account_manager, account_owner, organization_member), (string), (array | null), (date-time), (uuid), (uuid), (string), (string), (uuid)
alternate_resource_idchange_made_bychange_typechangescreated_atidorganization_idrecord_typeresource_iduser_idGet user balance details
GET /balancejavascript
const balance = await client.balance.retrieve();
console.log(balance.data);Returns: (string), (string), (string), (string), (string), (enum: balance)
available_creditbalancecredit_limitcurrencypendingrecord_typeGet monthly charges breakdown
Retrieve a detailed breakdown of monthly charges for phone numbers in a specified date range. The date range cannot exceed 31 days.
GET /charges_breakdownjavascript
const chargesBreakdown = await client.chargesBreakdown.retrieve({ start_date: '2025-05-01' });
console.log(chargesBreakdown.data);Returns: (string), (date), (array[object]), (date), (email), (string)
currencyend_dateresultsstart_dateuser_emailuser_idGet monthly charges summary
Retrieve a summary of monthly charges for a specified date range. The date range cannot exceed 31 days.
GET /charges_summaryjavascript
const chargesSummary = await client.chargesSummary.retrieve({
end_date: '2025-06-01',
start_date: '2025-05-01',
});
console.log(chargesSummary.data);Returns: (string), (date), (date), (object), (object), (email), (string)
currencyend_datestart_datesummarytotaluser_emailuser_idSearch detail records
Search for any detail record across the Telnyx Platform
GET /detail_recordsjavascript
// Automatically fetches more pages as needed.
for await (const detailRecordListResponse of client.detailRecords.list()) {
console.log(detailRecordListResponse);
}Returns: (string), (string), (string), (string), (date-time), (string), (string), (date-time), (string), (string), (string), (string), (enum: inbound, outbound), (array[string]), (boolean), (string), (enum: SMS, MMS, RCS), (string), (boolean), (integer), (string), (string), (string), (string), (date-time), (string), (enum: gw_timeout, delivered, dlr_unconfirmed, dlr_timeout, received, gw_reject, failed), (string), (date-time), (string), (string)
carriercarrier_feecldclicompleted_atcostcountry_codecreated_atcurrencydelivery_statusdelivery_status_failover_urldelivery_status_webhook_urldirectionerrorsfteumccmessage_typemncon_netpartsprofile_idprofile_nameraterecord_typesent_atsource_country_codestatustagsupdated_atuser_iduuidList invoices
Retrieve a paginated list of invoices.
GET /invoicesjavascript
// Automatically fetches more pages as needed.
for await (const invoiceListResponse of client.invoices.list()) {
console.log(invoiceListResponse.file_id);
}Returns: (uuid), (uuid), (boolean), (date), (date), (uri)
file_idinvoice_idpaidperiod_endperiod_starturlGet invoice by ID
Retrieve a single invoice by its unique identifier.
GET /invoices/{id}javascript
const invoice = await client.invoices.retrieve('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e');
console.log(invoice.data);Returns: (uri), (uuid), (uuid), (boolean), (date), (date), (uri)
download_urlfile_idinvoice_idpaidperiod_endperiod_starturlList auto recharge preferences
Returns the payment auto recharge preferences.
GET /payment/auto_recharge_prefsjavascript
const autoRechargePrefs = await client.payment.autoRechargePrefs.list();
console.log(autoRechargePrefs.data);Returns: (boolean), (string), (boolean), (enum: credit_paypal, ach), (string), (string), (string)
enabledidinvoice_enabledpreferencerecharge_amountrecord_typethreshold_amountUpdate auto recharge preferences
Update payment auto recharge preferences.
PATCH /payment/auto_recharge_prefsOptional: (boolean), (boolean), (enum: credit_paypal, ach), (string), (string)
enabledinvoice_enabledpreferencerecharge_amountthreshold_amountjavascript
const autoRechargePref = await client.payment.autoRechargePrefs.update();
console.log(autoRechargePref.data);Returns: (boolean), (string), (boolean), (enum: credit_paypal, ach), (string), (string), (string)
enabledidinvoice_enabledpreferencerecharge_amountrecord_typethreshold_amountList User Tags
List all user tags.
GET /user_tagsjavascript
const userTags = await client.userTags.list();
console.log(userTags.data);Returns: (array[string]), (array[string])
number_tagsoutbound_profile_tagsCreate a stored payment transaction
POST /v2/payment/stored_payment_transactionsamountjavascript
const response = await client.payment.createStoredPaymentTransaction({ amount: '120.00' });
console.log(response.data);Returns: (integer), (string), (boolean), (date-time), (string), (string), (enum: transaction), (enum: stored_payment)
amount_centsamount_currencyauto_rechargecreated_atidprocessor_statusrecord_typetransaction_processing_typeList webhook deliveries
Lists webhook_deliveries for the authenticated user
GET /webhook_deliveriesjavascript
// Automatically fetches more pages as needed.
for await (const webhookDeliveryListResponse of client.webhookDeliveries.list()) {
console.log(webhookDeliveryListResponse.id);
}Returns: (array[object]), (date-time), (uuid), (string), (date-time), (enum: delivered, failed), (uuid), (object)
attemptsfinished_atidrecord_typestarted_atstatususer_idwebhookFind webhook_delivery details by ID
Provides webhook_delivery debug data, such as timestamps, delivery status and attempts.
GET /webhook_deliveries/{id}javascript
const webhookDelivery = await client.webhookDeliveries.retrieve(
'C9C0797E-901D-4349-A33C-C2C8F31A92C2',
);
console.log(webhookDelivery.data);Returns: (array[object]), (date-time), (uuid), (string), (date-time), (enum: delivered, failed), (uuid), (object)
attemptsfinished_atidrecord_typestarted_atstatususer_idwebhook