$npx -y skills add team-telnyx/ai --skill telnyx-numbers-config-pythonConfigure phone number settings including caller ID, call forwarding, messaging enablement, and connection assignments. This skill provides Python SDK examples.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Numbers Config - Python |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```bash |
| 8 | pip install telnyx |
| 9 | ``` |
| 10 | |
| 11 | ## Setup |
| 12 | |
| 13 | ```python |
| 14 | import os |
| 15 | from telnyx import Telnyx |
| 16 | |
| 17 | client = Telnyx( |
| 18 | api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted |
| 19 | ) |
| 20 | ``` |
| 21 | |
| 22 | All examples below assume `client` is already initialized as shown above. |
| 23 | |
| 24 | ## Error Handling |
| 25 | |
| 26 | All API calls can fail with network errors, rate limits (429), validation errors (422), |
| 27 | or authentication errors (401). Always handle errors in production code: |
| 28 | |
| 29 | ```python |
| 30 | import telnyx |
| 31 | |
| 32 | try: |
| 33 | result = client.messages.send(to="+13125550001", from_="+13125550002", text="Hello") |
| 34 | except telnyx.APIConnectionError: |
| 35 | print("Network error — check connectivity and retry") |
| 36 | except telnyx.RateLimitError: |
| 37 | # 429: rate limited — wait and retry with exponential backoff |
| 38 | import time |
| 39 | time.sleep(1) # Check Retry-After header for actual delay |
| 40 | except telnyx.APIStatusError as e: |
| 41 | print(f"API error {e.status_code}: {e.message}") |
| 42 | if e.status_code == 422: |
| 43 | print("Validation error — check required fields and formats") |
| 44 | ``` |
| 45 | |
| 46 | Common error codes: `401` invalid API key, `403` insufficient permissions, |
| 47 | `404` resource not found, `422` validation error (check field formats), |
| 48 | `429` rate limited (retry with exponential backoff). |
| 49 | |
| 50 | ## Important Notes |
| 51 | |
| 52 | - **Phone numbers** must be in E.164 format (e.g., `+13125550001`). Include the `+` prefix and country code. No spaces, dashes, or parentheses. |
| 53 | - **Pagination:** List methods return an auto-paginating iterator. Use `for item in page_result:` to iterate through all pages automatically. |
| 54 | |
| 55 | ## Bulk update phone number profiles |
| 56 | |
| 57 | `POST /messaging_numbers_bulk_updates` — Required: `messaging_profile_id`, `numbers` |
| 58 | |
| 59 | Optional: `assign_only` (boolean) |
| 60 | |
| 61 | ```python |
| 62 | messaging_numbers_bulk_update = client.messaging_numbers_bulk_updates.create( |
| 63 | messaging_profile_id="00000000-0000-0000-0000-000000000000", |
| 64 | numbers=["+18880000000", "+18880000001", "+18880000002"], |
| 65 | ) |
| 66 | print(messaging_numbers_bulk_update.data) |
| 67 | ``` |
| 68 | |
| 69 | Returns: `failed` (array[string]), `order_id` (uuid), `pending` (array[string]), `record_type` (enum: messaging_numbers_bulk_update), `success` (array[string]) |
| 70 | |
| 71 | ## Retrieve bulk update status |
| 72 | |
| 73 | `GET /messaging_numbers_bulk_updates/{order_id}` |
| 74 | |
| 75 | ```python |
| 76 | messaging_numbers_bulk_update = client.messaging_numbers_bulk_updates.retrieve( |
| 77 | "order_id", |
| 78 | ) |
| 79 | print(messaging_numbers_bulk_update.data) |
| 80 | ``` |
| 81 | |
| 82 | Returns: `failed` (array[string]), `order_id` (uuid), `pending` (array[string]), `record_type` (enum: messaging_numbers_bulk_update), `success` (array[string]) |
| 83 | |
| 84 | ## List mobile phone numbers with messaging settings |
| 85 | |
| 86 | `GET /mobile_phone_numbers/messaging` |
| 87 | |
| 88 | ```python |
| 89 | page = client.mobile_phone_numbers.messaging.list() |
| 90 | page = page.data[0] |
| 91 | print(page.id) |
| 92 | ``` |
| 93 | |
| 94 | Returns: `country_code` (string), `created_at` (date-time), `features` (object), `id` (string), `messaging_product` (string), `messaging_profile_id` (string | null), `organization_id` (string), `phone_number` (string), `record_type` (enum: messaging_phone_number, messaging_settings), `tags` (array[string]), `traffic_type` (string), `type` (enum: longcode), `updated_at` (date-time) |
| 95 | |
| 96 | ## Retrieve a mobile phone number with messaging settings |
| 97 | |
| 98 | `GET /mobile_phone_numbers/{id}/messaging` |
| 99 | |
| 100 | ```python |
| 101 | messaging = client.mobile_phone_numbers.messaging.retrieve( |
| 102 | "id", |
| 103 | ) |
| 104 | print(messaging.data) |
| 105 | ``` |
| 106 | |
| 107 | Returns: `country_code` (string), `created_at` (date-time), `features` (object), `id` (string), `messaging_product` (string), `messaging_profile_id` (string | null), `organization_id` (string), `phone_number` (string), `record_type` (enum: messaging_phone_number, messaging_settings), `tags` (array[string]), `traffic_type` (string), `type` (enum: longcode), `updated_at` (date-time) |
| 108 | |
| 109 | ## List phone numbers |
| 110 | |
| 111 | `GET /phone_numbers` |
| 112 | |
| 113 | ```python |
| 114 | page = client.phone_numbers.list() |
| 115 | page = page.data[0] |
| 116 | print(page.id) |
| 117 | ``` |
| 118 | |
| 119 | Returns: `billing_group_id` (string | null), `call_forwarding_enabled` (boolean), `call_recording_enabled` (boolean), `caller_id_name_enabled` (boolean), `cnam_listing_enabled` (boolean), `connection_id` (string | null), `connection_name` (string | null), `country_iso_alpha2` (string), `created_at` (date-time), `customer_reference` (string | null), `deletion_lock_enabled` (boolean), `emergency_address_id` (string | null), `emergency_enabled` (boolean), `emergency_status` (enum: active, deprovisioning, disabled, provisioning, provisioning-failed), `external_pin` (string | null), `hd_voice_enabled` (boolean), `id` (string), `inbound_call_screening` (enum: disabled, reject_calls, flag_calls), `messaging |