import requests
# API credentials
API_PUBLIC_KEY = "your_public_key"
API_PRIVATE_KEY = "your_private_key"
BASE_URL = "https://api.pingproxies.com/1.0/public"
# Headers for authentication
headers = {
"X-API-Public-Key": API_PUBLIC_KEY,
"X-API-Private-Key": API_PRIVATE_KEY,
"Content-Type": "application/json"
}
def create_department_proxy_user(user_id, password, department, bandwidth_limit_bytes, service_id):
"""
Create a proxy user for a specific department with bandwidth limits and service restriction.
Args:
user_id: ID to be used for the proxy user
password: Password for the proxy user
department: Department name (for metadata)
bandwidth_limit_bytes: Residential bandwidth limit in bytes
service_id: Service ID to restrict this proxy user to
Returns:
Created proxy user details or None if creation failed
"""
# Convert GB to bytes (10GB = 10 * 1024 * 1024 * 1024 bytes)
# Create the request payload
payload = {
"proxy_user_id": user_id,
"proxy_user_password": password,
"proxy_user_is_service_restricted": True,
"restricted_service_ids": [service_id],
"proxy_user_residential_bytes_limit": bandwidth_limit_bytes,
"proxy_user_metadata": {
"department": department,
"created_by": "api",
"purpose": "seo_monitoring"
}
}
# Make request to create the proxy user
response = requests.post(
f"{BASE_URL}/user/proxy_user/create",
json=payload,
headers=headers
)
if response.status_code != 201: # This endpoint returns 201 Created on success
print(f"Error: {response.status_code}")
print(response.text)
return None
data = response.json()
print(f"Successfully created proxy user for {department} department")
return data
# Example usage
if __name__ == "__main__":
# Define parameters
DEPARTMENT = "SEO"
USER_ID = "seodepartment"
PASSWORD = "strongpassword123"
SERVICE_ID = "API-1234-5678" # Replace with your actual service ID
# Convert 10GB to bytes
BANDWIDTH_LIMIT_GB = 10
BANDWIDTH_LIMIT_BYTES = BANDWIDTH_LIMIT_GB * 1024 * 1024 * 1024
# Create the proxy user
result = create_department_proxy_user(
user_id=USER_ID,
password=PASSWORD,
department=DEPARTMENT,
bandwidth_limit_bytes=BANDWIDTH_LIMIT_BYTES,
service_id=SERVICE_ID
)
if result:
print("Proxy User Details:")
print(f" ID: {result['data']['proxy_user_id']}")
print(f" Password: {result['data']['proxy_user_password']}")
print(f" Service Restricted: Yes, to service {SERVICE_ID}")
print(f" Bandwidth Limit: {BANDWIDTH_LIMIT_GB}GB")