telnyx-account-java
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese<!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. -->
<!-- 由Telnyx OpenAPI规范自动生成,请勿编辑。 -->
Telnyx Account - Java
Telnyx 账户管理 - Java
Installation
安装
text
<!-- Maven -->
<dependency>
<groupId>com.telnyx.sdk</groupId>
<artifactId>telnyx</artifactId>
<version>6.36.0</version>
</dependency>
// Gradle
implementation("com.telnyx.sdk:telnyx:6.36.0")text
<!-- Maven -->
<dependency>
<groupId>com.telnyx.sdk</groupId>
<artifactId>telnyx</artifactId>
<version>6.36.0</version>
</dependency>
// Gradle
implementation("com.telnyx.sdk:telnyx:6.36.0")Setup
配置
java
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
TelnyxClient client = TelnyxOkHttpClient.fromEnv();All examples below assume is already initialized as shown above.
clientjava
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
TelnyxClient client = TelnyxOkHttpClient.fromEnv();以下所有示例均假设已按照上述方式完成初始化。
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:
java
import com.telnyx.sdk.errors.TelnyxServiceException;
try {
var result = client.messages().send(params);
} catch (TelnyxServiceException e) {
System.err.println("API error " + e.statusCode() + ": " + e.getMessage());
if (e.statusCode() == 422) {
System.err.println("Validation error — check required fields and formats");
} else if (e.statusCode() == 429) {
// Rate limited — wait and retry with exponential backoff
Thread.sleep(1000);
}
}Common error codes: invalid API key, insufficient permissions,
resource not found, validation error (check field formats),
rate limited (retry with exponential backoff).
401403404422429所有API调用都可能遇到网络错误、速率限制(429)、校验错误(422)或认证错误(401)。在生产代码中请务必处理错误:
java
import com.telnyx.sdk.errors.TelnyxServiceException;
try {
var result = client.messages().send(params);
} catch (TelnyxServiceException e) {
System.err.println("API error " + e.statusCode() + ": " + e.getMessage());
if (e.statusCode() == 422) {
System.err.println("Validation error — check required fields and formats");
} else if (e.statusCode() == 429) {
// Rate limited — wait and retry with exponential backoff
Thread.sleep(1000);
}
}常见错误码: API密钥无效, 权限不足, 资源不存在, 校验错误(请检查字段格式), 触发速率限制(请使用指数退避策略重试)。
401403404422429Important Notes
重要说明
- Pagination: List methods return a page. Use for automatic iteration:
.autoPager(). For manual control, usefor (var item : page.autoPager()) { ... }and.hasNextPage()..nextPage()
- 分页: 列表方法返回单页数据。使用可实现自动遍历:
.autoPager()。如果需要手动控制,可使用for (var item : page.autoPager()) { ... }和.hasNextPage()方法。.nextPage()
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_eventsjava
import com.telnyx.sdk.models.auditevents.AuditEventListPage;
import com.telnyx.sdk.models.auditevents.AuditEventListParams;
AuditEventListPage page = client.auditEvents().list();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_id获取审计日志条目列表。审计日志是尽力而为、最终一致的记录,存储与账户相关的重大变更。
GET /audit_eventsjava
import com.telnyx.sdk.models.auditevents.AuditEventListPage;
import com.telnyx.sdk.models.auditevents.AuditEventListParams;
AuditEventListPage page = client.auditEvents().list();返回字段: (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 /balancejava
import com.telnyx.sdk.models.balance.BalanceRetrieveParams;
import com.telnyx.sdk.models.balance.BalanceRetrieveResponse;
BalanceRetrieveResponse balance = client.balance().retrieve();Returns: (string), (string), (string), (string), (string), (enum: balance)
available_creditbalancecredit_limitcurrencypendingrecord_typeGET /balancejava
import com.telnyx.sdk.models.balance.BalanceRetrieveParams;
import com.telnyx.sdk.models.balance.BalanceRetrieveResponse;
BalanceRetrieveResponse balance = client.balance().retrieve();返回字段: (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_breakdownjava
import com.telnyx.sdk.models.chargesbreakdown.ChargesBreakdownRetrieveParams;
import com.telnyx.sdk.models.chargesbreakdown.ChargesBreakdownRetrieveResponse;
import java.time.LocalDate;
ChargesBreakdownRetrieveParams params = ChargesBreakdownRetrieveParams.builder()
.startDate(LocalDate.parse("2025-05-01"))
.build();
ChargesBreakdownRetrieveResponse chargesBreakdown = client.chargesBreakdown().retrieve(params);Returns: (string), (date), (array[object]), (date), (email), (string)
currencyend_dateresultsstart_dateuser_emailuser_id查询指定日期范围内电话号码的月度费用详细明细。日期范围不可超过31天。
GET /charges_breakdownjava
import com.telnyx.sdk.models.chargesbreakdown.ChargesBreakdownRetrieveParams;
import com.telnyx.sdk.models.chargesbreakdown.ChargesBreakdownRetrieveResponse;
import java.time.LocalDate;
ChargesBreakdownRetrieveParams params = ChargesBreakdownRetrieveParams.builder()
.startDate(LocalDate.parse("2025-05-01"))
.build();
ChargesBreakdownRetrieveResponse chargesBreakdown = client.chargesBreakdown().retrieve(params);返回字段: (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_summaryjava
import com.telnyx.sdk.models.chargessummary.ChargesSummaryRetrieveParams;
import com.telnyx.sdk.models.chargessummary.ChargesSummaryRetrieveResponse;
import java.time.LocalDate;
ChargesSummaryRetrieveParams params = ChargesSummaryRetrieveParams.builder()
.endDate(LocalDate.parse("2025-06-01"))
.startDate(LocalDate.parse("2025-05-01"))
.build();
ChargesSummaryRetrieveResponse chargesSummary = client.chargesSummary().retrieve(params);Returns: (string), (date), (date), (object), (object), (email), (string)
currencyend_datestart_datesummarytotaluser_emailuser_id查询指定日期范围内的月度费用汇总。日期范围不可超过31天。
GET /charges_summaryjava
import com.telnyx.sdk.models.chargessummary.ChargesSummaryRetrieveParams;
import com.telnyx.sdk.models.chargessummary.ChargesSummaryRetrieveResponse;
import java.time.LocalDate;
ChargesSummaryRetrieveParams params = ChargesSummaryRetrieveParams.builder()
.endDate(LocalDate.parse("2025-06-01"))
.startDate(LocalDate.parse("2025-05-01"))
.build();
ChargesSummaryRetrieveResponse chargesSummary = client.chargesSummary().retrieve(params);返回字段: (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_recordsjava
import com.telnyx.sdk.models.detailrecords.DetailRecordListPage;
import com.telnyx.sdk.models.detailrecords.DetailRecordListParams;
DetailRecordListPage page = client.detailRecords().list();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_iduuid在Telnyx平台中搜索任意明细记录
GET /detail_recordsjava
import com.telnyx.sdk.models.detailrecords.DetailRecordListPage;
import com.telnyx.sdk.models.detailrecords.DetailRecordListParams;
DetailRecordListPage page = client.detailRecords().list();返回字段: (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 /invoicesjava
import com.telnyx.sdk.models.invoices.InvoiceListPage;
import com.telnyx.sdk.models.invoices.InvoiceListParams;
InvoiceListPage page = client.invoices().list();Returns: (uuid), (uuid), (boolean), (date), (date), (uri)
file_idinvoice_idpaidperiod_endperiod_starturl获取分页的发票列表。
GET /invoicesjava
import com.telnyx.sdk.models.invoices.InvoiceListPage;
import com.telnyx.sdk.models.invoices.InvoiceListParams;
InvoiceListPage page = client.invoices().list();返回字段: (uuid), (uuid), (boolean), (date), (date), (uri)
file_idinvoice_idpaidperiod_endperiod_starturlGet invoice by ID
根据ID查询发票
Retrieve a single invoice by its unique identifier.
GET /invoices/{id}java
import com.telnyx.sdk.models.invoices.InvoiceRetrieveParams;
import com.telnyx.sdk.models.invoices.InvoiceRetrieveResponse;
InvoiceRetrieveResponse invoice = client.invoices().retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e");Returns: (uri), (uuid), (uuid), (boolean), (date), (date), (uri)
download_urlfile_idinvoice_idpaidperiod_endperiod_starturl根据唯一标识符获取单张发票信息。
GET /invoices/{id}java
import com.telnyx.sdk.models.invoices.InvoiceRetrieveParams;
import com.telnyx.sdk.models.invoices.InvoiceRetrieveResponse;
InvoiceRetrieveResponse invoice = client.invoices().retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e");返回字段: (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_prefsjava
import com.telnyx.sdk.models.payment.autorechargeprefs.AutoRechargePrefListParams;
import com.telnyx.sdk.models.payment.autorechargeprefs.AutoRechargePrefListResponse;
AutoRechargePrefListResponse autoRechargePrefs = client.payment().autoRechargePrefs().list();Returns: (boolean), (string), (boolean), (enum: credit_paypal, ach), (string), (string), (string)
enabledidinvoice_enabledpreferencerecharge_amountrecord_typethreshold_amount返回支付自动充值的配置项。
GET /payment/auto_recharge_prefsjava
import com.telnyx.sdk.models.payment.autorechargeprefs.AutoRechargePrefListParams;
import com.telnyx.sdk.models.payment.autorechargeprefs.AutoRechargePrefListResponse;
AutoRechargePrefListResponse autoRechargePrefs = client.payment().autoRechargePrefs().list();返回字段: (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_amountjava
import com.telnyx.sdk.models.payment.autorechargeprefs.AutoRechargePrefUpdateParams;
import com.telnyx.sdk.models.payment.autorechargeprefs.AutoRechargePrefUpdateResponse;
AutoRechargePrefUpdateResponse autoRechargePref = client.payment().autoRechargePrefs().update();Returns: (boolean), (string), (boolean), (enum: credit_paypal, ach), (string), (string), (string)
enabledidinvoice_enabledpreferencerecharge_amountrecord_typethreshold_amount更新支付自动充值配置项。
PATCH /payment/auto_recharge_prefs可选参数: (boolean), (boolean), (enum: credit_paypal, ach), (string), (string)
enabledinvoice_enabledpreferencerecharge_amountthreshold_amountjava
import com.telnyx.sdk.models.payment.autorechargeprefs.AutoRechargePrefUpdateParams;
import com.telnyx.sdk.models.payment.autorechargeprefs.AutoRechargePrefUpdateResponse;
AutoRechargePrefUpdateResponse autoRechargePref = client.payment().autoRechargePrefs().update();返回字段: (boolean), (string), (boolean), (enum: credit_paypal, ach), (string), (string), (string)
enabledidinvoice_enabledpreferencerecharge_amountrecord_typethreshold_amountList User Tags
查询用户标签列表
List all user tags.
GET /user_tagsjava
import com.telnyx.sdk.models.usertags.UserTagListParams;
import com.telnyx.sdk.models.usertags.UserTagListResponse;
UserTagListResponse userTags = client.userTags().list();Returns: (array[string]), (array[string])
number_tagsoutbound_profile_tags查询所有用户标签。
GET /user_tagsjava
import com.telnyx.sdk.models.usertags.UserTagListParams;
import com.telnyx.sdk.models.usertags.UserTagListResponse;
UserTagListResponse userTags = client.userTags().list();返回字段: (array[string]), (array[string])
number_tagsoutbound_profile_tagsCreate a stored payment transaction
创建预存支付交易
POST /v2/payment/stored_payment_transactionsamountjava
import com.telnyx.sdk.models.payment.PaymentCreateStoredPaymentTransactionParams;
import com.telnyx.sdk.models.payment.PaymentCreateStoredPaymentTransactionResponse;
PaymentCreateStoredPaymentTransactionParams params = PaymentCreateStoredPaymentTransactionParams.builder()
.amount("120.00")
.build();
PaymentCreateStoredPaymentTransactionResponse response = client.payment().createStoredPaymentTransaction(params);Returns: (integer), (string), (boolean), (date-time), (string), (string), (enum: transaction), (enum: stored_payment)
amount_centsamount_currencyauto_rechargecreated_atidprocessor_statusrecord_typetransaction_processing_typePOST /v2/payment/stored_payment_transactionsamountjava
import com.telnyx.sdk.models.payment.PaymentCreateStoredPaymentTransactionParams;
import com.telnyx.sdk.models.payment.PaymentCreateStoredPaymentTransactionResponse;
PaymentCreateStoredPaymentTransactionParams params = PaymentCreateStoredPaymentTransactionParams.builder()
.amount("120.00")
.build();
PaymentCreateStoredPaymentTransactionResponse response = client.payment().createStoredPaymentTransaction(params);返回字段: (integer), (string), (boolean), (date-time), (string), (string), (enum: transaction), (enum: stored_payment)
amount_centsamount_currencyauto_rechargecreated_atidprocessor_statusrecord_typetransaction_processing_typeList webhook deliveries
查询webhook投递记录列表
Lists webhook_deliveries for the authenticated user
GET /webhook_deliveriesjava
import com.telnyx.sdk.models.webhookdeliveries.WebhookDeliveryListPage;
import com.telnyx.sdk.models.webhookdeliveries.WebhookDeliveryListParams;
WebhookDeliveryListPage page = client.webhookDeliveries().list();Returns: (array[object]), (date-time), (uuid), (string), (date-time), (enum: delivered, failed), (uuid), (object)
attemptsfinished_atidrecord_typestarted_atstatususer_idwebhook列出当前认证用户的webhook投递记录
GET /webhook_deliveriesjava
import com.telnyx.sdk.models.webhookdeliveries.WebhookDeliveryListPage;
import com.telnyx.sdk.models.webhookdeliveries.WebhookDeliveryListParams;
WebhookDeliveryListPage page = client.webhookDeliveries().list();返回字段: (array[object]), (date-time), (uuid), (string), (date-time), (enum: delivered, failed), (uuid), (object)
attemptsfinished_atidrecord_typestarted_atstatususer_idwebhookFind webhook_delivery details by ID
根据ID查询webhook投递详情
Provides webhook_delivery debug data, such as timestamps, delivery status and attempts.
GET /webhook_deliveries/{id}java
import com.telnyx.sdk.models.webhookdeliveries.WebhookDeliveryRetrieveParams;
import com.telnyx.sdk.models.webhookdeliveries.WebhookDeliveryRetrieveResponse;
WebhookDeliveryRetrieveResponse webhookDelivery = client.webhookDeliveries().retrieve("C9C0797E-901D-4349-A33C-C2C8F31A92C2");Returns: (array[object]), (date-time), (uuid), (string), (date-time), (enum: delivered, failed), (uuid), (object)
attemptsfinished_atidrecord_typestarted_atstatususer_idwebhook提供webhook投递的调试数据,例如时间戳、投递状态和尝试次数。
GET /webhook_deliveries/{id}java
import com.telnyx.sdk.models.webhookdeliveries.WebhookDeliveryRetrieveParams;
import com.telnyx.sdk.models.webhookdeliveries.WebhookDeliveryRetrieveResponse;
WebhookDeliveryRetrieveResponse webhookDelivery = client.webhookDeliveries().retrieve("C9C0797E-901D-4349-A33C-C2C8F31A92C2");返回字段: (array[object]), (date-time), (uuid), (string), (date-time), (enum: delivered, failed), (uuid), (object)
attemptsfinished_atidrecord_typestarted_atstatususer_idwebhook