$npx -y skills add team-telnyx/ai --skill telnyx-numbers-compliance-javascriptManage regulatory requirements, number bundles, supporting documents, and verified numbers for compliance. This skill provides JavaScript SDK examples.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Numbers Compliance - JavaScript |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```bash |
| 8 | npm install telnyx |
| 9 | ``` |
| 10 | |
| 11 | ## Setup |
| 12 | |
| 13 | ```javascript |
| 14 | import Telnyx from 'telnyx'; |
| 15 | |
| 16 | const client = new Telnyx({ |
| 17 | apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted |
| 18 | }); |
| 19 | ``` |
| 20 | |
| 21 | All examples below assume `client` is already initialized as shown above. |
| 22 | |
| 23 | ## Error Handling |
| 24 | |
| 25 | All API calls can fail with network errors, rate limits (429), validation errors (422), |
| 26 | or authentication errors (401). Always handle errors in production code: |
| 27 | |
| 28 | ```javascript |
| 29 | try { |
| 30 | const result = await client.messages.send({ to: '+13125550001', from: '+13125550002', text: 'Hello' }); |
| 31 | } catch (err) { |
| 32 | if (err instanceof Telnyx.APIConnectionError) { |
| 33 | console.error('Network error — check connectivity and retry'); |
| 34 | } else if (err instanceof Telnyx.RateLimitError) { |
| 35 | // 429: rate limited — wait and retry with exponential backoff |
| 36 | const retryAfter = err.headers?.['retry-after'] || 1; |
| 37 | await new Promise(r => setTimeout(r, retryAfter * 1000)); |
| 38 | } else if (err instanceof Telnyx.APIError) { |
| 39 | console.error(`API error ${err.status}: ${err.message}`); |
| 40 | if (err.status === 422) { |
| 41 | console.error('Validation error — check required fields and formats'); |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | ``` |
| 46 | |
| 47 | Common error codes: `401` invalid API key, `403` insufficient permissions, |
| 48 | `404` resource not found, `422` validation error (check field formats), |
| 49 | `429` rate limited (retry with exponential backoff). |
| 50 | |
| 51 | ## Important Notes |
| 52 | |
| 53 | - **Phone numbers** must be in E.164 format (e.g., `+13125550001`). Include the `+` prefix and country code. No spaces, dashes, or parentheses. |
| 54 | - **Pagination:** List methods return an auto-paginating iterator. Use `for await (const item of result) { ... }` to iterate through all pages automatically. |
| 55 | |
| 56 | ## Retrieve Bundles |
| 57 | |
| 58 | Get all allowed bundles. |
| 59 | |
| 60 | `GET /bundle_pricing/billing_bundles` |
| 61 | |
| 62 | ```javascript |
| 63 | // Automatically fetches more pages as needed. |
| 64 | for await (const billingBundleSummary of client.bundlePricing.billingBundles.list()) { |
| 65 | console.log(billingBundleSummary.id); |
| 66 | } |
| 67 | ``` |
| 68 | |
| 69 | Returns: `cost_code` (string), `created_at` (date), `currency` (string), `id` (uuid), `is_public` (boolean), `mrc_price` (float), `name` (string), `slug` (string), `specs` (array[string]) |
| 70 | |
| 71 | ## Get Bundle By Id |
| 72 | |
| 73 | Get a single bundle by ID. |
| 74 | |
| 75 | `GET /bundle_pricing/billing_bundles/{bundle_id}` |
| 76 | |
| 77 | ```javascript |
| 78 | const billingBundle = await client.bundlePricing.billingBundles.retrieve( |
| 79 | '8661948c-a386-4385-837f-af00f40f111a', |
| 80 | ); |
| 81 | |
| 82 | console.log(billingBundle.data); |
| 83 | ``` |
| 84 | |
| 85 | Returns: `active` (boolean), `bundle_limits` (array[object]), `cost_code` (string), `created_at` (date), `id` (uuid), `is_public` (boolean), `name` (string), `slug` (string) |
| 86 | |
| 87 | ## Get User Bundles |
| 88 | |
| 89 | Get a paginated list of user bundles. |
| 90 | |
| 91 | `GET /bundle_pricing/user_bundles` |
| 92 | |
| 93 | ```javascript |
| 94 | // Automatically fetches more pages as needed. |
| 95 | for await (const userBundle of client.bundlePricing.userBundles.list()) { |
| 96 | console.log(userBundle.id); |
| 97 | } |
| 98 | ``` |
| 99 | |
| 100 | Returns: `active` (boolean), `billing_bundle` (object), `created_at` (date), `id` (uuid), `resources` (array[object]), `updated_at` (date), `user_id` (uuid) |
| 101 | |
| 102 | ## Create User Bundles |
| 103 | |
| 104 | Creates multiple user bundles for the user. |
| 105 | |
| 106 | `POST /bundle_pricing/user_bundles/bulk` |
| 107 | |
| 108 | Optional: `idempotency_key` (uuid), `items` (array[object]) |
| 109 | |
| 110 | ```javascript |
| 111 | const userBundle = await client.bundlePricing.userBundles.create(); |
| 112 | |
| 113 | console.log(userBundle.data); |
| 114 | ``` |
| 115 | |
| 116 | Returns: `active` (boolean), `billing_bundle` (object), `created_at` (date), `id` (uuid), `resources` (array[object]), `updated_at` (date), `user_id` (uuid) |
| 117 | |
| 118 | ## Get Unused User Bundles |
| 119 | |
| 120 | Returns all user bundles that aren't in use. |
| 121 | |
| 122 | `GET /bundle_pricing/user_bundles/unused` |
| 123 | |
| 124 | ```javascript |
| 125 | const response = await client.bundlePricing.userBundles.listUnused(); |
| 126 | |
| 127 | console.log(response.data); |
| 128 | ``` |
| 129 | |
| 130 | Returns: `billing_bundle` (object), `user_bundle_ids` (array[string]) |
| 131 | |
| 132 | ## Get User Bundle by Id |
| 133 | |
| 134 | Retrieves a user bundle by its ID. |
| 135 | |
| 136 | `GET /bundle_pricing/user_bundles/{user_bundle_id}` |
| 137 | |
| 138 | ```javascript |
| 139 | const userBundle = await client.bundlePricing.userBundles.retrieve( |
| 140 | 'ca1d2263-d1f1-43ac-ba53-248e7a4bb26a', |
| 141 | ); |
| 142 | |
| 143 | console.log(userBundle.data); |
| 144 | ``` |
| 145 | |
| 146 | Returns: `active` (boolean), `billing_bundle` (object), `created_at` (date), `id` (uuid), `resources` (array[object]), `updated_at` (date), `user_id` (uuid) |
| 147 | |
| 148 | ## Deactivate User Bundle |
| 149 | |
| 150 | Deactivates a user bundle by its ID. |
| 151 | |
| 152 | `DELETE /bundle_pricing/user_bundles/{user_bundle_id}` |
| 153 | |
| 154 | ```javascript |
| 155 | const response = await client.bundlePricing.userBundles.deactivate( |
| 156 | 'ca1d2263-d1f1-43ac-ba53-248e7a4bb26a', |
| 157 | ); |
| 158 | |
| 159 | console.log(response.data); |