Authentication overview

Authentication for WebScraping.AI's Web Scraping API primarily relies on a unique API key assigned to each user account. This key serves as the primary credential to verify your identity and authorize your API requests. When a request is made to the Web Scraping API endpoint, the provided API key is checked against registered accounts to ensure that the request originates from an authorized user. This mechanism controls access to services such as proxy rotation, CAPTCHA bypassing, and JavaScript rendering, and helps manage your allocated request quota, including the free tier of 1,000 requests per month.

The API key is a secret token that should be protected to prevent unauthorized use of your account and its associated resources. The design prioritizes ease of use for developers while maintaining a necessary level of security for API access. Understanding how to securely manage and transmit your API key is essential for effective and protected integration with WebScraping.AI.

Supported authentication methods

WebScraping.AI supports API key authentication, which can be transmitted either as a query parameter or within an HTTP header. While both methods provide the necessary authentication, transmitting the key in an HTTP header is generally considered more secure as it prevents the key from being logged in server access logs or browser history in some contexts.

Method When to Use Security Level
API Key (Query Parameter) Simple integrations, quick testing, environments where URL logging is acceptable. Moderate (key visible in URLs, may be logged)
API Key (HTTP Header) Production environments, sensitive applications, recommended for all new integrations. High (key not visible in URLs, generally not logged)

The choice between these methods depends on your specific application requirements and security considerations. For most production applications, utilizing the HTTP header method is advisable to enhance security and reduce potential exposure of your API key. The WebScraping.AI documentation provides examples for both approaches.

Getting your credentials

To obtain your WebScraping.AI API key, you need to register for an account on the official website. Upon successful registration and login:

  1. Access Your Dashboard: Navigate to your account dashboard after logging in to your WebScraping.AI account.
  2. Locate API Key Section: Within the dashboard, there will be a dedicated section or tab for your API key. This is typically labeled something like "API Key" or "Settings."
  3. Retrieve Your Key: Your unique API key will be displayed. Copy this key, as it is required for all authenticated requests.
  4. Key Regeneration: Most API providers, including WebScraping.AI, offer an option to regenerate your API key. This feature is useful if you suspect your key has been compromised or if you need to rotate keys as part of your security policy. Refer to the WebScraping.AI documentation for specific steps on key regeneration.

It is crucial to store your API key securely and avoid hardcoding it directly into your application's source code, especially for client-side applications or publicly accessible repositories. Environment variables or secure configuration management systems are preferred methods for storing API keys.

Authenticated request example

Regardless of whether you use a query parameter or an HTTP header, the core interaction involves sending your API key with each request. The following examples illustrate how to make an authenticated request using cURL and Python, demonstrating both methods.

Using a query parameter (cURL)

In this example, the API key is passed directly within the URL as a query string parameter named api_key.

curl "https://api.webscraping.ai/html?api_key=YOUR_API_KEY&url=https://example.com"

Using an HTTP header (cURL)

This method sends the API key in a custom HTTP header, often named X-API-KEY or Authorization: Bearer depending on the specific API's convention. WebScraping.AI's documentation clarifies the exact header name if different from the query parameter name.

curl -H "X-API-KEY: YOUR_API_KEY" "https://api.webscraping.ai/html?url=https://example.com"

Using Python with requests library (HTTP header)

For Python applications, using the requests library is common. This example demonstrates including the API key in the headers for a more secure transmission.

import requests

api_key = "YOUR_API_KEY"
url = "https://api.webscraping.ai/html"
params = {"url": "https://example.com"}
headers = {"X-API-KEY": api_key}

response = requests.get(url, params=params, headers=headers)

if response.status_code == 200:
    print("Success!")
    print(response.json()) # Or response.text for HTML content
else:
    print(f"Error: {response.status_code} - {response.text}")

Make sure to replace YOUR_API_KEY with your actual key obtained from the WebScraping.AI dashboard. For detailed examples across other supported languages like Node.js, PHP, and Ruby, refer to the official WebScraping.AI documentation.

Security best practices

Securing your WebScraping.AI API key is critical to prevent unauthorized access to your account and API usage. Adhering to these best practices can mitigate common security risks:

  • Keep Your API Key Confidential: Treat your API key as you would a password. Never share it publicly, commit it to version control systems like Git without proper encryption or exclusion (e.g., using .gitignore), or embed it directly in client-side code where it could be exposed.
  • Use Environment Variables: Store your API key in environment variables rather than hardcoding it in your application. This separates sensitive credentials from your codebase and allows for easier rotation and management across different environments (development, staging, production). For example, in Python, you might use os.environ.get('WEB_SCRAPING_AI_API_KEY').
  • Transmit via HTTP Headers: Whenever possible, send your API key in an HTTP header (e.g., X-API-KEY or Authorization: Bearer YOUR_API_KEY) rather than as a query parameter. Keys in query parameters can be logged in server access logs, browser history, and proxy logs, increasing their exposure risk. MDN Web Docs on the Authorization header provide further context on proper usage.
  • Implement IP Whitelisting (if available): If WebScraping.AI offers IP whitelisting, configure it to allow API requests only from a specified list of trusted IP addresses. This adds an extra layer of security, ensuring that even if your key is compromised, it cannot be used from unauthorized locations. Check the WebScraping.AI documentation for features like IP whitelisting.
  • Regular Key Rotation: Periodically regenerate your API key, especially if you have a large team or if a developer leaves your organization. This limits the window of opportunity for a compromised key to be exploited.
  • Monitor API Usage: Regularly check your WebScraping.AI dashboard for unusual API usage patterns. Spikes in requests or usage from unexpected geographical locations could indicate a compromised key.
  • Secure Your Development Environment: Ensure that your development machines and build pipelines are secure. Malicious software or improper access controls in these environments can lead to credential theft.
  • HTTPS Everywhere: Always ensure that all communications with the WebScraping.AI API occur over HTTPS. This encrypts data in transit, protecting your API key and other sensitive information from eavesdropping. All modern APIs, including WebScraping.AI, enforce HTTPS by default.

By implementing these security measures, you can significantly reduce the risk of unauthorized access and maintain the integrity of your WebScraping.AI integration.