# List available phone numbers

GET https://services.leadconnectorhq.com/phone-system/numbers/location/{locationId}/available

Search Twilio inventory for purchasable phone numbers in a country for the given location.

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `phonenumbers.read`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | API Version |

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `locationId` | string | Yes | Location ID as string |

### Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `firstPart` | string | Yes | firstPart is the beginning of the phone number |
| `lastPart` | string | Yes | lastPart is the ending of the phone number |
| `anywhere` | string | Yes | anywhere are the numbers required anywhere in phone number |
| `numberTypes` | array | Yes | comma separated types of phone number required |
| `smsEnabled` | boolean | Yes | requested phone numbers should have sms functionality |
| `mmsEnabled` | boolean | Yes | requested phone numbers should have mms functionality |
| `voiceEnabled` | boolean | Yes | requested phone numbers should have voice functionality |
| `countryCode` | string | Yes | country for which the phone numbers are being requested |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/phone-system/numbers/location/{locationId}/available": {
      "get": {
        "summary": "List available phone numbers",
        "operationId": "listAvailablePhoneNumbers",
        "description": "Search Twilio inventory for purchasable phone numbers in a country for the given location.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "required": true,
            "description": "API Version",
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "firstPart",
            "required": true,
            "in": "query",
            "description": "firstPart is the beginning of the phone number",
            "schema": {
              "type": "string",
              "example": "830"
            }
          },
          {
            "name": "lastPart",
            "required": true,
            "in": "query",
            "description": "lastPart is the ending of the phone number",
            "schema": {
              "type": "string",
              "example": "825"
            }
          },
          {
            "name": "anywhere",
            "required": true,
            "in": "query",
            "description": "anywhere are the numbers required anywhere in phone number",
            "schema": {
              "type": "string",
              "example": "825"
            }
          },
          {
            "name": "numberTypes",
            "required": true,
            "in": "query",
            "description": "comma separated types of phone number required",
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "example": "tollFree,mobile,local"
            }
          },
          {
            "name": "smsEnabled",
            "required": true,
            "in": "query",
            "description": "requested phone numbers should have sms functionality",
            "schema": {
              "type": "boolean",
              "example": "true"
            }
          },
          {
            "name": "mmsEnabled",
            "required": true,
            "in": "query",
            "description": "requested phone numbers should have mms functionality",
            "schema": {
              "type": "boolean",
              "example": "true"
            }
          },
          {
            "name": "voiceEnabled",
            "required": true,
            "in": "query",
            "description": "requested phone numbers should have voice functionality",
            "schema": {
              "type": "boolean",
              "example": "true"
            }
          },
          {
            "name": "countryCode",
            "required": true,
            "in": "query",
            "description": "country for which the phone numbers are being requested",
            "schema": {
              "type": "string",
              "example": "US"
            }
          },
          {
            "name": "locationId",
            "required": true,
            "in": "path",
            "description": "Location ID as string",
            "schema": {
              "type": "string",
              "example": "tDtDnQdgm2LXpyiqYvZ6"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Available phone numbers matching the search criteria."
          }
        },
        "security": [
          {
            "Location-Access": [
              "phonenumbers.read"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account.",
        "type": "http"
      },
      "Agency-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency (OR) Private Integration Token of Agency.",
        "type": "http"
      },
      "Agency-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency.",
        "type": "http"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X GET 'https://services.leadconnectorhq.com/phone-system/numbers/location/<locationId>/available?firstPart=<FIRSTPART>&lastPart=<LASTPART>&anywhere=<ANYWHERE>&numberTypes=<NUMBERTYPES>&smsEnabled=<SMSENABLED>&mmsEnabled=<MMSENABLED>&voiceEnabled=<VOICEENABLED>&countryCode=<COUNTRYCODE>' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3'
```

**Node.js**

```javascript
const options = {
  method: 'GET',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3'
  }
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/phone-system/numbers/location/<locationId>/available?firstPart=<FIRSTPART>&lastPart=<LASTPART>&anywhere=<ANYWHERE>&numberTypes=<NUMBERTYPES>&smsEnabled=<SMSENABLED>&mmsEnabled=<MMSENABLED>&voiceEnabled=<VOICEENABLED>&countryCode=<COUNTRYCODE>', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/phone-system/numbers/location/{locationId}/available"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

params = {
    "firstPart": "<FIRSTPART>",
    "lastPart": "<LASTPART>",
    "anywhere": "<ANYWHERE>",
    "numberTypes": "<NUMBERTYPES>",
    "smsEnabled": "<SMSENABLED>",
    "mmsEnabled": "<MMSENABLED>",
    "voiceEnabled": "<VOICEENABLED>",
    "countryCode": "<COUNTRYCODE>"
}

response = requests.get(url, params=params, headers=headers)
print(response.json())
```

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/phone-system/numbers/location/<locationId>/available?firstPart=<FIRSTPART>&lastPart=<LASTPART>&anywhere=<ANYWHERE>&numberTypes=<NUMBERTYPES>&smsEnabled=<SMSENABLED>&mmsEnabled=<MMSENABLED>&voiceEnabled=<VOICEENABLED>&countryCode=<COUNTRYCODE>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
  ],
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .get("https://services.leadconnectorhq.com/phone-system/numbers/location/<locationId>/available?firstPart=<FIRSTPART>&lastPart=<LASTPART>&anywhere=<ANYWHERE>&numberTypes=<NUMBERTYPES>&smsEnabled=<SMSENABLED>&mmsEnabled=<MMSENABLED>&voiceEnabled=<VOICEENABLED>&countryCode=<COUNTRYCODE>")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .asString();
```

**Go**

```go
package main

import (
  "fmt"
  "net/http"
  "io"
)

func main() {
  url := "https://services.leadconnectorhq.com/phone-system/numbers/location/<locationId>/available?firstPart=<FIRSTPART>&lastPart=<LASTPART>&anywhere=<ANYWHERE>&numberTypes=<NUMBERTYPES>&smsEnabled=<SMSENABLED>&mmsEnabled=<MMSENABLED>&voiceEnabled=<VOICEENABLED>&countryCode=<COUNTRYCODE>"
  req, _ := http.NewRequest("GET", url, nil)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/phone-system/numbers/location/<locationId>/available?firstPart=<FIRSTPART>&lastPart=<LASTPART>&anywhere=<ANYWHERE>&numberTypes=<NUMBERTYPES>&smsEnabled=<SMSENABLED>&mmsEnabled=<MMSENABLED>&voiceEnabled=<VOICEENABLED>&countryCode=<COUNTRYCODE>")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/phone-system/numbers/location/<locationId>/available?firstPart=<FIRSTPART>&lastPart=<LASTPART>&anywhere=<ANYWHERE>&numberTypes=<NUMBERTYPES>&smsEnabled=<SMSENABLED>&mmsEnabled=<MMSENABLED>&voiceEnabled=<VOICEENABLED>&countryCode=<COUNTRYCODE>' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
```
