Skip to main content
This example demonstrates how to manage Proxy User ACL (Access Control List) entries. You’ll learn how to view current ACLs, add new access permissions, and revoke access to services or proxies.

Overview

Common ACL management operations include:
  • Searching ACLs to see current permissions
  • Adding ACL entries to grant new access
  • Removing ACL entries to revoke access
  • Changing access types (e.g., from service to proxy restricted)
import requests

# 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 search_acls(proxy_user_id):
    """
    Search for all ACL entries for a specific proxy user.

    Args:
        proxy_user_id: The proxy user ID to search ACLs for

    Returns:
        List of ACL entries or None if failed
    """
    params = {"proxy_user_id": proxy_user_id}

    response = requests.get(
        f"{BASE_URL}/user/proxy_user_acl/search",
        params=params,
        headers=headers
    )

    if response.status_code != 200:
        print(f"Error searching ACLs: {response.status_code}")
        print(response.text)
        return None

    data = response.json()
    acls = data.get("data", [])

    print(f"\nFound {len(acls)} ACL entries for {proxy_user_id}:")
    for acl in acls:
        acl_id = acl.get("proxy_user_acl_id")
        service_id = acl.get("service_id")
        proxy_id = acl.get("proxy_id")

        if service_id:
            print(f"  - ACL {acl_id}: Service access to {service_id}")
        elif proxy_id:
            print(f"  - ACL {acl_id}: Proxy access to {proxy_id}")

    return acls

def add_service_access(proxy_user_id, service_id):
    """
    Add service access for a proxy user.

    Args:
        proxy_user_id: The proxy user ID
        service_id: The service ID to grant access to

    Returns:
        The created ACL ID or None if failed
    """
    payload = {
        "proxy_user_id": proxy_user_id,
        "service_id": service_id
    }

    response = requests.post(
        f"{BASE_URL}/user/proxy_user_acl/create",
        json=payload,
        headers=headers
    )

    if response.status_code != 201:
        print(f"Error adding service access: {response.status_code}")
        print(response.text)
        return None

    data = response.json()
    acl_id = data["created"][0]
    print(f"Successfully granted access to service {service_id}")
    return acl_id

def add_proxy_access(proxy_user_id, proxy_id):
    """
    Add proxy access for a proxy user.

    Args:
        proxy_user_id: The proxy user ID
        proxy_id: The proxy ID to grant access to

    Returns:
        The created ACL ID or None if failed
    """
    payload = {
        "proxy_user_id": proxy_user_id,
        "proxy_id": proxy_id
    }

    response = requests.post(
        f"{BASE_URL}/user/proxy_user_acl/create",
        json=payload,
        headers=headers
    )

    if response.status_code != 201:
        print(f"Error adding proxy access: {response.status_code}")
        print(response.text)
        return None

    data = response.json()
    acl_id = data["created"][0]
    print(f"Successfully granted access to proxy {proxy_id}")
    return acl_id

def remove_acl(acl_id):
    """
    Remove an ACL entry to revoke access.

    Args:
        acl_id: The ACL ID to delete

    Returns:
        True if successful, False otherwise
    """
    response = requests.delete(
        f"{BASE_URL}/user/proxy_user_acl/delete/{acl_id}",
        headers=headers
    )

    if response.status_code != 200:
        print(f"Error removing ACL: {response.status_code}")
        print(response.text)
        return False

    print(f"Successfully removed ACL {acl_id}")
    return True

def change_access_type_to_all(proxy_user_id):
    """
    Change a proxy user's access type to 'all' (unrestricted).
    This will also clear all existing ACL entries.

    Args:
        proxy_user_id: The proxy user ID

    Returns:
        True if successful, False otherwise
    """
    payload = {
        "proxy_user_access_type": "all",
        "clear_proxy_user_acl": True
    }

    response = requests.patch(
        f"{BASE_URL}/user/proxy_user/edit/{proxy_user_id}",
        json=payload,
        headers=headers
    )

    if response.status_code != 200:
        print(f"Error changing access type: {response.status_code}")
        print(response.text)
        return False

    print(f"Successfully changed {proxy_user_id} to unrestricted access")
    return True

# Example usage
if __name__ == "__main__":
    PROXY_USER_ID = "seo_team"

    print("=== Example 1: View Current ACLs ===")
    current_acls = search_acls(PROXY_USER_ID)

    print("\n=== Example 2: Add Service Access ===")
    add_service_access(PROXY_USER_ID, "API-NEW-SERVICE-001")

    print("\n=== Example 3: Add Multiple Services ===")
    for service_id in ["API-SERVICE-002", "API-SERVICE-003"]:
        add_service_access(PROXY_USER_ID, service_id)

    print("\n=== Example 4: View Updated ACLs ===")
    updated_acls = search_acls(PROXY_USER_ID)

    print("\n=== Example 5: Remove Specific ACL ===")
    if updated_acls and len(updated_acls) > 0:
        first_acl_id = updated_acls[0].get("proxy_user_acl_id")
        remove_acl(first_acl_id)

    print("\n=== Example 6: Change to Unrestricted Access ===")
    # Uncomment to change to unrestricted access (removes all ACLs)
    # change_access_type_to_all(PROXY_USER_ID)

Common Operations

1. View Current Permissions

Search ACLs to see what a proxy user currently has access to:
curl --request GET \
  --url 'https://api.pingproxies.com/1.0/public/user/proxy_user_acl/search?proxy_user_id=seo_team' \
  --header 'X-API-Public-Key: your_public_key' \
  --header 'X-API-Private-Key: your_private_key'
Response:
{
  "data": [
    {
      "proxy_user_acl_id": "uuid-1",
      "proxy_user_id": "seo_team",
      "service_id": "API-SEO-001",
      "proxy_user_acl_creation_datetime": "2023-09-28 12:34:56"
    },
    {
      "proxy_user_acl_id": "uuid-2",
      "proxy_user_id": "seo_team",
      "service_id": "API-SEO-002",
      "proxy_user_acl_creation_datetime": "2023-09-29 14:22:10"
    }
  ],
  "message": "Proxy User Acl search successful."
}

2. Grant New Access

Add a new ACL entry to grant access to another service or proxy:
curl --request POST \
  --url 'https://api.pingproxies.com/1.0/public/user/proxy_user_acl/create' \
  --header 'Content-Type: application/json' \
  --header 'X-API-Public-Key: your_public_key' \
  --header 'X-API-Private-Key: your_private_key' \
  --data '{
    "proxy_user_id": "seo_team",
    "service_id": "API-NEW-SERVICE"
  }'

3. Revoke Access

Delete an ACL entry to remove access:
curl --request DELETE \
  --url 'https://api.pingproxies.com/1.0/public/user/proxy_user_acl/delete/uuid-1' \
  --header 'X-API-Public-Key: your_public_key' \
  --header 'X-API-Private-Key: your_private_key'

4. Change from Restricted to Unrestricted

To give a proxy user unrestricted access, change the access type to "all" and clear ACLs:
curl --request PATCH \
  --url 'https://api.pingproxies.com/1.0/public/user/proxy_user/edit/seo_team' \
  --header 'Content-Type: application/json' \
  --header 'X-API-Public-Key: your_public_key' \
  --header 'X-API-Private-Key: your_private_key' \
  --data '{
    "proxy_user_access_type": "all",
    "clear_proxy_user_acl": true
  }'
Setting clear_proxy_user_acl: true is required when changing to "all" if ACLs exist. This ensures all ACL entries are removed.

Use Cases

Audit Access Permissions

Scenario: You need to audit which services or proxies each proxy user can access. Solution: Loop through all proxy users and search their ACLs to generate an access report.

Bulk Access Updates

Scenario: A new service is available and you need to grant access to multiple proxy users. Solution: For each proxy user that needs access, create an ACL entry with the new service ID.

Temporary Access

Scenario: Grant temporary access to a proxy user for testing, then revoke it. Solution:
  1. Create ACL entry for the service/proxy
  2. Proxy user performs testing
  3. Delete the ACL entry to revoke access

Access Migration

Scenario: Move a proxy user from one service to another. Solution:
  1. Create new ACL for the target service
  2. Delete old ACL for the previous service

Search Parameters

The ACL search endpoint supports filtering by:
ParameterDescriptionExample
proxy_user_idFilter by proxy user?proxy_user_id=seo_team
service_idFilter by service?service_id=API-SEO-001
proxy_idFilter by proxy?proxy_id=550e8400-e29b-41d4-a716-446655440001
pagePage number?page=1
per_pageResults per page?per_page=50