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.
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 requestsimport json# API credentialsAPI_PUBLIC_KEY ="your_public_key"API_PRIVATE_KEY ="your_private_key"BASE_URL ="https://api.pingproxies.com/1.0/public"# Headers for authenticationheaders ={"X-API-Public-Key": API_PUBLIC_KEY,"X-API-Private-Key": API_PRIVATE_KEY,"Content-Type":"application/json"}defupdate_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 orNoneif 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 successfulif response.status_code ==200:return response.json()else:print(f"Error: {response.status_code}")print(response.text)returnNone# Example usageif __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