Authentication overview

Hunter.io provides a RESTful API that allows programmatic access to its email verification, email finding, and domain search functionalities. Authentication for the Hunter.io API is managed through API keys. An API key is a unique token associated with a user's Hunter.io account, which must be included in every API request to authorize access to the requested resources. This method facilitates straightforward integration for developers building applications that interact with Hunter.io services.

The API is designed with predictable, resource-oriented URLs and uses standard HTTP response codes to indicate the success or failure of an API call. All API responses are returned in JSON format, which is a common data interchange format for web services, as described by the W3C JSON format specification. This consistency aids in parsing and integrating API responses into various programming environments.

Hunter.io primarily supports server-side integrations where the API key can be securely stored and managed. Client-side usage is generally discouraged due to the inherent security risks of exposing API keys in publicly accessible code. The API documentation provides examples in several popular programming languages, including Node.js, Python, Ruby, PHP, and Go, illustrating how to construct authenticated requests and handle responses.

Supported authentication methods

Hunter.io's API utilizes a single, primary authentication method: API keys. This method is suitable for most server-to-server communication and applications where the API key can be kept confidential.

The following table outlines the details of the supported authentication method:

Method When to Use Security Level
API Key (Query Parameter) Server-side applications, backend services, scripting, internal tools where the key can be securely stored. Medium to High (dependent on key management). Requires secure storage and transmission over HTTPS.

Hunter.io's API keys are designed for simplicity and ease of use. They are unique strings that identify and authenticate the calling application to the Hunter.io API. Each key is linked to a specific user account and its associated usage limits and subscription plan. It is crucial to treat API keys as sensitive credentials, similar to passwords, to prevent unauthorized access to your Hunter.io account and services.

The API key must be transmitted over HTTPS to ensure that the key is encrypted during transit, protecting it from interception. The use of HTTPS is a standard security practice for web APIs, as detailed in the Mozilla Developer Network's HTTPS explanation.

Getting your credentials

To access the Hunter.io API, you need to obtain an API key from your Hunter.io account dashboard. The process is straightforward:

  1. Account Creation/Login: First, ensure you have an active Hunter.io account. If you don't have one, you can sign up on the Hunter.io homepage.
  2. Navigate to API Settings: Once logged in, go to your account settings or the specific API section. Typically, this is found under a menu item like 'API' or 'API Keys' within your dashboard. Hunter.io provides direct access to this section via their API documentation portal.
  3. Generate API Key: In the API section, you will find an option to generate or view your API key. If a key already exists, it will be displayed. If not, click a button to generate a new API key.
  4. Copy Your API Key: Once generated, copy the API key. It's recommended to store it immediately in a secure location, such as an environment variable or a secrets management system, as it might not be fully displayed again for security reasons.

Hunter.io API keys do not have an explicit expiration date; however, you can regenerate them from your dashboard if you suspect a key has been compromised or if you need to rotate keys for security policies. Regenerating a key invalidates the old one, so any applications using the old key will need to be updated with the new key.

Authenticated request example

Hunter.io API keys are passed as a query parameter named api_key in the URL of your API requests. Below is an example of an authenticated request using the Email Finder endpoint, which searches for email addresses associated with a given domain and name.

This example uses curl, a common command-line tool for making HTTP requests, to demonstrate how to include the API key.

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

In this example:

  • https://api.hunter.io/v2/email-finder is the base URL for the Email Finder endpoint.
  • domain=apispine.com specifies the domain to search within.
  • first_name=John and last_name=Doe provide the name for which to find an email.
  • api_key=YOUR_API_KEY is where you replace YOUR_API_KEY with the actual API key obtained from your Hunter.io dashboard.

Upon successful authentication and a valid request, the API will return a JSON response containing the requested data, such as the found email address, its verification status, and other relevant information. If authentication fails (e.g., due to an invalid or missing API key), the API will return an appropriate HTTP error status code, typically 401 Unauthorized or 403 Forbidden, along with a JSON error message explaining the issue.

Security best practices

When integrating with the Hunter.io API or any API that uses API keys, adhering to security best practices is essential to protect your credentials and data. The following recommendations help maintain the confidentiality and integrity of your API key and interactions:

  • Keep API Keys Confidential: Treat your API key as a confidential secret. Do not embed it directly in client-side code (e.g., JavaScript in a web browser or mobile application) where it can be easily extracted by users. Instead, use a backend server to make API calls, passing the API key securely from your server to the Hunter.io API.
  • Use Environment Variables or Secret Management: Store your API key in environment variables or a dedicated secrets management service (e.g., AWS Secrets Manager, Google Secret Manager, Azure Key Vault) rather than hardcoding it directly into your application's source code. This practice prevents the key from being exposed if your code repository is compromised and allows for easier key rotation.
  • Transmit Over HTTPS Only: Always ensure that all API requests to Hunter.io are made over HTTPS. This encrypts the communication channel, protecting your API key and other sensitive data from eavesdropping during transit. Hunter.io's API endpoints are exclusively served over HTTPS.
  • Implement Rate Limiting and Monitoring: Implement rate limiting on your application's calls to the Hunter.io API to prevent abuse and stay within your subscription limits. Monitor API usage for unusual patterns that might indicate unauthorized access or a compromised key.
  • Rotate API Keys Periodically: Regularly rotate your API keys, even if there's no suspected compromise. This practice reduces the window of opportunity for an attacker if a key is ever exposed. Hunter.io allows you to regenerate your API key from your dashboard, which invalidates the old one.
  • Restrict API Key Permissions (if applicable): While Hunter.io API keys typically grant access to all available API endpoints for your account, if an API offered granular permissions, it would be best practice to create keys with the minimum necessary permissions for each application.
  • Secure Your Development Environment: Ensure that your development and deployment environments are secure. This includes using strong passwords, enabling multi-factor authentication for access to code repositories and servers, and regularly patching systems to protect against vulnerabilities.
  • Error Handling: Implement robust error handling for API responses. If an API call fails due to authentication issues, log the error (without exposing the API key) and handle it gracefully within your application.

By following these best practices, developers can significantly enhance the security posture of their applications that integrate with the Hunter.io API, safeguarding both their account and user data.