Skip to main content
This example demonstrates how to create a proxy user with service-restricted access. This is useful for organizing access by teams, departments, or customers where each needs access to specific proxy services but not others.

Overview

The process involves two steps:
  1. Create a proxy user with proxy_user_access_type: "service_restricted"
  2. Create Proxy User ACL entries to grant access to specific services
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 create_service_restricted_proxy_user(user_id, password, service_ids, metadata=None):
    """
    Create a proxy user with service-restricted access.

    Args:
        user_id: ID for the proxy user
        password: Password for the proxy user
        service_ids: List of service IDs to grant access to
        metadata: Optional metadata dictionary

    Returns:
        Tuple of (proxy_user_data, acl_ids) or (None, None) if failed
    """

    # Step 1: Create the proxy user with service_restricted access type
    create_user_payload = {
        "proxy_user_id": user_id,
        "proxy_user_password": password,
        "proxy_user_access_type": "service_restricted"
    }

    if metadata:
        create_user_payload["proxy_user_metadata"] = metadata

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

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

    user_data = response.json()
    print(f"Successfully created proxy user: {user_id}")

    # Step 2: Create ACL entries for each service
    acl_ids = []
    for service_id in service_ids:
        acl_payload = {
            "proxy_user_id": user_id,
            "service_id": service_id
        }

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

        if acl_response.status_code != 201:
            print(f"Error creating ACL for service {service_id}: {acl_response.status_code}")
            print(acl_response.text)
            continue

        acl_data = acl_response.json()
        acl_id = acl_data["created"][0]
        acl_ids.append(acl_id)
        print(f"Granted access to service: {service_id}")

    return user_data, acl_ids

# Example usage
if __name__ == "__main__":
    # Create an SEO team proxy user with access to two services
    USER_ID = "seo_team"
    PASSWORD = "securepassword123"
    SERVICE_IDS = ["API-SEO-001", "API-SEO-002"]
    METADATA = {
        "department": "SEO",
        "team_lead": "Jane Smith",
        "purpose": "keyword_research"
    }

    user_data, acl_ids = create_service_restricted_proxy_user(
        user_id=USER_ID,
        password=PASSWORD,
        service_ids=SERVICE_IDS,
        metadata=METADATA
    )

    if user_data:
        print("\n=== Setup Complete ===")
        print(f"Proxy User ID: {USER_ID}")
        print(f"Password: {PASSWORD}")
        print(f"Access Type: service_restricted")
        print(f"Services Granted: {', '.join(SERVICE_IDS)}")
        print(f"ACL Entries Created: {len(acl_ids)}")

Key Points

1. Access Type Must Be Set

When creating the proxy user, you must set proxy_user_access_type to "service_restricted":
{
  "proxy_user_id": "seo_team",
  "proxy_user_password": "securepassword123",
  "proxy_user_access_type": "service_restricted"
}

2. ACL Entries Grant Actual Access

After creating the proxy user, create one ACL entry for each service they should access:
{
  "proxy_user_id": "seo_team",
  "service_id": "API-SEO-001"
}
The proxy user can access all proxies within each granted service.

3. Multiple Services

You can grant access to multiple services by creating multiple ACL entries:
  • ACL 1: seo_teamAPI-SEO-001
  • ACL 2: seo_teamAPI-SEO-002
  • ACL 3: seo_teamAPI-SEO-003

Use Cases

Team-Based Access Control

Scenario: Your company has different teams that need access to different proxy pools. Implementation:
  • SEO Team → Service: API-SEO-PROXIES
  • Marketing Team → Service: API-MARKETING-PROXIES
  • Research Team → Service: API-RESEARCH-PROXIES

Customer Segregation

Scenario: You provide proxy services to multiple customers, each should only access their allocated services. Implementation:
  • Customer A → Services: API-CUSTOMER-A-001, API-CUSTOMER-A-002
  • Customer B → Service: API-CUSTOMER-B-001

Environment Separation

Scenario: Separate production and development proxy access. Implementation:
  • Production User → Service: API-PROD-PREMIUM
  • Development User → Service: API-DEV-TESTING

Verifying Access

After setup, you can verify the ACL entries were created:
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'

Managing Access

Adding More Services

Create additional ACL entries to grant access to more services:
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-SEO-003"
  }'

Removing Service Access

Delete an ACL entry to revoke access to a service:
curl --request DELETE \
  --url 'https://api.pingproxies.com/1.0/public/user/proxy_user_acl/delete/{proxy_user_acl_id}' \
  --header 'X-API-Public-Key: your_public_key' \
  --header 'X-API-Private-Key: your_private_key'