# Inspect a name's DNS

What every resolver answers for any name, without creating a claim.

GET `/api/dns/inspect`

**cURL**

```shell
curl 'http://localhost:5200/api/dns/inspect?name=yourcompany.com' \
  -b cookies.txt
```

**Node.js**

```javascript
// `cookie` is the session cookie that Create a claim returned.
const response = await fetch("http://localhost:5200/api/dns/inspect?name=yourcompany.com", {
  headers: { cookie },
})
const data = await response.json()
```

**Python**

```python
import requests

# `session` is the requests.Session() that created the claim.
response = session.get("http://localhost:5200/api/dns/inspect?name=yourcompany.com")
data = response.json()
```

Response 200 OK

```json
{
  "zone": {
    "kind": "delegated",
    "apex": "yourcompany.com",
    "provider": "Namecheap"
  },
  "observations": [
    {
      "resolver": "authoritative:dns1.registrar-servers.com",
      "serverIp": "192.0.2.53",
      "qname": "_prufy-challenge.yourcompany.com",
      "qtype": "TXT",
      "rcode": "NXDOMAIN",
      "answers": [],
      "cnameChain": [],
      "ad": null,
      "latencyMs": 18,
      "error": null
    },
    {
      "resolver": "authoritative:dns2.registrar-servers.com",
      "serverIp": "192.0.2.53",
      "qname": "_prufy-challenge.yourcompany.com",
      "qtype": "TXT",
      "rcode": "NXDOMAIN",
      "answers": [],
      "cnameChain": [],
      "ad": null,
      "latencyMs": 18,
      "error": null
    },
    {
      "resolver": "google",
      "serverIp": null,
      "qname": "_prufy-challenge.yourcompany.com",
      "qtype": "TXT",
      "rcode": "NXDOMAIN",
      "answers": [],
      "cnameChain": [],
      "ad": false,
      "latencyMs": 31,
      "error": null
    },
    {
      "resolver": "cloudflare",
      "serverIp": null,
      "qname": "_prufy-challenge.yourcompany.com",
      "qtype": "TXT",
      "rcode": "NXDOMAIN",
      "answers": [],
      "cnameChain": [],
      "ad": false,
      "latencyMs": 31,
      "error": null
    }
  ]
}
```

> **Development only**
>
> This route answers `not_found` when the server runs in production. It's here for building and testing against a local server.

A way to see raw observations while building: who runs the zone, and what each server says about the challenge record's name.

## Authentication

Send the session cookie. Without it the answer is `unauthorized`. [How sessions work](https://www.prufy.dev/docs/authentication.md).

## Query parameters

`name` string required

The domain to look up. Normalized the same way as a claim's input.

## Response

`200 OK`, with every field below present. Times are ISO 8601 strings in UTC.

- `zone` object

  Who is in charge of this name's DNS.

  - `kind` string

    Whether the name has nameservers, doesn't exist, or couldn't be looked up.

    - One of `delegated` `nxdomain` `lookup_failed`
  - `apex` string | null

    The zone the name lives in, when it's delegated.
  - `provider` string | null

    Who runs that zone, when it's delegated.
- `observations` array of objects

  What each DNS server answered.

  - `resolver` string

    Who answered: `authoritative:<nameserver>` for one of the domain's own servers, or a public resolver.

    - One of `google` `cloudflare`, or a value added later
  - `serverIp` string | null

    The address that was asked, when we know it.
  - `qname` string

    The name that was looked up.
  - `qtype` string

    The record type that was asked for.

    - One of `TXT` `NS` `SOA` `CNAME` `A` `AAAA`
  - `rcode` string | null

    The DNS response code. Null when no response arrived at all.

    - One of `NOERROR` `NXDOMAIN` `SERVFAIL` `REFUSED` `OTHER`
  - `answers` array of strings

    The values that came back, one per record.
  - `cnameChain` array of strings

    Any CNAMEs followed on the way to the answer.
  - `ad` boolean | null

    The DNSSEC authenticated-data flag. Null when the server can't report it.
  - `latencyMs` number

    How long the answer took, in milliseconds.
  - `error` string | null

    How the lookup went wrong, if it did.

    - One of `timeout` `servfail` `refused` `network` `bad_response` `no_nameserver_address`

## Errors

| Status | Kind | When |
| --- | --- | --- |
| 400 | `bad_request` | `name` is missing or longer than 2,000 characters. |
| 401 | `unauthorized` | The request has no session cookie, or one we don't recognise. |
| 404 | `not_found` | The server is running in production. |
| 422 | `empty` | The input is blank. This and the seven kinds below are a 422, each with a message that says what to type instead. |
| 422 | `invalid_characters` | The input has characters a domain can't contain. |
| 422 | `label_too_long` | One part between dots is longer than 63 characters. |
| 422 | `too_long` | The whole name is longer than 253 characters. |
| 422 | `ip_address` | The input is an IP address, not a domain. |
| 422 | `reserved_tld` | The ending is set aside, like `.test` or `.localhost`. |
| 422 | `public_suffix` | The input is a suffix many people share, like `co.uk`, not a domain under it. |
| 422 | `single_label` | The input has no dot, so there's no ending to look up. |

Any route can also answer `500` with `internal_error`. Every error has the same shape, described in [Errors](https://www.prufy.dev/docs/errors.md).

---

Every page of these docs, as a list: https://www.prufy.dev/llms.txt
