Updating Proxy User Metadata

This example demonstrates how to edit an existing proxy user’s metadata using the Ping Proxies API. Metadata is a flexible way to store custom information with your proxy users, which can be useful for organizing, tracking, and managing your proxy infrastructure.

Use Cases for Metadata

  • Organization: Tag proxy users by department, project, or team
  • Tracking: Store reference IDs from your internal systems
  • Usage: Track purpose, permissions, or usage limits
  • Custom Properties: Store any information that’s relevant to your workflow
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

Metadata Fields Explained

When updating proxy user metadata, keep these constraints in mind:

  • Structure: Metadata must be a flat JSON object (no nested objects)
  • Size: Maximum 30 keys per metadata object
  • Value length: Each value’s string representation must be ≤ 300 characters
  • Total size: The entire metadata object must be ≤ 32KB
  • Supported value types: String, boolean, float, and integer values

Sample Response

{
  "edited": [
    "seoteamuser"
  ],
  "message": "Proxy User successfully edited."
}