$npx -y skills add team-telnyx/ai --skill telnyx-messaging-hosted-curlSet up hosted SMS numbers, toll-free verification, and RCS messaging. Use when migrating numbers or enabling rich messaging features. This skill provides REST API (curl) examples.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Messaging Hosted - curl |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```text |
| 8 | # curl is pre-installed on macOS, Linux, and Windows 10+ |
| 9 | ``` |
| 10 | |
| 11 | ## Setup |
| 12 | |
| 13 | ```bash |
| 14 | export TELNYX_API_KEY="YOUR_API_KEY_HERE" |
| 15 | ``` |
| 16 | |
| 17 | All examples below use `$TELNYX_API_KEY` for authentication. |
| 18 | |
| 19 | ## Error Handling |
| 20 | |
| 21 | All API calls can fail with network errors, rate limits (429), validation errors (422), |
| 22 | or authentication errors (401). Always handle errors in production code: |
| 23 | |
| 24 | ```bash |
| 25 | # Check HTTP status code in response |
| 26 | response=$(curl -s -w "\n%{http_code}" \ |
| 27 | -X POST "https://api.telnyx.com/v2/messages" \ |
| 28 | -H "Authorization: Bearer $TELNYX_API_KEY" \ |
| 29 | -H "Content-Type: application/json" \ |
| 30 | -d '{"to": "+13125550001", "from": "+13125550002", "text": "Hello"}') |
| 31 | |
| 32 | http_code=$(echo "$response" | tail -1) |
| 33 | body=$(echo "$response" | sed '$d') |
| 34 | |
| 35 | case $http_code in |
| 36 | 2*) echo "Success: $body" ;; |
| 37 | 422) echo "Validation error — check required fields and formats" ;; |
| 38 | 429) echo "Rate limited — retry after delay"; sleep 1 ;; |
| 39 | 401) echo "Authentication failed — check TELNYX_API_KEY" ;; |
| 40 | *) echo "Error $http_code: $body" ;; |
| 41 | esac |
| 42 | ``` |
| 43 | |
| 44 | Common error codes: `401` invalid API key, `403` insufficient permissions, |
| 45 | `404` resource not found, `422` validation error (check field formats), |
| 46 | `429` rate limited (retry with exponential backoff). |
| 47 | |
| 48 | ## Important Notes |
| 49 | |
| 50 | - **Phone numbers** must be in E.164 format (e.g., `+13125550001`). Include the `+` prefix and country code. No spaces, dashes, or parentheses. |
| 51 | - **Pagination:** List endpoints return paginated results. Use `page[number]` and `page[size]` query parameters to navigate pages. Check `meta.total_pages` in the response. |
| 52 | |
| 53 | ## Send an RCS message |
| 54 | |
| 55 | `POST /messages/rcs` — Required: `agent_id`, `to`, `messaging_profile_id`, `agent_message` |
| 56 | |
| 57 | Optional: `mms_fallback` (object), `sms_fallback` (object), `type` (enum: RCS), `webhook_url` (url) |
| 58 | |
| 59 | ```bash |
| 60 | curl \ |
| 61 | -X POST \ |
| 62 | -H "Authorization: Bearer $TELNYX_API_KEY" \ |
| 63 | -H "Content-Type: application/json" \ |
| 64 | -d '{ |
| 65 | "agent_id": "Agent007", |
| 66 | "to": "+13125551234", |
| 67 | "messaging_profile_id": "550e8400-e29b-41d4-a716-446655440000", |
| 68 | "agent_message": {} |
| 69 | }' \ |
| 70 | "https://api.telnyx.com/v2/messages/rcs" |
| 71 | ``` |
| 72 | |
| 73 | Returns: `body` (object), `direction` (string), `encoding` (string), `from` (object), `id` (string), `messaging_profile_id` (string), `organization_id` (string), `received_at` (date-time), `record_type` (string), `to` (array[object]), `type` (string), `wait_seconds` (float) |
| 74 | |
| 75 | ## Generate RCS deeplink |
| 76 | |
| 77 | Generate a deeplink URL that can be used to start an RCS conversation with a specific agent. |
| 78 | |
| 79 | `GET /messages/rcs/deeplinks/{agent_id}` |
| 80 | |
| 81 | ```bash |
| 82 | curl -H "Authorization: Bearer $TELNYX_API_KEY" "https://api.telnyx.com/v2/messages/rcs/deeplinks/{agent_id}?phone_number=%2B18445550001&body=hello%20world" |
| 83 | ``` |
| 84 | |
| 85 | Returns: `url` (string) |
| 86 | |
| 87 | ## List all RCS agents |
| 88 | |
| 89 | `GET /messaging/rcs/agents` |
| 90 | |
| 91 | ```bash |
| 92 | curl -H "Authorization: Bearer $TELNYX_API_KEY" "https://api.telnyx.com/v2/messaging/rcs/agents" |
| 93 | ``` |
| 94 | |
| 95 | Returns: `agent_id` (string), `agent_name` (string), `created_at` (date-time), `enabled` (boolean), `profile_id` (uuid), `updated_at` (date-time), `user_id` (string), `webhook_failover_url` (url), `webhook_url` (url) |
| 96 | |
| 97 | ## Retrieve an RCS agent |
| 98 | |
| 99 | `GET /messaging/rcs/agents/{id}` |
| 100 | |
| 101 | ```bash |
| 102 | curl -H "Authorization: Bearer $TELNYX_API_KEY" "https://api.telnyx.com/v2/messaging/rcs/agents/550e8400-e29b-41d4-a716-446655440000" |
| 103 | ``` |
| 104 | |
| 105 | Returns: `agent_id` (string), `agent_name` (string), `created_at` (date-time), `enabled` (boolean), `profile_id` (uuid), `updated_at` (date-time), `user_id` (string), `webhook_failover_url` (url), `webhook_url` (url) |
| 106 | |
| 107 | ## Modify an RCS agent |
| 108 | |
| 109 | `PATCH /messaging/rcs/agents/{id}` |
| 110 | |
| 111 | Optional: `profile_id` (uuid), `webhook_failover_url` (url), `webhook_url` (url) |
| 112 | |
| 113 | ```bash |
| 114 | curl \ |
| 115 | -X PATCH \ |
| 116 | -H "Authorization: Bearer $TELNYX_API_KEY" \ |
| 117 | -H "Content-Type: application/json" \ |
| 118 | "https://api.telnyx.com/v2/messaging/rcs/agents/550e8400-e29b-41d4-a716-446655440000" |
| 119 | ``` |
| 120 | |
| 121 | Returns: `agent_id` (string), `agent_name` (string), `created_at` (date-time), `enabled` (boolean), `profile_id` (uuid), `updated_at` (date-time), `user_id` (string), `webhook_failover_url` (url), `webhook_url` (url) |
| 122 | |
| 123 | ## Check RCS capabilities (batch) |
| 124 | |
| 125 | `POST /messaging/rcs/bulk_capabilities` — Required: `agent_id`, `phone_numbers` |
| 126 | |
| 127 | ```bash |
| 128 | curl \ |
| 129 | -X POST \ |
| 130 | -H "Authorization: Bearer $TELNYX_API_KEY" \ |
| 131 | -H "Content-Type: application/json" \ |
| 132 | -d '{ |
| 133 | "agent_id": "TestAgent", |
| 134 | "phone_numbers": [ |
| 135 | "+13125551234" |
| 136 | ] |
| 137 | }' \ |
| 138 | "https://api.telnyx.com/v2/messaging/rcs/bulk_capabilities" |
| 139 | ``` |
| 140 | |
| 141 | Returns: `agent_id` (st |