$npx -y skills add team-telnyx/ai --skill telnyx-numbers-javaSearch, order, and manage phone numbers by location, features, and coverage.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Numbers - Java |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```text |
| 8 | <!-- Maven --> |
| 9 | <dependency> |
| 10 | <groupId>com.telnyx.sdk</groupId> |
| 11 | <artifactId>telnyx</artifactId> |
| 12 | <version>6.82.0</version> |
| 13 | </dependency> |
| 14 | |
| 15 | // Gradle |
| 16 | implementation("com.telnyx.sdk:telnyx:6.82.0") |
| 17 | ``` |
| 18 | |
| 19 | ## Setup |
| 20 | |
| 21 | ```java |
| 22 | import com.telnyx.sdk.client.TelnyxClient; |
| 23 | import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient; |
| 24 | |
| 25 | TelnyxClient client = TelnyxOkHttpClient.fromEnv(); |
| 26 | ``` |
| 27 | |
| 28 | All examples below assume `client` is already initialized as shown above. |
| 29 | |
| 30 | ## Error Handling |
| 31 | |
| 32 | All API calls can fail with network errors, rate limits (429), validation errors (422), |
| 33 | or authentication errors (401). Always handle errors in production code: |
| 34 | |
| 35 | ```java |
| 36 | import com.telnyx.sdk.models.availablephonenumbers.AvailablePhoneNumberListParams; |
| 37 | import com.telnyx.sdk.models.availablephonenumbers.AvailablePhoneNumberListResponse; |
| 38 | AvailablePhoneNumberListResponse availablePhoneNumbers = client.availablePhoneNumbers().list(); |
| 39 | ``` |
| 40 | |
| 41 | Common error codes: `401` invalid API key, `403` insufficient permissions, |
| 42 | `404` resource not found, `422` validation error (check field formats), |
| 43 | `429` rate limited (retry with exponential backoff). |
| 44 | |
| 45 | ## Important Notes |
| 46 | |
| 47 | - **Phone numbers** must be in E.164 format (e.g., `+13125550001`). Include the `+` prefix and country code. No spaces, dashes, or parentheses. |
| 48 | - **Pagination:** List methods return a page. Use `.autoPager()` for automatic iteration: `for (var item : page.autoPager()) { ... }`. For manual control, use `.hasNextPage()` and `.nextPage()`. |
| 49 | |
| 50 | ## Reference Use Rules |
| 51 | |
| 52 | Do not invent Telnyx parameters, enums, response fields, or webhook fields. |
| 53 | |
| 54 | - If the parameter, enum, or response field you need is not shown inline in this skill, read [references/api-details.md](references/api-details.md) before writing code. |
| 55 | - Before using any operation in `## Additional Operations`, read [the optional-parameters section](references/api-details.md#optional-parameters) and [the response-schemas section](references/api-details.md#response-schemas). |
| 56 | |
| 57 | ## Core Tasks |
| 58 | |
| 59 | ### Search available phone numbers |
| 60 | |
| 61 | Number search is the entrypoint for provisioning. Agents need the search method, key query filters, and the fields returned for candidate numbers. |
| 62 | |
| 63 | `client.availablePhoneNumbers().list()` — `GET /available_phone_numbers` |
| 64 | |
| 65 | | Parameter | Type | Required | Description | |
| 66 | |-----------|------|----------|-------------| |
| 67 | | `filter` | object | No | Consolidated filter parameter (deepObject style). | |
| 68 | |
| 69 | ```java |
| 70 | import com.telnyx.sdk.models.availablephonenumbers.AvailablePhoneNumberListParams; |
| 71 | import com.telnyx.sdk.models.availablephonenumbers.AvailablePhoneNumberListResponse; |
| 72 | |
| 73 | AvailablePhoneNumberListResponse availablePhoneNumbers = client.availablePhoneNumbers().list(); |
| 74 | ``` |
| 75 | |
| 76 | Response wrapper: |
| 77 | - items: `availablePhoneNumbers.data` |
| 78 | - pagination: `availablePhoneNumbers.meta` |
| 79 | |
| 80 | Primary item fields: |
| 81 | - `phoneNumber` |
| 82 | - `recordType` |
| 83 | - `quickship` |
| 84 | - `reservable` |
| 85 | - `bestEffort` |
| 86 | - `costInformation` |
| 87 | |
| 88 | ### Create a number order |
| 89 | |
| 90 | Number ordering is the production provisioning step after number selection. |
| 91 | |
| 92 | `client.numberOrders().create()` — `POST /number_orders` |
| 93 | |
| 94 | | Parameter | Type | Required | Description | |
| 95 | |-----------|------|----------|-------------| |
| 96 | | `phoneNumbers` | array[object] | Yes | | |
| 97 | | `connectionId` | string (UUID) | No | Identifies the connection associated with this phone number. | |
| 98 | | `messagingProfileId` | string (UUID) | No | Identifies the messaging profile associated with the phone n... | |
| 99 | | `billingGroupId` | string (UUID) | No | Identifies the billing group associated with the phone numbe... | |
| 100 | | ... | | | +1 optional params in [references/api-details.md](references/api-details.md) | |
| 101 | |
| 102 | ```java |
| 103 | import com.telnyx.sdk.models.numberorders.NumberOrderCreateParams; |
| 104 | import com.telnyx.sdk.models.numberorders.NumberOrderCreateResponse; |
| 105 | |
| 106 | NumberOrderCreateParams params = NumberOrderCreateParams.builder() |
| 107 | |
| 108 | .addPhoneNumber( |
| 109 | |
| 110 | NumberOrderCreateParams.PhoneNumber.builder() |
| 111 | |
| 112 | .phoneNumber("+18005550101") |
| 113 | |
| 114 | .build() |
| 115 | |
| 116 | ) |
| 117 | |
| 118 | .build(); |
| 119 | |
| 120 | NumberOrderCreateResponse numberOrder = client.numberOrders().create(params); |
| 121 | ``` |
| 122 | |
| 123 | Primary response fields: |
| 124 | - `numberOrder.data.id` |
| 125 | - `numberOrder.data.status` |
| 126 | - `numberOrder.data.phoneNumbersCount` |
| 127 | - `numberOrder.data.requirementsMet` |
| 128 | - `numberOrder.data.messagingProfileId` |
| 129 | - `numberOrder.data.connectionId` |
| 130 | |
| 131 | ### Check number order status |
| 132 | |
| 133 | Order status determines whether provisioning completed or additional requirements are still blocking fulfillment. |
| 134 | |
| 135 | `client.numberOrders().retrieve()` — `GET /number_orders/{number_order_id}` |
| 136 | |
| 137 | | Parameter | Type | Required | Description | |
| 138 | |-----------|------|----------|----- |