Create a proxy user with metadata, bandwidth limits and service restriction
Learn how to create a proxy user for your SEO with custom metadata, bandwidth limits and restricted to a specific service
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 credentialsAPI_PUBLIC_KEY ="your_public_key"API_PRIVATE_KEY ="your_private_key"BASE_URL ="https://api.pingproxies.com/1.0/public"# Headers for authenticationheaders ={"X-API-Public-Key": API_PUBLIC_KEY,"X-API-Private-Key": API_PRIVATE_KEY,"Content-Type":"application/json"}defcreate_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 inbytes service_id: Service ID to restrict this proxy user to Returns: Created proxy user details orNoneif 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 successprint(f"Error: {response.status_code}")print(response.text)returnNone data = response.json()print(f"Successfully created proxy user for {department} department")return data# Example usageif __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")
Adding department information to the proxy user’s metadata helps with organization and makes it easier to track usage and manage resources by department:
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: