Authentication overview

ZenRows utilizes an API key-based authentication system to manage access to its web scraping infrastructure. This method ensures that all requests originating from a user's application are identifiable and authorized against their account. The API key functions as a unique identifier and credential, enabling ZenRows to enforce usage limits, apply billing rules, and provide access to features such as proxy rotation, JavaScript rendering, and anti-bot bypass mechanisms.

Integrating with ZenRows typically involves making an HTTP GET or POST request to their API endpoint, including the assigned API key as a query parameter. This approach is common for public-facing APIs where the primary goal is to authenticate the application making the request rather than an individual user. For developers, this means a straightforward setup process, with the key being the central component for all authenticated interactions with the ZenRows service.

For detailed instructions on API usage and parameters, consult the ZenRows API reference documentation.

Supported authentication methods

ZenRows primarily supports a single authentication method for its API: API Key authentication. This method is widely adopted for its simplicity and effectiveness in controlling access to web services.

API Key authentication

The API key is a unique token generated for each ZenRows user. It is a string of alphanumeric characters that must be included in every API request. When a request is received, ZenRows validates the provided key against its database to confirm the request's legitimacy and associate it with a specific user account. This method provides:

  • Ease of Use: Simple to implement by directly embedding the key in the request URL.
  • Access Control: Granular control over API usage, enabling ZenRows to monitor and manage request quotas.
  • Tracing: Allows for tracking API calls back to specific accounts for analytics and debugging.

While API keys offer convenience, their security relies heavily on correct handling by the developer. They should be treated as sensitive credentials, similar to passwords, especially when used in client-side code, where they could be exposed. For more information on securing API keys, the Google Cloud API Keys documentation provides general best practices applicable across various API platforms.

Authentication methods comparison

The following table outlines the key characteristics of the authentication method supported by ZenRows:

Method When to Use Security Level
API Key Direct application-to-API communication; when simplicity and rate limiting are primary concerns. Moderate (dependent on secure storage and transmission practices).

Getting your credentials

To authenticate with the ZenRows API, you will need your unique API key. This key is readily available within your ZenRows account dashboard.

  1. Sign Up/Log In: Navigate to the ZenRows homepage and either sign up for a new account or log in to your existing one. ZenRows offers a free tier that includes 1,000 requests per month, which is sufficient for obtaining and testing your API key.
  2. Access Dashboard: Once logged in, you will be directed to your ZenRows dashboard.
  3. Locate API Key: Your API key is prominently displayed in the main section of your dashboard. It is labeled as Your API Key or similar.
  4. Copy Key: Copy the entire string of characters. This is the credential you will use in all your ZenRows API requests.

ZenRows does not support creating multiple API keys per account or key rotation directly through the dashboard. If you believe your API key has been compromised, you should contact ZenRows support for assistance with key invalidation and regeneration.

Authenticated request example

Authenticating with ZenRows involves including your API key as a query parameter in your API requests. The key typically uses the parameter name apikey.

Curl example

Here's an example using curl to make a simple authenticated request to the ZenRows API. Replace YOUR_API_KEY with your actual API key and https://example.com with the target URL you wish to scrape.

curl "https://api.zenrows.com/v1/get?url=https://example.com&apikey=YOUR_API_KEY"

This request fetches the HTML content of https://example.com through the ZenRows service, applying any default proxy or anti-bot measures enabled for your account. Additional parameters can be added to the URL for features like JavaScript rendering (&js_render=true) or premium proxies (&premium_proxy=true).

Python example

Using the requests library in Python, an authenticated request would look like this:

import requests

api_key = "YOUR_API_KEY"
target_url = "https://example.com"
zenrows_api_url = f"https://api.zenrows.com/v1/get?url={target_url}&apikey={api_key}"

response = requests.get(zenrows_api_url)

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

This Python script performs the same function as the curl example, retrieving content via the ZenRows API. For more language-specific examples, refer to the ZenRows documentation, which provides snippets for Python, Node.js, PHP, Go, and Ruby.

Security best practices

Securing your ZenRows API key and managing access to the API are critical for preventing unauthorized usage and protecting your data.

1. Keep API keys confidential

Your API key grants full access to your ZenRows account's allocated requests and features. Treat it with the same level of confidentiality as you would a password.

  • Do not embed directly in client-side code: Never hardcode your API key directly into client-side JavaScript or mobile applications where it can be easily extracted by users.
  • Use environment variables: Store your API key as an environment variable on your server or development machine. This prevents the key from being committed to version control systems like Git.
  • Avoid public repositories: Ensure your API key is never pushed to public code repositories. If it accidentally is, immediately consider the key compromised and contact ZenRows support.

2. Use secure communication (HTTPS)

Always use HTTPS when making requests to the ZenRows API. ZenRows's API endpoints are designed to use TLS encryption, which protects your API key and data in transit from eavesdropping and tampering. Using HTTPS is a fundamental security practice for any API interaction.

3. Implement rate limiting and error handling

While ZenRows manages its own rate limits based on your subscription, implementing client-side rate limiting and robust error handling in your application can prevent accidental overuse of your quota and improve application stability. Handle HTTP status codes appropriately, especially 401 Unauthorized (due to an invalid key) or 429 Too Many Requests (if you exceed ZenRows's internal limits).

4. Monitor usage

Regularly check your ZenRows dashboard to monitor API key usage. Unusual spikes in requests or unexpected activity could indicate a compromised key or an issue with your application's logic. Proactive monitoring allows for early detection of potential security incidents.

5. Secure your development environment

Ensure that your development environment, build servers, and deployment pipelines are secure. Access to these systems could indirectly compromise your API keys. Follow secure coding guidelines and maintain strict access controls to all systems that interact with your ZenRows key.

6. Consider IP whitelisting (if available/applicable)

While ZenRows's primary authentication method is API keys, some API services offer IP whitelisting as an additional layer of security. This feature restricts API access only to requests originating from a predefined set of IP addresses. If ZenRows were to support this feature in the future, it would be a strong recommendation to use it to further lock down access to your API key, even if the key itself were exposed. Always check the latest ZenRows documentation for current security features.

By adhering to these best practices, developers can significantly reduce the risk of unauthorized access to their ZenRows account and ensure the secure operation of their web scraping applications.