telnyx-account-ruby
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese<!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. -->
<!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. -->
Telnyx Account - Ruby
Telnyx 账户 - Ruby
Installation
安装
bash
gem install telnyxbash
gem install telnyxSetup
配置
ruby
require "telnyx"
client = Telnyx::Client.new(
api_key: ENV["TELNYX_API_KEY"], # This is the default and can be omitted
)All examples below assume is already initialized as shown above.
clientruby
require "telnyx"
client = Telnyx::Client.new(
api_key: ENV["TELNYX_API_KEY"], # This is the default and can be omitted
)以下所有示例均假定已按上述方式初始化完成。
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:
ruby
begin
result = client.messages.send_(to: "+13125550001", from: "+13125550002", text: "Hello")
rescue Telnyx::Errors::APIConnectionError
puts "Network error — check connectivity and retry"
rescue Telnyx::Errors::RateLimitError
# 429: rate limited — wait and retry with exponential backoff
sleep(1) # Check Retry-After header for actual delay
rescue Telnyx::Errors::APIStatusError => e
puts "API error #{e.status}: #{e.message}"
if e.status == 422
puts "Validation error — check required fields and formats"
end
endCommon 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)而失败。生产代码中请务必做好错误处理:
ruby
begin
result = client.messages.send_(to: "+13125550001", from: "+13125550002", text: "Hello")
rescue Telnyx::Errors::APIConnectionError
puts "Network error — check connectivity and retry"
rescue Telnyx::Errors::RateLimitError
# 429: rate limited — wait and retry with exponential backoff
sleep(1) # Check Retry-After header for actual delay
rescue Telnyx::Errors::APIStatusError => e
puts "API error #{e.status}: #{e.message}"
if e.status == 422
puts "Validation error — check required fields and formats"
end
end常见错误码: 无效API密钥, 权限不足, 资源不存在, 校验错误(请检查字段格式), 速率受限(请使用指数退避策略重试)。
401403404422429Important Notes
重要说明
- Pagination: Use for automatic iteration:
.auto_paging_each.page.auto_paging_each { |item| puts item.id }
- 分页: 使用实现自动遍历:
.auto_paging_each。page.auto_paging_each { |item| puts item.id }
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_eventsruby
page = client.audit_events.list
puts(page)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_eventsruby
page = client.audit_events.list
puts(page)返回参数: (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 /balanceruby
balance = client.balance.retrieve
puts(balance)Returns: (string), (string), (string), (string), (string), (enum: balance)
available_creditbalancecredit_limitcurrencypendingrecord_typeGET /balanceruby
balance = client.balance.retrieve
puts(balance)返回参数: (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_breakdownruby
charges_breakdown = client.charges_breakdown.retrieve(start_date: "2025-05-01")
puts(charges_breakdown)Returns: (string), (date), (array[object]), (date), (email), (string)
currencyend_dateresultsstart_dateuser_emailuser_id获取指定日期范围内电话号码月度费用的详细拆分。日期范围不得超过31天。
GET /charges_breakdownruby
charges_breakdown = client.charges_breakdown.retrieve(start_date: "2025-05-01")
puts(charges_breakdown)返回参数: (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_summaryruby
charges_summary = client.charges_summary.retrieve(end_date: "2025-06-01", start_date: "2025-05-01")
puts(charges_summary)Returns: (string), (date), (date), (object), (object), (email), (string)
currencyend_datestart_datesummarytotaluser_emailuser_id获取指定日期范围内的月度费用汇总。日期范围不得超过31天。
GET /charges_summaryruby
charges_summary = client.charges_summary.retrieve(end_date: "2025-06-01", start_date: "2025-05-01")
puts(charges_summary)返回参数: (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_recordsruby
page = client.detail_records.list
puts(page)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_recordsruby
page = client.detail_records.list
puts(page)返回参数: (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 /invoicesruby
page = client.invoices.list
puts(page)Returns: (uuid), (uuid), (boolean), (date), (date), (uri)
file_idinvoice_idpaidperiod_endperiod_starturl获取分页的发票列表。
GET /invoicesruby
page = client.invoices.list
puts(page)返回参数: (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}ruby
invoice = client.invoices.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
puts(invoice)Returns: (uri), (uuid), (uuid), (boolean), (date), (date), (uri)
download_urlfile_idinvoice_idpaidperiod_endperiod_starturl通过唯一标识符获取单张发票。
GET /invoices/{id}ruby
invoice = client.invoices.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
puts(invoice)返回参数: (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_prefsruby
auto_recharge_prefs = client.payment.auto_recharge_prefs.list
puts(auto_recharge_prefs)Returns: (boolean), (string), (boolean), (enum: credit_paypal, ach), (string), (string), (string)
enabledidinvoice_enabledpreferencerecharge_amountrecord_typethreshold_amount返回支付自动充值的偏好配置。
GET /payment/auto_recharge_prefsruby
auto_recharge_prefs = client.payment.auto_recharge_prefs.list
puts(auto_recharge_prefs)返回参数: (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_amountruby
auto_recharge_pref = client.payment.auto_recharge_prefs.update
puts(auto_recharge_pref)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_amountruby
auto_recharge_pref = client.payment.auto_recharge_prefs.update
puts(auto_recharge_pref)返回参数: (boolean), (string), (boolean), (enum: credit_paypal, ach), (string), (string), (string)
enabledidinvoice_enabledpreferencerecharge_amountrecord_typethreshold_amountList User Tags
列出用户标签
List all user tags.
GET /user_tagsruby
user_tags = client.user_tags.list
puts(user_tags)Returns: (array[string]), (array[string])
number_tagsoutbound_profile_tags列出所有用户标签。
GET /user_tagsruby
user_tags = client.user_tags.list
puts(user_tags)返回参数: (array[string]), (array[string])
number_tagsoutbound_profile_tagsCreate a stored payment transaction
创建存储支付交易
POST /v2/payment/stored_payment_transactionsamountruby
response = client.payment.create_stored_payment_transaction(amount: "120.00")
puts(response)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_transactionsamountruby
response = client.payment.create_stored_payment_transaction(amount: "120.00")
puts(response)返回参数: (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_deliveriesruby
page = client.webhook_deliveries.list
puts(page)Returns: (array[object]), (date-time), (uuid), (string), (date-time), (enum: delivered, failed), (uuid), (object)
attemptsfinished_atidrecord_typestarted_atstatususer_idwebhook列出已认证用户的webhook投递记录
GET /webhook_deliveriesruby
page = client.webhook_deliveries.list
puts(page)返回参数: (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}ruby
webhook_delivery = client.webhook_deliveries.retrieve("C9C0797E-901D-4349-A33C-C2C8F31A92C2")
puts(webhook_delivery)Returns: (array[object]), (date-time), (uuid), (string), (date-time), (enum: delivered, failed), (uuid), (object)
attemptsfinished_atidrecord_typestarted_atstatususer_idwebhook提供webhook投递的调试数据,例如时间戳、投递状态和尝试次数。
GET /webhook_deliveries/{id}ruby
webhook_delivery = client.webhook_deliveries.retrieve("C9C0797E-901D-4349-A33C-C2C8F31A92C2")
puts(webhook_delivery)返回参数: (array[object]), (date-time), (uuid), (string), (date-time), (enum: delivered, failed), (uuid), (object)
attemptsfinished_atidrecord_typestarted_atstatususer_idwebhook