# Phone validation

```http
POST https://api.qelka.com/v1/phone
```

Validates a phone number against its country's numbering plan and describes it. Costs 1 credit at the `basic` level and 3 credits at the `live` level. Errors are not billed.

The API never returns the name or address of the person or company behind a number.

## Request

```json
{
  "phone": "+14155550123",
  "country": "US",
  "level": "basic",
  "fresh": false
}
```

| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| `phone` | string | Yes | none | The number to check, 1 to 64 characters, in any common format: `+1 415-555-0123`, `(415) 555-0123`, `+14155550123`. E.164 is recommended. A number written with the `00` international prefix, such as `00 44 7400 123456`, is read like one starting with `+`. |
| `country` | string | No | none | ISO 3166-1 alpha-2 code such as `US`, `GB` or `FR`, in either case. Tells the API how to read a number written without a `+` prefix. Not needed when the number starts with `+`. |
| `level` | string | No | `basic` | `basic` reads the numbering plan. `live` also asks the network for the current carrier and porting status. |
| `fresh` | boolean | No | `false` | `true` skips the 7-day result cache and runs the checks again. |

## Levels

| What | `basic` | `live` |
|---|---|---|
| Credits | 1 | 3 |
| Source | Numbering plan data from Google's libphonenumber | An upstream number-lookup provider, queried at the time of the call |
| Validity, formats, country, region, time zones, line type | Yes | Yes |
| Carrier | The carrier the number range was originally assigned to | The carrier currently serving the number |
| `carrier.mcc` and `carrier.mnc` | `null` | Mobile country and network codes |
| `ported` | `null` | `true` or `false` |
| `carrier.source` | `numbering_plan` | `live` |
| When the provider fails | Not applicable | `502 upstream_unavailable`, not billed |

The basic level reads the plan, not the network: it cannot see that a number was ported to another carrier or that it was disconnected. When the current carrier matters, for example to route messages through the right network, use `live`.

A live lookup sends the phone number to our live lookup provider, Telnyx. At the basic level, the number is not sent to any lookup provider. See [Data and privacy](/docs/data-and-privacy).

## Response

```json
{
  "id": "lkp_01M84BPXA0RJ291DEC04H84EKA",
  "object": "phone",
  "input": "+14155550123",
  "valid": true,
  "status": "valid",
  "e164": "+14155550123",
  "national": "(415) 555-0123",
  "country": { "code": "US", "name": "United States", "calling_code": "1" },
  "region": "California",
  "timezones": ["America/Los_Angeles"],
  "line_type": "fixed_line_or_mobile",
  "carrier": { "name": null, "mcc": null, "mnc": null, "source": "numbering_plan" },
  "ported": null,
  "credits_used": 1,
  "cached": false
}
```

| Field | Type | Description |
|---|---|---|
| `id` | string | Identifier of this lookup: `lkp_` and 26 characters. |
| `object` | string | Always `phone`. |
| `input` | string | The `phone` value you sent. |
| `valid` | boolean | `true` when the number is valid in its country's numbering plan. |
| `status` | string | `valid`, `invalid` or `unknown`. See [statuses](#statuses). |
| `e164` | string or null | The number in E.164 format, such as `+14155550123`. Null unless `status` is `valid`. |
| `national` | string or null | The number formatted the way it is written inside its country, such as `(415) 555-0123`. Null unless `status` is `valid`. |
| `country` | object or null | The country the number belongs to. Null when it cannot be determined, for example when `status` is `unknown`. |
| `country.code` | string | ISO 3166-1 alpha-2 code, such as `US`. |
| `country.name` | string | English short name of the country. |
| `country.calling_code` | string | Country calling code without the `+`, such as `1` or `44`. |
| `region` | string or null | Area of the number range in the numbering plan, such as a US state. Null when the plan does not tie the number to an area, as for most mobile numbers, and when the number is not valid. |
| `timezones` | array of strings | IANA time zones of the number range, such as `America/Los_Angeles`. Can hold several zones when a range spans them. Empty when unknown or when the number is not valid. |
| `line_type` | string | Type of line. See [line types](#line-types). |
| `carrier` | object or null | Carrier information. Null unless `status` is `valid`. |
| `carrier.name` | string or null | At the basic level, the carrier the range was originally assigned to; null when the numbering plan data names none. At the live level, the carrier currently serving the number. |
| `carrier.mcc` | string or null | Mobile country code (ITU-T E.212). Live level only; always null at the basic level. |
| `carrier.mnc` | string or null | Mobile network code (ITU-T E.212). Live level only; always null at the basic level. |
| `carrier.source` | string | `numbering_plan` for the original range holder, `live` for the current carrier. |
| `ported` | boolean or null | `true` when the number has been ported away from the carrier its range was assigned to. Live level only; null at the basic level, which cannot detect porting. |
| `credits_used` | integer | Credits debited for this call. |
| `cached` | boolean | `true` when the result was served from the 7-day cache. |

## Statuses

| `status` | `valid` | Meaning | What to do |
|---|---|---|---|
| `valid` | `true` | The number is valid in its numbering plan. | Store `e164`. |
| `invalid` | `false` | The number does not fit the numbering plan, such as a wrong length or a prefix the plan does not use, or the input is not a phone number at all. | Ask the person to check the number. |
| `unknown` | `false` | The number was written without a `+` prefix and no `country` was sent, so it cannot be read. | Send `country` with the request. |

A `valid` number exists in the numbering plan; it is not proof that someone answers it. The basic level cannot see disconnected numbers.

## Line types

| `line_type` | Meaning |
|---|---|
| `mobile` | Mobile number. |
| `landline` | Fixed, geographic line. |
| `fixed_line_or_mobile` | The numbering plan does not separate landlines from mobiles. This is the case of the North American Numbering Plan, which covers the US and Canada. |
| `voip` | Number from a range assigned to internet telephony. |
| `toll_free` | Free for the caller, such as US numbers starting with 800. |
| `premium_rate` | The caller pays a higher rate. |
| `shared_cost` | The cost of the call is shared between caller and receiver. |
| `personal_number` | A personal number that forwards to other lines. |
| `pager` | Pager number. |
| `uan` | Universal access number: one number that routes to a company's offices. |
| `voicemail` | Direct access to a voicemail service. |
| `unknown` | The type could not be determined, or the number could not be read. |

## Examples

### Basic check

```bash
curl https://api.qelka.com/v1/phone \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"phone": "+14155550123"}'
```

```javascript
const response = await fetch('https://api.qelka.com/v1/phone', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ phone: '+14155550123' }),
})
const result = await response.json()
```

The response is the one shown above.

### A number in national format

A number typed the way people write it in their own country needs `country`:

```bash
curl https://api.qelka.com/v1/phone \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"phone": "07400 123456", "country": "GB"}'
```

The response has `e164` set to `+447400123456` and `line_type` set to `mobile`. Without `country`, the same input returns `status: "unknown"`.

### Live lookup

```bash
curl https://api.qelka.com/v1/phone \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"phone": "+14155550123", "level": "live"}'
```

```javascript
const response = await fetch('https://api.qelka.com/v1/phone', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ phone: '+14155550123', level: 'live' }),
})
const result = await response.json()
```

```json
{
  "id": "lkp_01M84BPZ037KMC9XHB5N9T5H0K",
  "object": "phone",
  "input": "+14155550123",
  "valid": true,
  "status": "valid",
  "e164": "+14155550123",
  "national": "(415) 555-0123",
  "country": { "code": "US", "name": "United States", "calling_code": "1" },
  "region": "California",
  "timezones": ["America/Los_Angeles"],
  "line_type": "mobile",
  "carrier": { "name": "Example Wireless", "mcc": "310", "mnc": "000", "source": "live" },
  "ported": false,
  "credits_used": 3,
  "cached": false
}
```

At the live level, the line type reported by the provider, when there is one, replaces the numbering plan's: here `fixed_line_or_mobile` became `mobile`.

Values in the examples are illustrative.

## Errors

| Status | Type | When |
|---|---|---|
| 400 | [invalid_request](/docs/errors#invalid_request) | `phone` is missing or longer than 64 characters, `country` is not two letters, `level` is not `basic` or `live`, or the body has a field that is not listed above |
| 401 | [invalid_api_key](/docs/errors#invalid_api_key) | The key is missing, invalid or revoked |
| 402 | [insufficient_credits](/docs/errors#insufficient_credits) | Your balance is below the cost of the call: 1 at the basic level, 3 at the live level |
| 403 | [forbidden](/docs/errors#forbidden) | The key is restricted to other endpoints |
| 429 | [rate_limited](/docs/errors#rate_limited) | Too many requests; wait `Retry-After` seconds |
| 500 | [internal_error](/docs/errors#internal_error) | Unexpected error on our side; retry with backoff |
| 502 | [upstream_unavailable](/docs/errors#upstream_unavailable) | Live level only: the carrier lookup provider failed. Retry later or use the basic level |

None of these responses is billed.

## Related

- [Format phone numbers in E.164](/docs/guides/format-phone-numbers-e164)
- [Validate signup forms](/docs/guides/validate-signup-forms)
- Free tools: [phone validator](/tools/phone-validator), [carrier lookup](/tools/carrier-lookup), [line type lookup](/tools/line-type-lookup), [phone number formatter](/tools/phone-number-formatter)
