DNS Lookup API: Query A, MX, TXT Records Programmatically

Looking up DNS records programmatically is essential for monitoring infrastructure, validating domain configurations, and building network tools. The Apixies DNS Lookup API lets you query any record type -- A, MX, TXT, CNAME, and more -- with a single HTTP request. No DNS libraries to install, no resolvers to configure, and no raw socket code to maintain.

How the DNS Lookup API Works

The API exposes a straightforward GET endpoint. You pass a domain name and an optional record type, and the service returns a JSON response containing the matching DNS records.

GET https://apixies.io/api/v1/dns-lookup?domain=example.com&type=A
Parameter Required Default Description
domain Yes -- The domain name to look up
type No A Record type: A, AAAA, MX, TXT, CNAME, NS, SOA, SRV, CAA, PTR

The response is a JSON object containing a records array with the resolved entries. Each element in the array represents a single DNS record returned by the authoritative nameservers.

Authentication

Pass your API key in the X-API-Key header. Anonymous requests work without a key at 20 requests per day, while a free registered account gives you 75 requests/day -- enough for development, testing, and lightweight production workloads.

curl -H "X-API-Key: YOUR_API_KEY" \
  "https://apixies.io/api/v1/dns-lookup?domain=example.com&type=A"

Get a free API key to raise your daily limit and start building immediately.

What Are DNS Records?

The Domain Name System (DNS) is the internet's phonebook. When a browser navigates to example.com, it queries DNS to translate that human-readable name into an IP address. Different record types serve different purposes:

  • A records map a domain to an IPv4 address.
  • AAAA records map a domain to an IPv6 address.
  • MX records identify the mail servers responsible for receiving email.
  • TXT records hold arbitrary text data, often used for SPF, DKIM, and domain ownership verification.
  • CNAME records alias one domain to another.
  • NS records specify the authoritative nameservers for a domain.

For a deeper dive into every supported record type, see the DNS Record Types Explained guide.

Step-by-Step: Your First DNS Lookup

Step 1 -- Query an A Record

Start with the simplest case. This cURL command looks up the A records for example.com:

curl -H "X-API-Key: YOUR_API_KEY" \
  "https://apixies.io/api/v1/dns-lookup?domain=example.com&type=A"

The JSON response will contain the IPv4 addresses associated with the domain:

{
  "records": [
    {
      "type": "A",
      "value": "93.184.216.34",
      "ttl": 3600
    }
  ]
}

Step 2 -- Query MX Records

To find which mail servers handle email for a domain, change the type parameter to MX:

curl -H "X-API-Key: YOUR_API_KEY" \
  "https://apixies.io/api/v1/dns-lookup?domain=google.com&type=MX"

MX records include a priority field. Lower values indicate higher priority, meaning mail is routed to that server first. This is especially useful for verifying email deliverability -- see the dedicated MX records guide for a detailed walkthrough.

Step 3 -- Query TXT Records

TXT records store metadata such as SPF policies, DKIM signatures, and domain verification tokens:

curl -H "X-API-Key: YOUR_API_KEY" \
  "https://apixies.io/api/v1/dns-lookup?domain=example.com&type=TXT"

Parsing TXT records is important for email security auditing, domain ownership checks, and compliance monitoring.

Code Examples

JavaScript (Node.js)

async function dnsLookup(domain, type = "A") {
  const url = new URL("https://apixies.io/api/v1/dns-lookup");
  url.searchParams.set("domain", domain);
  url.searchParams.set("type", type);

  const response = await fetch(url, {
    headers: { "X-API-Key": process.env.APIXIES_KEY },
  });

  if (!response.ok) {
    throw new Error(`DNS lookup failed: ${response.status}`);
  }

  const data = await response.json();
  return data.records;
}

// Look up A records
const records = await dnsLookup("example.com", "A");
console.log("A records:", records);

// Look up MX records
const mxRecords = await dnsLookup("example.com", "MX");
console.log("MX records:", mxRecords);

Python

import requests
import os

api_key = os.environ["APIXIES_KEY"]

def dns_lookup(domain, record_type="A"):
    response = requests.get(
        "https://apixies.io/api/v1/dns-lookup",
        params={"domain": domain, "type": record_type},
        headers={"X-API-Key": api_key},
    )
    response.raise_for_status()
    return response.json()["records"]

# Query A records
a_records = dns_lookup("example.com", "A")
print("A records:", a_records)

# Query TXT records
txt_records = dns_lookup("example.com", "TXT")
print("TXT records:", txt_records)

PHP

$apiKey = getenv('APIXIES_KEY');

function dnsLookup(string $domain, string $type = 'A'): array
{
    global $apiKey;

    $query = http_build_query([
        'domain' => $domain,
        'type'   => $type,
    ]);

    $ch = curl_init("https://apixies.io/api/v1/dns-lookup?{$query}");
    curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-API-Key: {$apiKey}"]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $body = curl_exec($ch);
    $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    if ($status !== 200) {
        throw new RuntimeException("DNS lookup failed with status {$status}");
    }

    return json_decode($body, true)['records'];
}

$records = dnsLookup('example.com', 'MX');
print_r($records);

Parsing and Using the Results

The records array in the response is designed to be straightforward to consume. Each object includes the record type, its value, and the ttl (time-to-live in seconds). Depending on the record type, additional fields may be present -- for example, MX records include priority.

A common pattern is to iterate over the results and take action based on the values. For instance, you might check whether an expected IP address appears in the A records, verify that MX records exist before sending email, or confirm that a TXT record contains a specific verification token.

const records = await dnsLookup("example.com", "A");

const expectedIp = "93.184.216.34";
const found = records.some((r) => r.value === expectedIp);

if (!found) {
  console.warn("Expected IP not found in A records");
}

Common Use Cases

  • Infrastructure monitoring -- Periodically query DNS records and alert when values change unexpectedly.
  • Domain validation -- Confirm that a customer has pointed their domain to your servers before activating their account.
  • Email verification -- Check MX and TXT records to validate that a domain can receive email and has proper SPF/DKIM configuration.
  • Security auditing -- Scan TXT records for SPF, DKIM, and DMARC policies across a portfolio of domains.
  • Migration verification -- After a DNS change, programmatically verify that new records have propagated.

Next Steps

The free tier provides 75 requests/day with a free account, giving you plenty of room to integrate DNS lookups into your projects. When you need higher volume, paid plans scale with your usage.

Get your free API key and start querying DNS records in minutes.

Try the DNS Lookup API

Free tier is for development & small projects. 75 requests/day with a registered account.

Getting Started

Explore

Resources

Get Started Free

Free for development and small projects.

Get Free API Key