# Email Validation

**GET** `/v1/emails`

Validates an email address and reports whether it is deliverable.

Requires an API Key licensed for email validation. A query over 320 characters is rejected.

A validated address decrements your lookup balance. An address the API cannot check returns `unknown` and costs no lookup. An address whose domain does not resolve, or publishes no MX records, returns `not_deliverable` and also costs no lookup. Only those two domain failures populate `suggestions`. Every other response returns an empty list.

## Example request

**URL**

```http
https://api.ideal-postcodes.co.uk/v1/emails?api_key=ak_test&query=foo@domain.com
```

**curl**

```bash
curl -G 'https://api.ideal-postcodes.co.uk/v1/emails' \
  -d 'api_key=ak_test' \
  --data-urlencode 'query=foo@domain.com'
```

**JavaScript**

```javascript
import { createIdpcClient, emailValidation } from '@ideal-postcodes/sdk';

const client = createIdpcClient({ apiKey: 'ak_test' });

const { data } = await emailValidation({
  client,
  query: { query: 'foo@domain.com' },
});
```

**Python**

```python
# pip install ideal-postcodes
from ideal_postcodes import IdealPostcodes

with IdealPostcodes("ak_test") as client:
    result = client.email_validation(query="foo@domain.com")
```

**Ruby**

```ruby
require "net/http"
require "json"

uri = URI("https://api.ideal-postcodes.co.uk/v1/emails")
uri.query = URI.encode_www_form(api_key: "ak_test", query: "foo@domain.com")
result = JSON.parse(Net::HTTP.get(uri))["result"]
```

**PHP**

```php
<?php
// composer require ideal-postcodes/sdk
use IdealPostcodes\IdealPostcodes;

$client = IdealPostcodes::client('ak_test');
$result = $client->emailValidation(['query' => 'foo@domain.com'])->result;
```

## Example response

**200 OK**

```json
{
  "result": {
    "result": "deliverable",
    "deliverable": true,
    "catchall": false,
    "free": false,
    "role": true,
    "disposable": false,
    "suggestions": []
  },
  "code": 2000,
  "message": "Success"
}
```

**400 Bad Request**

response.jsonjson

```json
{
  "code": 4000,
  "message": "Invalid Request"
}
```

## Query parameters

* `api_key` string optional

  **API Key**

  Your unique identifier that allows access to our APIs.

  Begins `ak_`. Available from your dashboard.

  Example: `ak_test`

* `query` string

  Specifies the email address to validate

* `tags` string optional

  **Tags**

  A comma separated list of tags to query over.

  Useful if you want to specify the circumstances in which the request was made.

  If you specify multiple tags, the response comprises only requests that satisfy all of them. Searching `"foo,bar"` queries only requests tagged both `"foo"` and `"bar"`.

  Example: `foo,bar`

## Response

`result` is a small, fixed object containing email validation attributes.

* `result` one of

  * Email

    | Field         | Type      | Description                                                                                                                                                           |
    | ------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | `result`      | string    | Values: "deliverable", "not\_deliverable"                                                                                                                             |
    | `deliverable` | boolean   | Returns `true` if the email can be delivered                                                                                                                          |
    | `disposable`  | boolean   | Returns `true` if email comes from a disposable email service like temp-mail                                                                                          |
    | `free`        | boolean   | Returns `true` if the email originates from a free service like Outlook or Gmail.                                                                                     |
    | `role`        | boolean   | Returns `true` if email address represents an organisational role like `admin`, `support`, `postmaster` etc                                                           |
    | `catchall`    | boolean   | Returns `true` if this domain accepts all emails regardless of username                                                                                               |
    | `suggestions` | string\[] | Returns an array of suggested email addresses if the email address is not deliverable. The suggested emails are not validated. Example: `corrected_email@example.com` |

  * UnknownEmail

    | Field         | Type      | Description                                      |
    | ------------- | --------- | ------------------------------------------------ |
    | `result`      | string    | Values: "unknown"                                |
    | `deliverable` | boolean   | Deliverability is not known. Values: "null"      |
    | `disposable`  | boolean   | Disposability is not known. Values: "null"       |
    | `free`        | boolean   | Free email provider is not known. Values: "null" |
    | `role`        | boolean   | Role is not known. Values: "null"                |
    | `catchall`    | boolean   | Catch-all status is not known. Values: "null"    |
    | `suggestions` | string\[] | Suggestions will be empty                        |

The `result` sits inside the standard `{ result, code, message }` envelope, see the [API reference](/docs/api/api-reference.md) for the wrapper format.
