telnyx-porting-out-python
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 Porting Out - Python
Telnyx 号码转出 - Python
Installation
安装
bash
pip install telnyxbash
pip install telnyxSetup
初始化配置
python
import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)All examples below assume is already initialized as shown above.
clientpython
import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # 这是默认配置,可省略
)以下所有示例均假设已按照上述方式完成初始化。
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:
python
import telnyx
try:
result = client.messages.send(to="+13125550001", from_="+13125550002", text="Hello")
except telnyx.APIConnectionError:
print("Network error — check connectivity and retry")
except telnyx.RateLimitError:
# 429: rate limited — wait and retry with exponential backoff
import time
time.sleep(1) # Check Retry-After header for actual delay
except telnyx.APIStatusError as e:
print(f"API error {e.status_code}: {e.message}")
if e.status_code == 422:
print("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).
401403404422429所有API调用都可能因网络错误、速率限制(429)、校验错误(422)或认证错误(401)而失败。在生产代码中请务必做好错误处理:
python
import telnyx
try:
result = client.messages.send(to="+13125550001", from_="+13125550002", text="Hello")
except telnyx.APIConnectionError:
print("网络错误 — 检查网络连接后重试")
except telnyx.RateLimitError:
# 429: 触发速率限制 — 等待后使用指数退避策略重试
import time
time.sleep(1) # 可查看Retry-After响应头获取准确的等待时长
except telnyx.APIStatusError as e:
print(f"API错误 {e.status_code}: {e.message}")
if e.status_code == 422:
print("校验错误 — 检查必填字段和格式是否正确")常见错误码: API密钥无效, 权限不足, 资源不存在, 校验错误(检查字段格式), 触发速率限制(使用指数退避策略重试)。
401403404422429Important Notes
重要说明
- Pagination: List methods return an auto-paginating iterator. Use to iterate through all pages automatically.
for item in page_result:
- 分页: 列表类方法返回支持自动分页的迭代器,使用即可自动遍历所有分页结果。
for item in page_result:
List portout requests
列出portout请求
Returns the portout requests according to filters
GET /portoutspython
page = client.portouts.list()
page = page.data[0]
print(page.id)Returns: (boolean), (string), (string), (string), (string), (string), (string), (string), (boolean), (string), (string), (array[string]), (array[string]), (string), (string | null), (string), (integer), (string), (string), (string), (string), (enum: pending, authorized, ported, rejected, rejected-pending, canceled), (string), (string), (uuid), (uuid), (string)
already_portedauthorized_namecarrier_namecitycreated_atcurrent_carrierend_user_namefoc_datehost_messagingidinserted_atlsrphone_numbersponreasonrecord_typerejection_coderequested_foc_dateservice_addressspidstatestatussupport_keyupdated_atuser_idvendorzip根据筛选条件返回portout请求
GET /portoutspython
page = client.portouts.list()
page = page.data[0]
print(page.id)返回字段: (boolean), (string), (string), (string), (string), (string), (string), (string), (boolean), (string), (string), (array[string]), (array[string]), (string), (string | null), (string), (integer), (string), (string), (string), (string), (enum: pending, authorized, ported, rejected, rejected-pending, canceled), (string), (string), (uuid), (uuid), (string)
already_portedauthorized_namecarrier_namecitycreated_atcurrent_carrierend_user_namefoc_datehost_messagingidinserted_atlsrphone_numbersponreasonrecord_typerejection_coderequested_foc_dateservice_addressspidstatestatussupport_keyupdated_atuser_idvendorzipList all port-out events
列出所有port-out事件
Returns a list of all port-out events.
GET /portouts/eventspython
page = client.portouts.events.list()
page = page.data[0]
print(page)Returns: (array[string]), (date-time), (enum: portout.status_changed, portout.foc_date_changed, portout.new_comment), (uuid), (object), (enum: created, completed), (uuid), (string), (date-time)
available_notification_methodscreated_atevent_typeidpayloadpayload_statusportout_idrecord_typeupdated_at返回所有port-out事件的列表
GET /portouts/eventspython
page = client.portouts.events.list()
page = page.data[0]
print(page)返回字段: (array[string]), (date-time), (enum: portout.status_changed, portout.foc_date_changed, portout.new_comment), (uuid), (object), (enum: created, completed), (uuid), (string), (date-time)
available_notification_methodscreated_atevent_typeidpayloadpayload_statusportout_idrecord_typeupdated_atShow a port-out event
查询单个port-out事件
Show a specific port-out event.
GET /portouts/events/{id}python
event = client.portouts.events.retrieve(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(event.data)Returns: (array[string]), (date-time), (enum: portout.status_changed, portout.foc_date_changed, portout.new_comment), (uuid), (object), (enum: created, completed), (uuid), (string), (date-time)
available_notification_methodscreated_atevent_typeidpayloadpayload_statusportout_idrecord_typeupdated_at查询指定的port-out事件详情
GET /portouts/events/{id}python
event = client.portouts.events.retrieve(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(event.data)返回字段: (array[string]), (date-time), (enum: portout.status_changed, portout.foc_date_changed, portout.new_comment), (uuid), (object), (enum: created, completed), (uuid), (string), (date-time)
available_notification_methodscreated_atevent_typeidpayloadpayload_statusportout_idrecord_typeupdated_atRepublish a port-out event
重新发布port-out事件
Republish a specific port-out event.
POST /portouts/events/{id}/republishpython
client.portouts.events.republish(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)重新发布指定的port-out事件
POST /portouts/events/{id}/republishpython
client.portouts.events.republish(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)List eligible port-out rejection codes for a specific order
列出特定订单符合条件的port-out拒绝码
Given a port-out ID, list rejection codes that are eligible for that port-out
GET /portouts/rejections/{portout_id}python
response = client.portouts.list_rejection_codes(
portout_id="329d6658-8f93-405d-862f-648776e8afd7",
)
print(response.data)Returns: (integer), (string), (boolean)
codedescriptionreason_required传入port-out ID,列出该port-out可使用的拒绝码
GET /portouts/rejections/{portout_id}python
response = client.portouts.list_rejection_codes(
portout_id="329d6658-8f93-405d-862f-648776e8afd7",
)
print(response.data)返回字段: (integer), (string), (boolean)
codedescriptionreason_requiredList port-out related reports
列出port-out相关报表
List the reports generated about port-out operations.
GET /portouts/reportspython
page = client.portouts.reports.list()
page = page.data[0]
print(page.id)Returns: (date-time), (uuid), (uuid), (object), (string), (enum: export_portouts_csv), (enum: pending, completed), (date-time)
created_atdocument_ididparamsrecord_typereport_typestatusupdated_at列出所有port-out操作生成的报表
GET /portouts/reportspython
page = client.portouts.reports.list()
page = page.data[0]
print(page.id)返回字段: (date-time), (uuid), (uuid), (object), (string), (enum: export_portouts_csv), (enum: pending, completed), (date-time)
created_atdocument_ididparamsrecord_typereport_typestatusupdated_atCreate a port-out related report
创建port-out相关报表
Generate reports about port-out operations.
POST /portouts/reportspython
report = client.portouts.reports.create(
params={
"filters": {}
},
report_type="export_portouts_csv",
)
print(report.data)Returns: (date-time), (uuid), (uuid), (object), (string), (enum: export_portouts_csv), (enum: pending, completed), (date-time)
created_atdocument_ididparamsrecord_typereport_typestatusupdated_at生成port-out操作的相关报表
POST /portouts/reportspython
report = client.portouts.reports.create(
params={
"filters": {}
},
report_type="export_portouts_csv",
)
print(report.data)返回字段: (date-time), (uuid), (uuid), (object), (string), (enum: export_portouts_csv), (enum: pending, completed), (date-time)
created_atdocument_ididparamsrecord_typereport_typestatusupdated_atRetrieve a report
查询单个报表
Retrieve a specific report generated.
GET /portouts/reports/{id}python
report = client.portouts.reports.retrieve(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(report.data)Returns: (date-time), (uuid), (uuid), (object), (string), (enum: export_portouts_csv), (enum: pending, completed), (date-time)
created_atdocument_ididparamsrecord_typereport_typestatusupdated_at查询指定的生成报表详情
GET /portouts/reports/{id}python
report = client.portouts.reports.retrieve(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(report.data)返回字段: (date-time), (uuid), (uuid), (object), (string), (enum: export_portouts_csv), (enum: pending, completed), (date-time)
created_atdocument_ididparamsrecord_typereport_typestatusupdated_atGet a portout request
查询单个portout请求
Returns the portout request based on the ID provided
GET /portouts/{id}python
portout = client.portouts.retrieve(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(portout.data)Returns: (boolean), (string), (string), (string), (string), (string), (string), (string), (boolean), (string), (string), (array[string]), (array[string]), (string), (string | null), (string), (integer), (string), (string), (string), (string), (enum: pending, authorized, ported, rejected, rejected-pending, canceled), (string), (string), (uuid), (uuid), (string)
already_portedauthorized_namecarrier_namecitycreated_atcurrent_carrierend_user_namefoc_datehost_messagingidinserted_atlsrphone_numbersponreasonrecord_typerejection_coderequested_foc_dateservice_addressspidstatestatussupport_keyupdated_atuser_idvendorzip根据传入的ID返回对应的portout请求详情
GET /portouts/{id}python
portout = client.portouts.retrieve(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(portout.data)返回字段: (boolean), (string), (string), (string), (string), (string), (string), (string), (boolean), (string), (string), (array[string]), (array[string]), (string), (string | null), (string), (integer), (string), (string), (string), (string), (enum: pending, authorized, ported, rejected, rejected-pending, canceled), (string), (string), (uuid), (uuid), (string)
already_portedauthorized_namecarrier_namecitycreated_atcurrent_carrierend_user_namefoc_datehost_messagingidinserted_atlsrphone_numbersponreasonrecord_typerejection_coderequested_foc_dateservice_addressspidstatestatussupport_keyupdated_atuser_idvendorzipList all comments for a portout request
列出portout请求的所有评论
Returns a list of comments for a portout request.
GET /portouts/{id}/commentspython
comments = client.portouts.comments.list(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(comments.data)Returns: (string), (string), (string), (string), (string), (string)
bodycreated_atidportout_idrecord_typeuser_id返回指定portout请求的评论列表
GET /portouts/{id}/commentspython
comments = client.portouts.comments.list(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(comments.data)返回字段: (string), (string), (string), (string), (string), (string)
bodycreated_atidportout_idrecord_typeuser_idCreate a comment on a portout request
为portout请求添加评论
Creates a comment on a portout request.
POST /portouts/{id}/commentsOptional: (string)
bodypython
comment = client.portouts.comments.create(
id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(comment.data)Returns: (string), (string), (string), (string), (string), (string)
bodycreated_atidportout_idrecord_typeuser_id为指定portout请求创建一条评论
POST /portouts/{id}/comments可选参数: (string)
bodypython
comment = client.portouts.comments.create(
id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(comment.data)返回字段: (string), (string), (string), (string), (string), (string)
bodycreated_atidportout_idrecord_typeuser_idList supporting documents on a portout request
列出portout请求的支持文件
List every supporting documents for a portout request.
GET /portouts/{id}/supporting_documentspython
supporting_documents = client.portouts.supporting_documents.list(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(supporting_documents.data)Returns: (string), (uuid), (uuid), (uuid), (string), (enum: loa, invoice), (string)
created_atdocument_ididportout_idrecord_typetypeupdated_at列出指定portout请求的所有支持文件
GET /portouts/{id}/supporting_documentspython
supporting_documents = client.portouts.supporting_documents.list(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(supporting_documents.data)返回字段: (string), (uuid), (uuid), (uuid), (string), (enum: loa, invoice), (string)
created_atdocument_ididportout_idrecord_typetypeupdated_atCreate a list of supporting documents on a portout request
为portout请求添加支持文件
Creates a list of supporting documents on a portout request.
POST /portouts/{id}/supporting_documentsOptional: (array[object])
documentspython
supporting_document = client.portouts.supporting_documents.create(
id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(supporting_document.data)Returns: (string), (uuid), (uuid), (uuid), (string), (enum: loa, invoice), (string)
created_atdocument_ididportout_idrecord_typetypeupdated_at为指定portout请求批量添加支持文件
POST /portouts/{id}/supporting_documents可选参数: (array[object])
documentspython
supporting_document = client.portouts.supporting_documents.create(
id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(supporting_document.data)返回字段: (string), (uuid), (uuid), (uuid), (string), (enum: loa, invoice), (string)
created_atdocument_ididportout_idrecord_typetypeupdated_atUpdate Status
更新状态
Authorize or reject portout request
PATCH /portouts/{id}/{status}reasonOptional: (boolean)
host_messagingpython
response = client.portouts.update_status(
status="authorized",
id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
reason="I do not recognize this transaction",
)
print(response.data)Returns: (boolean), (string), (string), (string), (string), (string), (string), (string), (boolean), (string), (string), (array[string]), (array[string]), (string), (string | null), (string), (integer), (string), (string), (string), (string), (enum: pending, authorized, ported, rejected, rejected-pending, canceled), (string), (string), (uuid), (uuid), (string)
already_portedauthorized_namecarrier_namecitycreated_atcurrent_carrierend_user_namefoc_datehost_messagingidinserted_atlsrphone_numbersponreasonrecord_typerejection_coderequested_foc_dateservice_addressspidstatestatussupport_keyupdated_atuser_idvendorzip授权或拒绝portout请求
PATCH /portouts/{id}/{status}reason可选参数: (boolean)
host_messagingpython
response = client.portouts.update_status(
status="authorized",
id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
reason="I do not recognize this transaction",
)
print(response.data)返回字段: (boolean), (string), (string), (string), (string), (string), (string), (string), (boolean), (string), (string), (array[string]), (array[string]), (string), (string | null), (string), (integer), (string), (string), (string), (string), (enum: pending, authorized, ported, rejected, rejected-pending, canceled), (string), (string), (uuid), (uuid), (string)
already_portedauthorized_namecarrier_namecitycreated_atcurrent_carrierend_user_namefoc_datehost_messagingidinserted_atlsrphone_numbersponreasonrecord_typerejection_coderequested_foc_dateservice_addressspidstatestatussupport_keyupdated_atuser_idvendorzip