Examples

  • Find all proxy users associated with a specific department
  • Find proxy users with a employee_id within a certain range
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/user"

# Headers for authentication
headers = {
    "X-API-Public-Key": API_PUBLIC_KEY,
    "X-API-Private-Key": API_PRIVATE_KEY
}

# Example 1: Search proxy users by exact metadata match (department = "Marketing")
# This will find all proxy users that have their department field in metadata set to "Marketing"
exact_match_url = f"{BASE_URL}/proxy_user/search"
exact_match_params = {
    "proxy_user_metadata.department": "Marketing"
}

# Make the API request
exact_match_response = requests.get(exact_match_url, headers=headers, params=exact_match_params)

# Check if the request was successful
if exact_match_response.status_code == 200:
    exact_match_data = exact_match_response.json()
    print(f"Found {exact_match_data['total_count']} proxy users in Marketing department:")
    
    # Display the results
    for proxy_user in exact_match_data['data']:
        print(f"  - {proxy_user['proxy_user_id']}: {proxy_user.get('proxy_user_metadata', {})}")
else:
    print(f"Error in exact match search: {exact_match_response.status_code}")
    print(exact_match_response.text)

# Example 2: Search proxy users by metadata range (employee_id between 1000 and 5000)
# This will find all proxy users that have a employee_id value between 1000 and 5000
range_url = f"{BASE_URL}/proxy_user/search"
range_params = {
    "proxy_user_metadata.min_employee_id": 1000,
    "proxy_user_metadata.max_employee_id": 5000
}

# Make the API request
range_response = requests.get(range_url, headers=headers, params=range_params)

# Check if the request was successful
if range_response.status_code == 200:
    range_data = range_response.json()
    print(f"\nFound {range_data['total_count']} proxy users with employee_id between 1000 and 5000:")
    
    # Display the results
    for proxy_user in range_data['data']:
        print(f"  - {proxy_user['proxy_user_id']}: EmployeeId = {proxy_user.get('proxy_user_metadata', {}).get('employee_id', 'N/A')}")
else:
    print(f"Error in range search: {range_response.status_code}")
    print(range_response.text)

Key Concepts

  1. Exact Metadata Matching: Use proxy_user_metadata.field_name to search for proxy users with a specific value in their metadata.

  2. Range Filtering: Use proxy_user_metadata.min_field_name and proxy_user_metadata.max_field_name to search for proxy users with metadata values within a specific range.

Advanced Metadata Search Operators

In addition to exact matching and range filtering, the Ping Proxies API supports several advanced operators that provide more flexibility when searching proxy users by their metadata.

Pattern Matching with like_

The like_ operator allows you to search for proxy users with metadata fields that match a specific pattern. This is particularly useful for partial text matches.

Example: Find proxy users with email addresses from a specific domain

proxy_user_metadata.like_email=@example.com

This will match any proxy user with an email field in their metadata that contains “@example.com”.

Example: Find proxy users with names starting with a specific prefix

proxy_user_metadata.like_name=John%

The % character acts as a wildcard. This query would match names like “John”, “Johnny”, “Johnson”, etc.

Existence Checking with exists_

The exists_ operator allows you to find proxy users that have a particular metadata field defined, regardless of its value.

Example: Find proxy users that have a department field

exists_proxy_user_metadata.department=true

This will return all proxy users that have the “department” field in their metadata, regardless of what department it is.

Example: Find proxy users without a specific field

exists_proxy_user_metadata.end_date=false

This will return all proxy users that do not have an “end_date” field in their metadata.

Negation with not_

The not_ operator allows you to find proxy users where a metadata field does not match a specific value.

Example: Find proxy users not in the Marketing department

proxy_user_metadata.not_department=Marketing

This will return all proxy users whose department field is not set to “Marketing”.

Example: Find proxy users with employee_id outside a specific range

proxy_user_metadata.not_min_employee_id=1000
proxy_user_metadata.not_max_employee_id=5000

This will return proxy users whose employee_id is less than 1000 or greater than 5000.

Combining Search Operators

You can combine multiple search operators to create complex queries.

Example: Find active proxy users in the Sales department with an email from example.com

proxy_user_metadata.department=Sales
proxy_user_metadata.status=active
proxy_user_metadata.like_email=@example.com

Example: Find proxy users with a project field but without an end_date

exists_proxy_user_metadata.project=true
exists_proxy_user_metadata.end_date=false