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"
}
def update_proxy_user_metadata(proxy_user_id, metadata):
"""
Update the metadata for an existing proxy user.
Args:
proxy_user_id: ID of the proxy user to edit
metadata: Dictionary containing metadata key-value pairs
Returns:
API response or None if the update failed
"""
# Build the request URL
url = f"{BASE_URL}/user/proxy_user/edit/{proxy_user_id}"
# Create the payload with only the metadata field
payload = {
"proxy_user_metadata": metadata
}
# Make the API request
response = requests.patch(url, headers=headers, json=payload)
# Check if the request was successful
if response.status_code == 200:
return response.json()
else:
print(f"Error: {response.status_code}")
print(response.text)
return None
# Example usage
if __name__ == "__main__":
# Define parameters
PROXY_USER_ID = "seoteamuser"
# Define metadata to update
metadata = {
"department": "SEO",
"project": "Competitor Analysis",
"manager": "Jane Smith",
"cost_center": "MKTG-123",
"usage_priority": "high",
"notes": "Updated for Q2 campaign"
}
# Update the proxy user metadata
result = update_proxy_user_metadata(PROXY_USER_ID, metadata)
if result:
print("Proxy user metadata updated successfully")
print(f"Edited proxy user: {result['edited'][0]}")
else:
print("Failed to update proxy user metadata")
# Note: You can also update other fields at the same time as metadata:
# - proxy_user_password: Update the password
# - proxy_user_is_service_restricted: Restrict to specific services
# - restricted_service_ids: List of allowed service IDs
# - proxy_user_is_strict_security: Enable strict security
# - ip_address_authentications: List of allowed IP addresses
# - proxy_user_residential_bytes_limit: Set bandwidth limits