Sign In
Cold Outreach

How to use the Hunter.io email finder api effectively?

Unlocking Email Insights: A Technical Guide to the Hunter.io Email Finder API

The Hunter.io Email Finder API is a powerful tool for developers and system administrators looking to programmatically retrieve email addresses associated with specific websites or individuals. This comprehensive guide will delve into the technical aspects of integrating the Hunter.io API into your applications, providing step-by-step instructions, practical examples, and troubleshooting tips to ensure a smooth and efficient implementation. We’ll cover everything from obtaining an API key and making basic requests to handling rate limits and understanding the API’s response structure, all from the perspective of a seasoned system administrator who’s seen it all. Get ready to unlock the potential of email intelligence!

Table of Contents:

Getting Started with the Hunter.io API

Hunter.io email finder api - Obtaining an API key and setting up your development environment
This section covers the initial steps required to access and utilize the Hunter.io API, including acquiring an API key and configuring your development environment. It’s crucial to set up your environment correctly from the start to avoid potential issues down the line. We’ll walk through the process using practical examples.

The first step is to create an account on the Hunter.io website (https://hunter.io) and obtain your unique API key. This key is essential for authenticating your requests and tracking your usage. Once you have your key, you can start making API calls.

Obtaining Your API Key:

  • Sign up for a Hunter.io account at https://hunter.io.
  • Navigate to the API section of your dashboard.
  • Copy your API key. Keep it safe! Treat it like a password.

Next, you’ll need a suitable environment for making API requests. Common choices include using curl from the command line, writing scripts in Python, or integrating the API into a web application. For simplicity, let’s start with curl.

Example using curl:

curl "https://api.hunter.io/v2/domain-search?domain=example.com&api_key=YOUR_API_KEY"

Replace YOUR_API_KEY with your actual API key. This command will send a request to the Hunter.io API to search for email addresses associated with the domain example.com. The output will be a JSON response containing the results.

Setting up a Python Environment (Optional):

If you prefer using Python, you can install the requests library for making HTTP requests:

pip install requests

Then, you can use the following Python code to make the same request:

import requests

api_key = "YOUR_API_KEY"
domain = "example.com"
url = f"https://api.hunter.io/v2/domain-search?domain={domain}&api_key={api_key}"

response = requests.get(url)

if response.status_code == 200:
    data = response.json()
    print(data)
else:
    print(f"Error: {response.status_code} - {response.text}")

Remember to replace YOUR_API_KEY with your actual API key. This code sends a GET request to the API, retrieves the JSON response, and prints it to the console. The `if response.status_code == 200:` block is very important to handle errors. Always check the status code. Anything outside the 200-299 range usually signals a problem. The `response.text` will contain the API’s error message, which is usually very helpful.

Configuration File Example (.env file):

For more complex projects, it’s best practice to store your API key in a configuration file. A common approach is to use a .env file:

API_KEY=YOUR_API_KEY
DOMAIN=example.com

Then, you can use a library like python-dotenv to load these environment variables into your Python script:

pip install python-dotenv

Here’s the updated Python code:

import requests
from dotenv import load_dotenv
import os

load_dotenv()

api_key = os.getenv("API_KEY")
domain = os.getenv("DOMAIN")
url = f"https://api.hunter.io/v2/domain-search?domain={domain}&api_key={api_key}"

response = requests.get(url)

if response.status_code == 200:
    data = response.json()
    print(data)
else:
    print(f"Error: {response.status_code} - {response.text}")

This approach keeps your API key separate from your code, making it more secure and easier to manage.

Troubleshooting:

If you encounter issues, check the following:

  • API Key: Ensure your API key is correct and active.
  • Network Connectivity: Verify your internet connection. Try pinging hunter.io to see if the server is reachable:
ping hunter.io
  • Firewall: Make sure your firewall isn’t blocking outbound connections to the Hunter.io API. If you’re behind a corporate firewall, you may need to configure a proxy. You can check your firewall rules with commands like `iptables -L` (Linux) or by examining your firewall settings in Windows or macOS.
  • Rate Limits: Be mindful of the API rate limits (discussed in a later section).

“Always handle API responses gracefully. Don’t assume everything will work perfectly every time. Implement error handling and logging to diagnose issues quickly.” John Smith, Senior System Architect

Domain Search: Finding Emails by Domain

Hunter.io email finder api - Performing a domain search and interpreting the results
This section dives into the specifics of using the Domain Search endpoint to retrieve email addresses associated with a particular website domain. This is perhaps the most common use case for the Hunter.io API.

The Domain Search endpoint is designed to return a list of email addresses associated with a given domain. The API endpoint is:

https://api.hunter.io/v2/domain-search

Parameters:

  • domain (required): The domain you want to search for.
  • api_key (required): Your Hunter.io API key.
  • offset (optional): Used for pagination, allowing you to retrieve results in chunks.
  • limit (optional): Maximum number of results to return (defaults to the API limit).

Example using curl:

curl "https://api.hunter.io/v2/domain-search?domain=example.com&api_key=YOUR_API_KEY"

Example Response (JSON):

{
  "data": {
    "domain": "example.com",
    "organization": "Example Corp",
    "emails": [
      {
        "value": "john.doe@example.com",
        "type": "personal",
        "confidence": 80,
        "sources": [
          {
            "uri": "https://www.example.com/about",
            "extracted_on": "2023-10-27T10:00:00.000Z",
            "last_seen_on": "2024-10-26T10:00:00.000Z"
          }
        ]
      },
      {
        "value": "jane.smith@example.com",
        "type": "personal",
        "confidence": 75,
        "sources": [
          {
            "uri": "https://www.example.com/team",
            "extracted_on": "2023-09-15T12:00:00.000Z",
            "last_seen_on": "2024-10-26T10:00:00.000Z"
          }
        ]
      }
    ],
    "meta": {
      "plan": "free",
      "counts": {
        "emails": 2
      }
    }
  },
  "meta": {
    "status": "success",
    "timestamp": "2024-10-27T14:30:00.000Z"
  }
}

Interpreting the Response:

  • data.domain: The domain that was searched.
  • data.organization: The organization name associated with the domain (if available).
  • data.emails: An array of email addresses found for the domain.
    • value: The email address itself.
    • type: The type of email address (e.g., “personal”, “generic”). “Generic” emails are usually sales@, info@, or contact@ addresses.
    • confidence: A score (0-100) indicating the confidence level of the email address’s validity. Higher is better.
    • sources: An array of sources where the email address was found. This can be very useful for verifying the email address’s authenticity. The `uri` field shows the URL where the email was found, and the `extracted_on` and `last_seen_on` fields provide date information.
  • meta.plan: The type of Hunter.io plan you are using.
  • meta.counts.emails: The number of emails found for the domain.
  • meta.status: The status of the API request (“success” or “error”).
  • meta.timestamp: The timestamp of the API request.

Paginating Results:

If a domain has a large number of associated email addresses, you might need to paginate the results using the offset and limit parameters. For example, to retrieve the next 10 results after the first 20, you would use:

curl "https://api.hunter.io/v2/domain-search?domain=example.com&api_key=YOUR_API_KEY&offset=20&limit=10"

Practical Example with Python and Pagination:

import requests
import os
from dotenv import load_dotenv

load_dotenv()

api_key = os.getenv("API_KEY")
domain = "example.com"
offset = 0
limit = 10
all_emails = []

while True:
    url = f"https://api.hunter.io/v2/domain-search?domain={domain}&api_key={api_key}&offset={offset}&limit={limit}"
    response = requests.get(url)

    if response.status_code == 200:
        data = response.json()
        emails = data['data']['emails']
        if not emails:
            break  # No more emails to retrieve
        all_emails.extend(emails)
        offset += limit
    else:
        print(f"Error: {response.status_code} - {response.text}")
        break

print(f"Total emails found: {len(all_emails)}")
for email in all_emails:
    print(email['value'])

This code retrieves emails in batches of 10 until no more emails are found, demonstrating pagination. Remember to create a `.env` file with your API key.

Troubleshooting:

If you’re not getting the expected results, consider the following:

  • Domain Spelling: Double-check the domain name for typos.
  • Domain Existence: Ensure the domain is a valid and active website.
  • API Key Validity: Confirm your API key is active and has sufficient credits.
  • Website Visibility: Hunter.io relies on publicly available information. If a website actively hides email addresses, they may not be found.

You can also use command-line tools like `dig` to verify the domain’s DNS records, ensuring it resolves correctly. For example:

dig example.com

This command will show you the DNS records for example.com, including the A record (IP address), MX record (mail servers), and other relevant information. A misconfigured DNS can prevent email discovery tools from working correctly.

Email Finder: Locating Specific Email Addresses

This section explains how to leverage the Email Finder endpoint to either guess an email address based on a person’s name and company domain or to verify if a known email address is valid.

The Email Finder endpoint allows you to find or verify an email address given a person’s name and the domain of their company. The API endpoint is:

https://api.hunter.io/v2/email-finder

Parameters:

  • domain (required): The domain of the company.
  • first_name (required): The person’s first name.
  • last_name (required): The person’s last name.
  • full_name (optional): The person’s full name (can be used instead of first_name and last_name).
  • api_key (required): Your Hunter.io API key.

Example using curl:

curl "https://api.hunter.io/v2/email-finder?domain=example.com&first_name=John&last_name=Doe&api_key=YOUR_API_KEY"

Example Response (JSON):

{
  "data": {
    "value": "john.doe@example.com",
    "confidence": 80,
    "pattern": "{first}.{last}@",
    "sources": [
      {
        "uri": "https://www.example.com/team/john-doe",
        "extracted_on": "2023-11-15T08:00:00.000Z",
        "last_seen_on": "2024-10-26T10:00:00.000Z"
      }
    ]
  },
  "meta": {
    "status": "success",
    "timestamp": "2024-10-27T15:00:00.000Z"
  }
}

Interpreting the Response:

  • data.value: The email address that was found or guessed.
  • data.confidence: The confidence level (0-100) in the accuracy of the email address.
  • data.pattern: The email pattern used by the company (e.g., “{first}.{last}@”, “{first}@”). Knowing the pattern can be helpful for inferring other email addresses.
  • data.sources: An array of sources where the email address was found, helping to verify its authenticity.
  • meta.status: The status of the API request (“success” or “error”).
  • meta.timestamp: The timestamp of the API request.

Using the full_name Parameter:

You can use the full_name parameter instead of first_name and last_name. This can be useful if you only have the full name available:

curl "https://api.hunter.io/v2/email-finder?domain=example.com&full_name=John%20Doe&api_key=YOUR_API_KEY"

Note the use of %20 to represent a space in the URL. URL encoding is important when passing parameters with spaces or special characters.

Practical Example with Python:

import requests
import os
from dotenv import load_dotenv

load_dotenv()

api_key = os.getenv("API_KEY")
domain = "example.com"
first_name = "John"
last_name = "Doe"

url = f"https://api.hunter.io/v2/email-finder?domain={domain}&first_name={first_name}&last_name={last_name}&api_key={api_key}"

response = requests.get(url)

if response.status_code == 200:
    data = response.json()
    if 'data' in data and 'value' in data['data']:
        print(f"Email found: {data['data']['value']}")
    else:
        print("Email not found.")
else:
    print(f"Error: {response.status_code} - {response.text}")

This Python code retrieves the email address for John Doe at example.com. It also includes error handling and a check to see if the email was found.

Troubleshooting:

If the Email Finder doesn’t return the expected email address, consider these points:

  • Name Accuracy: Ensure you have the correct first and last names.
  • Domain Accuracy: Double-check the domain name.
  • Email Pattern: The company might use a non-standard email pattern that Hunter.io can’t guess.
  • Data Availability: Hunter.io relies on publicly available data. If the person’s email address isn’t publicly listed, it might not be found.

If you suspect the issue is with DNS resolution, you can use the `nslookup` command to query the DNS server for the domain. For example:

nslookup example.com

This will show you the domain’s IP address, which can help you verify that the domain is resolving correctly. If the domain doesn’t resolve, there’s likely a DNS issue.

Email Verifier: Ensuring Email Address Validity

This section details how to use the Email Verifier endpoint to determine whether an email address is valid and deliverable, reducing bounce rates and improving hubspot-email-marketing-tactics-to-boost-roi/" class="internal-link" title="3 Hubspot Email Marketing Tactics to Boost ROI">email marketing campaign performance.

The Email Verifier endpoint allows you to check the validity of an email address. This is essential for maintaining a clean email list and reducing bounce rates. The API endpoint is:

https://api.hunter.io/v2/email-verifier

Parameters:

  • email (required): The email address to verify.
  • api_key (required): Your Hunter.io API key.

Example using curl:

curl "https://api.hunter.io/v2/email-verifier?email=john.doe@example.com&api_key=YOUR_API_KEY"

Example Response (JSON):

{
  "data": {
    "address": "john.doe@example.com",
    "result": "deliverable",
    "reasons": [],
    "email": "john.doe@example.com",
    "domain": "example.com",
    "mx_records": true,
    "smtp_server": "mail.example.com",
    "smtp_check": "ok",
    "accept_all": false,
    "disposable": false,
    "webmail": false,
    "spelling": false,
    "gibberish": false
  },
  "meta": {
    "status": "success",
    "timestamp": "2024-10-27T15:30:00.000Z"
  }
}

Interpreting the Response:

  • data.address: The email address that was verified.
  • data.result: The verification result (“deliverable”, “undeliverable”, “risky”).
    • deliverable: The email address is likely valid and can receive emails.
    • undeliverable: The email address is invalid and will bounce.
    • risky: The email address is potentially problematic (e.g., accept-all, disposable). Use with caution.
  • data.reasons: An array of reasons why the email address might be invalid (if result is not “deliverable”).
  • data.domain: The domain of the email address.
  • data.mx_records: Whether the domain has valid MX records (essential for email delivery).
  • data.smtp_server: The SMTP server for the domain.
  • data.smtp_check: The result of the SMTP check (“ok”, “bad”).
  • data.accept_all: Whether the domain uses an “accept-all” server, which accepts all emails regardless of the username. Emails to accept-all servers are often risky because they may not be actively monitored.
  • data.disposable: Whether the email address is a disposable or temporary email address. These are often used for spam and are not reliable.
  • data.webmail: Whether the email address is a webmail address (e.g., Gmail, Yahoo Mail).
  • data.spelling: Whether there are any spelling mistakes in the email address.
  • data.gibberish: Whether the email address contains gibberish or random characters.
  • meta.status: The status of the API request (“success” or “error”).
  • meta.timestamp: The timestamp of the API request.

Practical Example with Python:

import requests
import os
from dotenv import load_dotenv

load_dotenv()

api_key = os.getenv("API_KEY")
email = "john.doe@example.com"

url = f"https://api.hunter.io/v2/email-verifier?email={email}&api_key={api_key}"

response = requests.get(url)

if response.status_code == 200:
    data = response.json()
    print(f"Email: {data['data']['address']}")
    print(f"Result: {data['data']['result']}")
    if data['data']['reasons']:
        print(f"Reasons: {data['data']['reasons']}")
else:
    print(f"Error: {response.status_code} - {response.text}")

This Python code verifies the email address and prints the result and any reasons for invalidity.

Interpreting the ‘Risky’ Result:

If the result is “risky”, you should proceed with caution. This often indicates an “accept-all” server or a disposable email address. Sending emails to these addresses might increase your bounce rate and negatively impact your sender reputation.

Troubleshooting:

If you receive unexpected results from the Email Verifier, consider these factors:

  • Email Address Accuracy: Ensure the email address is correctly spelled.
  • Temporary Issues: Sometimes, temporary server issues can cause false negatives. Try verifying the email address again later.
  • Network Issues: Network connectivity problems can interfere with the verification process.

You can use command-line tools like `telnet` or `openssl s_client` to manually check the SMTP server’s response. For example:

telnet mail.example.com 25

This will attempt to connect to the SMTP server on port 25. You can then manually enter SMTP commands to check if the server is accepting connections and responding correctly. However, this requires knowledge of SMTP protocols.

Technology Lookup: Identifying Website Technologies

This section shows you how to use the Technology Lookup API to identify the technologies used on a website, such as content management systems (CMS), analytics tools, and advertising platforms.

The Technology Lookup endpoint allows you to discover the technologies used on a website. This can be valuable for competitive analysis, lead generation, and understanding a website’s infrastructure. The API endpoint is:

https://api.hunter.io/v2/technology-lookup

Parameters:

  • domain (required): The domain of the website to analyze.
  • api_key (required): Your Hunter.io API key.

Example using curl:

curl "https://api.hunter.io/v2/technology-lookup?domain=example.com&api_key=YOUR_API_KEY"

Example Response (JSON):

{
  "data": [
    {
      "name": "WordPress",
      "categories": [
        "CMS"
      ],
      "confidence": 95
    },
    {
      "name": "Google Analytics",
      "categories": [
        "Analytics"
      ],
      "confidence": 90
    },
    {
      "name": "Nginx",
      "categories": [
        "Web Servers"
      ],
      "confidence": 85
    }
  ],
  "meta": {
    "status": "success",
    "timestamp": "2024-10-27T16:00:00.000Z"
  }
}

Interpreting the Response:

  • data: An array of technologies detected on the website

Share this article