$npx -y skills add team-telnyx/ai --skill telnyx-numbers-goSearch, order, and manage phone numbers by location, features, and coverage.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Numbers - Go |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```bash |
| 8 | go get github.com/team-telnyx/telnyx-go |
| 9 | ``` |
| 10 | |
| 11 | ## Setup |
| 12 | |
| 13 | ```go |
| 14 | import ( |
| 15 | "context" |
| 16 | "fmt" |
| 17 | "os" |
| 18 | |
| 19 | "github.com/team-telnyx/telnyx-go" |
| 20 | "github.com/team-telnyx/telnyx-go/option" |
| 21 | ) |
| 22 | |
| 23 | client := telnyx.NewClient( |
| 24 | option.WithAPIKey(os.Getenv("TELNYX_API_KEY")), |
| 25 | ) |
| 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 | ```go |
| 36 | import "errors" |
| 37 | |
| 38 | availablePhoneNumbers, err := client.AvailablePhoneNumbers.List(context.Background(), telnyx.AvailablePhoneNumberListParams{}) |
| 39 | if err != nil { |
| 40 | var apiErr *telnyx.Error |
| 41 | if errors.As(err, &apiErr) { |
| 42 | switch apiErr.StatusCode { |
| 43 | case 422: |
| 44 | fmt.Println("Validation error — check required fields and formats") |
| 45 | case 429: |
| 46 | fmt.Println("Rate limited, retrying...") |
| 47 | default: |
| 48 | fmt.Printf("API error %d: %s\n", apiErr.StatusCode, apiErr.Error()) |
| 49 | } |
| 50 | } else { |
| 51 | fmt.Println("Network error — check connectivity and retry") |
| 52 | } |
| 53 | } |
| 54 | ``` |
| 55 | |
| 56 | Common error codes: `401` invalid API key, `403` insufficient permissions, |
| 57 | `404` resource not found, `422` validation error (check field formats), |
| 58 | `429` rate limited (retry with exponential backoff). |
| 59 | |
| 60 | ## Important Notes |
| 61 | |
| 62 | - **Phone numbers** must be in E.164 format (e.g., `+13125550001`). Include the `+` prefix and country code. No spaces, dashes, or parentheses. |
| 63 | - **Pagination:** Use `ListAutoPaging()` for automatic iteration: `iter := client.Resource.ListAutoPaging(ctx, params); for iter.Next() { item := iter.Current() }`. |
| 64 | |
| 65 | ## Reference Use Rules |
| 66 | |
| 67 | Do not invent Telnyx parameters, enums, response fields, or webhook fields. |
| 68 | |
| 69 | - 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. |
| 70 | - 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). |
| 71 | |
| 72 | ## Core Tasks |
| 73 | |
| 74 | ### Search available phone numbers |
| 75 | |
| 76 | Number search is the entrypoint for provisioning. Agents need the search method, key query filters, and the fields returned for candidate numbers. |
| 77 | |
| 78 | `client.AvailablePhoneNumbers.List()` — `GET /available_phone_numbers` |
| 79 | |
| 80 | | Parameter | Type | Required | Description | |
| 81 | |-----------|------|----------|-------------| |
| 82 | | `Filter` | object | No | Consolidated filter parameter (deepObject style). | |
| 83 | |
| 84 | ```go |
| 85 | availablePhoneNumbers, err := client.AvailablePhoneNumbers.List(context.Background(), telnyx.AvailablePhoneNumberListParams{}) |
| 86 | if err != nil { |
| 87 | log.Fatal(err) |
| 88 | } |
| 89 | fmt.Printf("%+v\n", availablePhoneNumbers.Data) |
| 90 | ``` |
| 91 | |
| 92 | Response wrapper: |
| 93 | - items: `availablePhoneNumbers.data` |
| 94 | - pagination: `availablePhoneNumbers.meta` |
| 95 | |
| 96 | Primary item fields: |
| 97 | - `PhoneNumber` |
| 98 | - `RecordType` |
| 99 | - `Quickship` |
| 100 | - `Reservable` |
| 101 | - `BestEffort` |
| 102 | - `CostInformation` |
| 103 | |
| 104 | ### Create a number order |
| 105 | |
| 106 | Number ordering is the production provisioning step after number selection. |
| 107 | |
| 108 | `client.NumberOrders.New()` — `POST /number_orders` |
| 109 | |
| 110 | | Parameter | Type | Required | Description | |
| 111 | |-----------|------|----------|-------------| |
| 112 | | `PhoneNumbers` | array[object] | Yes | | |
| 113 | | `ConnectionId` | string (UUID) | No | Identifies the connection associated with this phone number. | |
| 114 | | `MessagingProfileId` | string (UUID) | No | Identifies the messaging profile associated with the phone n... | |
| 115 | | `BillingGroupId` | string (UUID) | No | Identifies the billing group associated with the phone numbe... | |
| 116 | | ... | | | +1 optional params in [references/api-details.md](references/api-details.md) | |
| 117 | |
| 118 | ```go |
| 119 | numberOrder, err := client.NumberOrders.New(context.Background(), telnyx.NumberOrderNewParams{ |
| 120 | PhoneNumbers: []telnyx.NumberOrderNewParamsPhoneNumber{{PhoneNumber: "+18005550101"}}, |
| 121 | }) |
| 122 | if err != nil { |
| 123 | log.Fatal(err) |
| 124 | } |
| 125 | fmt.Printf("%+v\n", numberOrder.Data) |
| 126 | ``` |
| 127 | |
| 128 | Primary response fields: |
| 129 | - `numberOrder.Data.ID` |
| 130 | - `numberOrder.Data.Status` |
| 131 | - `numberOrder.Data.PhoneNumbersCount` |
| 132 | - `numberOrder.Data.RequirementsMet` |
| 133 | - `numberOrder.Data.MessagingProfileID` |
| 134 | - `numberOrder.Data.ConnectionID` |
| 135 | |
| 136 | ### Check number order status |
| 137 | |
| 138 | Order status determines whether provisioning completed or additional requirements are still blocking fulfillment. |
| 139 | |
| 140 | `client.NumberOrders.Get()` — `GET /number_orders/{number_order_id}` |
| 141 | |
| 142 | | Parameter | Type | Required | Description | |
| 143 | |-----------|------|----------|-------------| |
| 144 | | `NumberOrderId` | string (UUID) | Yes | The number order ID. | |
| 145 | |
| 146 | ```go |
| 147 | numberOrder, err : |