Loading...
Loading...
Manage account balance, payments, invoices, webhooks, and view audit logs and detail records. This skill provides JavaScript SDK examples.
npx skill4agent add team-telnyx/skills telnyx-account-javascriptnpm install telnyximport Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});clienttry {
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');
}
}
}401403404422429for await (const item of result) { ... }GET /audit_events// Automatically fetches more pages as needed.
for await (const auditEventListResponse of client.auditEvents.list()) {
console.log(auditEventListResponse.id);
}alternate_resource_idchange_made_bychange_typechangescreated_atidorganization_idrecord_typeresource_iduser_idGET /balanceconst balance = await client.balance.retrieve();
console.log(balance.data);available_creditbalancecredit_limitcurrencypendingrecord_typeGET /charges_breakdownconst chargesBreakdown = await client.chargesBreakdown.retrieve({ start_date: '2025-05-01' });
console.log(chargesBreakdown.data);currencyend_dateresultsstart_dateuser_emailuser_idGET /charges_summaryconst chargesSummary = await client.chargesSummary.retrieve({
end_date: '2025-06-01',
start_date: '2025-05-01',
});
console.log(chargesSummary.data);currencyend_datestart_datesummarytotaluser_emailuser_idGET /detail_records// Automatically fetches more pages as needed.
for await (const detailRecordListResponse of client.detailRecords.list()) {
console.log(detailRecordListResponse);
}carriercarrier_feecldclicompleted_atcostcountry_codecreated_atcurrencydelivery_statusdelivery_status_failover_urldelivery_status_webhook_urldirectionerrorsfteumccmessage_typemncon_netpartsprofile_idprofile_nameraterecord_typesent_atsource_country_codestatustagsupdated_atuser_iduuidGET /invoices// Automatically fetches more pages as needed.
for await (const invoiceListResponse of client.invoices.list()) {
console.log(invoiceListResponse.file_id);
}file_idinvoice_idpaidperiod_endperiod_starturlGET /invoices/{id}const invoice = await client.invoices.retrieve('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e');
console.log(invoice.data);download_urlfile_idinvoice_idpaidperiod_endperiod_starturlGET /payment/auto_recharge_prefsconst autoRechargePrefs = await client.payment.autoRechargePrefs.list();
console.log(autoRechargePrefs.data);enabledidinvoice_enabledpreferencerecharge_amountrecord_typethreshold_amountPATCH /payment/auto_recharge_prefsenabledinvoice_enabledpreferencerecharge_amountthreshold_amountconst autoRechargePref = await client.payment.autoRechargePrefs.update();
console.log(autoRechargePref.data);enabledidinvoice_enabledpreferencerecharge_amountrecord_typethreshold_amountGET /user_tagsconst userTags = await client.userTags.list();
console.log(userTags.data);number_tagsoutbound_profile_tagsPOST /v2/payment/stored_payment_transactionsamountconst response = await client.payment.createStoredPaymentTransaction({ amount: '120.00' });
console.log(response.data);amount_centsamount_currencyauto_rechargecreated_atidprocessor_statusrecord_typetransaction_processing_typeGET /webhook_deliveries// Automatically fetches more pages as needed.
for await (const webhookDeliveryListResponse of client.webhookDeliveries.list()) {
console.log(webhookDeliveryListResponse.id);
}attemptsfinished_atidrecord_typestarted_atstatususer_idwebhookGET /webhook_deliveries/{id}const webhookDelivery = await client.webhookDeliveries.retrieve(
'C9C0797E-901D-4349-A33C-C2C8F31A92C2',
);
console.log(webhookDelivery.data);attemptsfinished_atidrecord_typestarted_atstatususer_idwebhook