用途:在号码从 Telnyx 携出(port-out)时,通过 Python SDK 管理携出申请,包括列表查询、查看详情、更新状态(批准或拒绝),以及管理事件、评论、支持文件和报表。
安装与初始化:pip install telnyx;使用 from telnyx import Telnyx,并以 api_key=os.environ.get("TELNYX_API_KEY") 初始化 client。
主要能力:
- 携出申请:GET /portouts 列表(支持过滤,返回自动分页迭代器)、GET /portouts/{id} 查看详情,字段含 status(pending、authorized、ported、rejected、rejected-pending、canceled)、foc_date、rejection_code、phone_numbers 等。
- 状态更新:PATCH /portouts/{id}/{status},reason 必填,可选 host_messaging。
- 事件:GET /portouts/events 列表、GET /portouts/events/{id} 查看、POST /portouts/events/{id}/republish 重新发布。
- 拒绝码:GET /portouts/rejections/{portout_id} 列出可用于该携出单的拒绝码。
- 报表:GET/POST /portouts/reports 列出与创建报表,GET /portouts/reports/{id} 获取;报表类型支持 export_portouts_csv。
- 评论与支持文件:GET/POST /portouts/{id}/comments,GET/POST /portouts/{id}/supporting_documents(类型 loa、invoice)。
错误处理:需捕获 telnyx.APIConnectionError、telnyx.RateLimitError(429 需指数退避重试)与 telnyx.APIStatusError;常见状态码 401、403、404、422、429。
限制:需已配置 TELNYX_API_KEY;分页需遍历迭代器;具体字段格式与业务约束以官方文档为准,资料未提供价格与额度信息。