This guide demonstrates how to programmatically purchase static residential proxies through the Ping Proxies API and then export them to a text file. The process involves:

  1. Getting product information using the catalog endpoint
  2. Creating a checkout for static residential proxies
  3. Exporting the proxies to a text file using list_by_search

Prerequisites

Before you begin, you’ll need:

  • Your Ping Proxies API keys (both public and private)
  • Enough credit balance in your account or a payment method set up

Implementation Examples

import requests
import json

# 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"
}

# For this example, we'll directly use US static residential proxies
product_code = "isp_us"  # Change this to your desired product code
quantity = 5  # Change this to your desired quantity

# Step 2: Create a checkout
checkout_url = f"{BASE_URL}/user/checkout/create"
checkout_payload = {
    "product_code": product_code,
    "quantity": quantity,
    "cycle_interval": "month",
    "cycle_interval_count": 1
}

checkout_response = requests.post(checkout_url, headers=headers, json=checkout_payload)

if checkout_response.status_code != 201:
    print(f"Error creating checkout: {checkout_response.status_code}")
    print(checkout_response.text)
    exit(1)

checkout_data = checkout_response.json()
print(f"Checkout created successfully!")

# Extract service ID directly from the response
service_id = checkout_data["data"]["service_id"]
print(f"Service ID: {service_id}")

# In a production environment, you might want to add a polling mechanism
# to check if the service is active before proceeding
# time.sleep(10)  # Simple wait - replace with polling in production

# Step 3: Export proxies to a text file using list_by_search
export_url = f"{BASE_URL}/user/proxy/list_by_search"
export_params = {
    "service_id": service_id,
    "list_format": "http",  # Format: http, socks5, socks5h, or standard
    "list_protocol": "http",  # Protocol: http or socks5
    "list_authentication": "username_and_password"  # Authentication type
}

export_response = requests.get(export_url, headers=headers, params=export_params)

if export_response.status_code != 200:
    print(f"Error exporting proxies: {export_response.status_code}")
    print(export_response.text)
    exit(1)

export_data = export_response.json()
proxies = export_data["data"]

# Write proxies to a text file
filename = f"{product_code}_proxies.txt"
with open(filename, "w") as f:
    for proxy in proxies:
        f.write(f"{proxy}\n")

print(f"Successfully exported {len(proxies)} proxies to {filename}")

Process Overview

  1. Product Selection:

    • We directly use the product code for US static residential proxies (“isp_us”)
    • You can find available product codes in your dashboard or using the catalog endpoint
  2. Checkout Creation:

    • We create a checkout using the product code, quantity, and billing cycle
    • The API returns a service ID which we’ll use to access our proxies
  3. Proxy Export:

    • Once the purchase is complete, we use the list_by_search endpoint to get our proxies
    • We filter by service ID and specify the format we want (HTTP in this example)
    • Finally, we save the proxies to a text file

Additional Considerations

  • In a production environment, implement a polling mechanism to check if the service is active before attempting to export proxies
  • The default proxy user credentials are used in this example
  • You may want to create a custom proxy user for better organization and access control