> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes. # Search phone numbers GET https://%7BYour_Space_Name%7D.signalwire.com/api/relay/rest/phone_numbers/search Searches SignalWire's available inventory for local or toll-free phone numbers. Search results are candidates, not numbers your project owns; pass a selected result to [Purchase phone number](/docs/apis/rest/phone-numbers/purchase-phone-number). Use [List phone numbers](/docs/apis/rest/phone-numbers/list-phone-numbers) for owned numbers, or Compatibility [Available Phone Numbers](/docs/compatibility-api/rest/available-phone-numbers/search-local-available-phone-numbers) for form-encoded requests. #### Permissions The API token used to authenticate must have the following scope(s) enabled to make a successful request: _Numbers_. [Learn more about API scopes](/docs/platform/your-signalwire-api-space). Reference: https://signalwire.com/docs/apis/rest/phone-numbers/search-available-phone-numbers ## Authentication - `Authorization` header (basic auth, required) — SignalWire Basic Authentication using Project ID and API Token. The client sends HTTP requests with the Authorization header containing the word Basic followed by a space and a base64-encoded string of project_id:token. The project ID will be used as the username and the API token as the password. Example: ``` Authorization: Basic base64(project_id:token) ``` ## Request ### Query parameters - `areacode` (string, optional) — An areacode to search within. - `number_type` (string, optional) — Search for either local or toll-free numbers. Defaults to local. - `starts_with` (string, optional) — A string of 3 to 7 digits that should be used as the start of a number. Cannot be used in combination with contains or ends_with. - `contains` (string, optional) — A string of 3 to 7 digits that should appear somewhere in the number. Cannot be used in combination with starts_with or ends_with. - `ends_with` (string, optional) — A string of 3 to 7 digits that should be used as the end of a number. Cannot be used in combination with starts_with or contains. - `max_results` (integer, optional) — The maximum number of matches to return. Upper limit of 100. Defaults to 50. - `region` (string, optional) — A region or state to search within. Must be an ISO 3166-2 alpha-2 code, i.e. TX for Texas. Only supported for local searches; not supported when `number_type` is toll-free. - `city` (string, optional) — A specific City to search within. Must be used in combination with region. Only supported for local searches; not supported when `number_type` is toll-free. ## Response ### 200 The request has succeeded. - `links` (PaginationLinks, optional) — Pagination links. - `data` (list of AvailablePhoneNumber, optional) — List of available phone numbers. ## Errors ### 401 Unauthorized Error Access is unauthorized. - `error` (enum, required) - Allowed values: `Unauthorized` ### 500 Internal Server Error An internal server error occurred. - `error` (enum, required) - Allowed values: `Internal Server Error` ## Types ### PaginationLinks Pagination links for list responses. - `self` (string, required) — Link to the current page. - `first` (string, required) — Link to the first page. - `next` (string, optional) — Link to the next page. Only present when there are more results. - `prev` (string, optional) — Link to the previous page. Only present when not on the first page. ### AvailablePhoneNumber Available phone number for purchase. - `number` (string, required) — The phone number in E.164 format. - `region` (string, optional) — The region of the phone number. - `city` (string, optional) — The city of the phone number. - `rate_center` (string, optional) — The rate center of the phone number. - `lata` (string, optional) — The LATA of the phone number. - `capabilities` (PhoneNumberCapabilities, optional) — The capabilities of the phone number. ### PhoneNumberCapabilities Phone number capabilities. - `voice` (boolean, optional) — Whether the phone number can receive voice calls. - `sms` (boolean, optional) — Whether the phone number can send/receive SMS. - `mms` (boolean, optional) — Whether the phone number can send/receive MMS. - `fax` (boolean, optional) — Whether the phone number can send/receive fax. ## Examples **Response** ```json { "links": { "self": "string", "first": "string", "next": "string", "prev": "string" }, "data": [ { "number": "+15551234567", "region": "CA", "city": "Los Angeles", "rate_center": "string", "lata": "string", "capabilities": { "voice": true, "sms": true, "mms": true, "fax": true } } ] } ``` **SDK Code** ```python import requests url = "https://{your_space_name}.signalwire.com/api/relay/rest/phone_numbers/search" response = requests.get(url, auth=("", "")) print(response.json()) ``` ```javascript const url = 'https://{your_space_name}.signalwire.com/api/relay/rest/phone_numbers/search'; const credentials = btoa(":"); const options = {method: 'GET', headers: {Authorization: `Basic ${credentials}`}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://{your_space_name}.signalwire.com/api/relay/rest/phone_numbers/search" req, _ := http.NewRequest("GET", url, nil) req.SetBasicAuth("", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://{your_space_name}.signalwire.com/api/relay/rest/phone_numbers/search") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request.basic_auth("", "") response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://{your_space_name}.signalwire.com/api/relay/rest/phone_numbers/search") .basicAuth("", "") .asString(); ``` ```php request('GET', 'https://{your_space_name}.signalwire.com/api/relay/rest/phone_numbers/search', [ 'headers' => [ ], 'auth' => ['', ''], ]); echo $response->getBody(); ``` ```csharp using RestSharp; using RestSharp.Authenticators; var client = new RestClient("https://{your_space_name}.signalwire.com/api/relay/rest/phone_numbers/search"); client.Authenticator = new HttpBasicAuthenticator("", ""); var request = new RestRequest(Method.GET); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let credentials = Data(":".utf8).base64EncodedString() let headers = ["Authorization": "Basic \(credentials)"] let request = NSMutableURLRequest(url: NSURL(string: "https://{your_space_name}.signalwire.com/api/relay/rest/phone_numbers/search")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```