This example demonstrates how to create a proxy user specifically for your SEO department with a 10GB bandwidth limit and restricted to a single service ID. This is useful for managing and controlling access to your proxy resources within different teams or departments.

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")

Key Features Explained

1. Department-Specific Metadata

Adding department information to the proxy user’s metadata helps with organization and makes it easier to track usage and manage resources by department:

"proxy_user_metadata": {
  "department": "SEO",
  "created_by": "api",
  "purpose": "seo_monitoring"
}

2. 10GB Bandwidth Limit

The example sets a 10GB bandwidth limit for residential proxy usage:

10GB = 10 * 1024 * 1024 * 1024 bytes = 10,737,418,240 bytes

This limit is applied through the proxy_user_residential_bytes_limit parameter.

3. Service Restriction

By setting proxy_user_is_service_restricted to true and providing the specific service ID in restricted_service_ids, you ensure that this proxy user can only access proxies from the designated service:

"proxy_user_is_service_restricted": true,
"restricted_service_ids": ["API-1234-5678"]