This example demonstrates how to retrieve all your proxies using pagination, storing the results in a list.

import requests
import math

# 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_all_proxies():
    """Retrieve all proxies using pagination."""
    proxies = []
    page = 1
    per_page = 100  # Maximum recommended page size
    total_pages = 1  # Initial value, will be updated after first request
    
    # Make initial request to get first page and total count
    response = requests.get(
        f"{BASE_URL}/user/proxy/search",
        params={"page": page, "per_page": per_page},
        headers=headers
    )
    
    if response.status_code != 200:
        print(f"Error: {response.status_code}")
        return []
    
    data = response.json()
    
    # Calculate total pages
    total_count = data["total_count"]
    total_pages = math.ceil(total_count / per_page)
    
    print(f"Found {total_count} proxies across {total_pages} pages")
    
    # Add first page results to our list
    proxies.extend(data["data"])
    
    # Fetch remaining pages
    for page in range(2, total_pages + 1):
        print(f"Fetching page {page} of {total_pages}")
        response = requests.get(
            f"{BASE_URL}/user/proxy/search",
            params={"page": page, "per_page": per_page},
            headers=headers
        )
        
        if response.status_code == 200:
            page_data = response.json()
            proxies.extend(page_data["data"])
        else:
            print(f"Error fetching page {page}: {response.status_code}")
    
    print(f"Successfully retrieved {len(proxies)} proxies")
    return proxies

# Example usage
if __name__ == "__main__":
    all_proxies = get_all_proxies()
    
    # Print the first proxy as an example
    if all_proxies:
        print("\nSample proxy:")
        print(f"  ID: {all_proxies[0]['proxy_id']}")
        print(f"  IP: {all_proxies[0]['proxy_ip_address']}")
        print(f"  Type: {all_proxies[0]['proxy_type']}")
        print(f"  Country: {all_proxies[0]['country_id']}")