This example demonstrates how to retrieve all proxies that belong to a specific service using the /proxy/search endpoint with a service ID filter.

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
}

def get_proxies_by_service_id(service_id):
    """
    Retrieve all proxies associated with a specific service ID.
    
    Args:
        service_id: The unique identifier of the service
        
    Returns:
        List of proxy objects belonging to the service
    """
    # Set up the parameters for the search
    params = {
        "service_id": service_id,
        "per_page": 100  # Adjust as needed
    }
    
    # Make request to the proxy search endpoint
    response = requests.get(
        f"{BASE_URL}/user/proxy/search",
        params=params,
        headers=headers
    )
    
    if response.status_code != 200:
        print(f"Error: {response.status_code}")
        print(response.text)
        return []
    
    data = response.json()
    
    print(f"Successfully retrieved {len(data['data'])} proxies for service {service_id}")
    return data['data']

def display_proxy_summary(proxies):
    """Display a summary of the retrieved proxies."""
    if not proxies:
        print("No proxies found for this service.")
        return
    
    # Group proxies by type
    proxy_types = {}
    countries = {}
    
    for proxy in proxies:
        proxy_type = proxy.get('proxy_type', 'unknown')
        country = proxy.get('country_id', 'unknown')
        
        proxy_types[proxy_type] = proxy_types.get(proxy_type, 0) + 1
        countries[country] = countries.get(country, 0) + 1
    
    print("\nProxy Types:")
    for ptype, count in proxy_types.items():
        print(f"  {ptype}: {count}")
    
    print("\nCountry Distribution:")
    for country, count in countries.items():
        print(f"  {country}: {count}")
    
    # Print sample proxy details
    print("\nSample Proxy Details:")
    sample = proxies[0]
    print(f"  ID: {sample.get('proxy_id')}")
    print(f"  IP Address: {sample.get('proxy_ip_address')}")
    print(f"  Type: {sample.get('proxy_type')}")
    print(f"  Protocol: {sample.get('proxy_protocol')}")
    print(f"  HTTP Port: {sample.get('proxy_http_port')}")
    print(f"  SOCKS5 Port: {sample.get('proxy_socks5_port')}")
    print(f"  Location: {sample.get('city_name')}, {sample.get('country_name')}")
    print(f"  ASN: {sample.get('asn_name')} (ASN {sample.get('asn_id')})")

# Example usage
if __name__ == "__main__":
    # Replace with your actual service ID
    SERVICE_ID = "API-1234-5678"
    
    proxies = get_proxies_by_service_id(SERVICE_ID)
    display_proxy_summary(proxies)

Key Concepts

  1. Service-based Filtering: The search endpoint supports filtering proxies by service ID.
  2. Multiple Formats: You can retrieve proxies in various formats depending on your needs.
  3. Full Proxy Details: The returned data includes all proxy attributes, including ports, protocols, and location information.