Authentication overview
ScrapingDog utilizes a single authentication method for accessing its suite of web scraping and proxy APIs: an API key. This key serves as the primary credential to verify a user's identity and authorize requests made to the ScrapingDog platform. The API key model provides a direct method for developers to integrate ScrapingDog services into their applications, ensuring that only authenticated requests are processed. Access to the API key is managed through the user's ScrapingDog dashboard, where it can be retrieved and, if necessary, regenerated. All API interactions, including those for the ScrapingDog API and Proxy API, require this key to be present in the request.
The implementation of API key authentication is common across various web services due to its simplicity and ease of integration. For example, similar authentication patterns are observed in services like the Cloudflare Workers AI API and the ArcGIS Mapping APIs, where a unique key is used to control access and track usage. This method allows ScrapingDog to manage access control and rate limits effectively, preventing unauthorized use and ensuring fair resource allocation among its users.
Supported authentication methods
ScrapingDog exclusively supports API key authentication. This method involves generating a unique, secret key associated with your user account. This key must be included in every API request to successfully authenticate with the ScrapingDog service. The system does not currently offer alternative authentication mechanisms such as OAuth 2.0, JWTs, or username/password combinations for API access.
The API key is passed as a query parameter within the request URL. This approach ensures that the key is readily available to the API endpoint for validation. While convenient, it necessitates careful handling to prevent exposure. The reliance on HTTPS for all API communications further protects the API key during transit, encrypting the data between the client and the server. Developers are responsible for securing their API keys within their applications and environments to prevent unauthorized access.
The table below summarizes the supported authentication method:
| Method | When to Use | Security Level |
|---|---|---|
| API Key (Query Parameter) | All ScrapingDog API interactions (Scraping API, Proxy API, SERP API) | Moderate (requires secure storage and HTTPS) |
Getting your credentials
To obtain your ScrapingDog API key, you need to register for an account on the official ScrapingDog website. Upon successful registration and login, your unique API key will be displayed within your user dashboard. This key is automatically generated for you and is essential for making any authenticated calls to the ScrapingDog API.
- Sign Up/Log In: Navigate to the ScrapingDog homepage and either create a new account or log in to an existing one.
- Access Dashboard: After logging in, you will be redirected to your personal dashboard.
- Locate API Key: Your API key is typically prominently displayed on the dashboard, often labeled as "Your API Key" or similar. It is a long alphanumeric string.
- Copy Key: Copy the API key to your clipboard. You will need to include this key in all your API requests.
- Key Management: The dashboard also provides options to regenerate your API key if you suspect it has been compromised or if you need a new one for security reasons. Regenerating a key invalidates the previous one, so update your applications accordingly.
It is crucial to treat your API key as sensitive information. Avoid hardcoding it directly into public repositories or client-side code where it could be easily exposed. Instead, use environment variables or secure configuration files to manage it.
Authenticated request example
Authenticated requests to the ScrapingDog API involve appending your unique API key as a query parameter named api_key to the request URL. The following examples demonstrate how to make an authenticated request using cURL and Python, targeting the ScrapingDog Scraping API.
cURL Example
This cURL command demonstrates a basic request to scrape a hypothetical URL, including the api_key parameter:
curl -X GET "https://api.scrapingdog.com/scrape?api_key=YOUR_API_KEY&url=https://example.com"
Replace YOUR_API_KEY with your actual API key obtained from your ScrapingDog dashboard.
Python Example
Using the requests library in Python, an authenticated request can be constructed as follows:
import requests
import os
# It's recommended to store your API key in an environment variable
api_key = os.environ.get("SCRAPINGDOG_API_KEY")
if not api_key:
raise ValueError("SCRAPINGDOG_API_KEY environment variable not set.")
url_to_scrape = "https://example.com"
api_endpoint = "https://api.scrapingdog.com/scrape"
params = {
"api_key": api_key,
"url": url_to_scrape
}
try:
response = requests.get(api_endpoint, params=params)
response.raise_for_status() # Raise HTTPError for bad responses (4xx or 5xx)
print(response.text)
except requests.exceptions.HTTPError as http_err:
print(f"HTTP error occurred: {http_err}") # Python 3.6+
except Exception as err:
print(f"Other error occurred: {err}") # Python 3.6+
Before running the Python example, ensure you have set the SCRAPINGDOG_API_KEY environment variable with your actual API key. For instance, on Linux/macOS, you might use export SCRAPINGDOG_API_KEY="YOUR_API_KEY" in your terminal before executing the script. In Windows, you can set it via the system environment variables or using set SCRAPINGDOG_API_KEY=YOUR_API_KEY in the command prompt.
This example demonstrates passing the API key as a dictionary of parameters to the requests.get() method, which the library automatically formats into query parameters in the URL.
Security best practices
Securing your ScrapingDog API key is crucial to prevent unauthorized access to your account and services. Adhering to general API key security principles helps protect your usage limits and data. The Microsoft Azure documentation on API key management provides broader guidance on these best practices.
- Keep your API key confidential: Never expose your API key in client-side code (e.g., JavaScript in a browser) or embed it directly into publicly accessible files or repositories (like GitHub).
- Use environment variables: Store your API key as an environment variable on your server or development machine. This prevents the key from being hardcoded in your application's source code, making it easier to manage and less likely to be exposed.
- Do not commit keys to version control: Ensure your API key is excluded from version control systems (e.g., by adding it to a
.gitignorefile for Git repositories). - Restrict access: Limit who has access to your API key within your organization. Only individuals who require it for development or deployment purposes should have access.
- Use HTTPS for all requests: ScrapingDog enforces HTTPS for all API communications. This encrypts data in transit, protecting your API key and other sensitive information from interception. Verify that your application is always making requests over HTTPS.
- Regenerate keys periodically: Regularly regenerate your API key from the ScrapingDog dashboard, especially if you suspect it may have been compromised or if personnel with access to the key leave your team. Remember to update your applications with the new key immediately.
- Monitor usage: Keep an eye on your API usage statistics in the ScrapingDog dashboard. Unusual spikes in usage could indicate unauthorized access or a compromised key.
- Implement IP whitelisting (if available): If ScrapingDog were to offer IP whitelisting functionality in the future, configure it to allow API requests only from known, trusted IP addresses. While not currently listed as a feature, it's a common API security practice.