Python Examples

Complete examples for integrating ClickyID API with Python.

Setup
Install the required dependencies for making API requests
pip install requests
# or
pip install httpx  # for async support
Basic Email Validation
Create a Python client for validating email addresses against target groups
Loading syntax highlighting...
Offer Validation
Validate an email address against a specific offer
def validate_offer(self, email: str, offer_id: str) -> Dict:
    """Validate if an email is eligible for an offer."""
    url = f"{self.base_url}/validate/offer"
    payload = {
        "email": email,
        "offerId": offer_id
    }
    
    try:
        response = self.session.post(url, json=payload)
        response.raise_for_status()
        return response.json()
    except requests.exceptions.HTTPError as e:
        if response.status_code == 400:
            error_data = response.json()
            return {
                "eligible": False, 
                "error": error_data.get("message", "Email not eligible")
            }
        else:
            raise Exception(f"API error: {response.status_code}")

# Add this method to the ClickyIDClient class

# Usage
try:
    result = client.validate_offer("student@university.edu", "off_1234567890")
    
    if result.get("eligible"):
        offer = result.get("offer", {})
        print(f"Discount code: {offer.get('discountCode')}")
        print(f"Discount: {offer.get('discountPercentage')}%")
        print(f"Offer title: {offer.get('title')}")
    else:
        print(f"Not eligible: {result.get('error', 'Unknown reason')}")
        
except Exception as e:
    print(f"Error: {e}")
Bulk Validation
Validate multiple email addresses in a single request
def bulk_validate_emails(self, emails: list, target_group_id: str) -> Dict:
    """Validate multiple emails in bulk."""
    url = f"{self.base_url}/validate/bulk"
    payload = {
        "emails": emails,
        "targetGroupId": target_group_id
    }
    
    try:
        response = self.session.post(url, json=payload)
        response.raise_for_status()
        return response.json()
    except requests.exceptions.HTTPError as e:
        raise Exception(f"Bulk validation failed: {response.status_code}")

# Add this method to the ClickyIDClient class

# Usage
email_list = [
    "student1@university.edu",
    "student2@college.edu", 
    "student3@school.edu"
]

try:
    result = client.bulk_validate_emails(email_list, "tg_1234567890")
    
    summary = result.get("summary", {})
    print(f"Validated {summary.get('total')} emails")
    print(f"Valid: {summary.get('valid')}, Invalid: {summary.get('invalid')}")
    
    for item in result.get("results", []):
        if item.get("valid"):
            print(f"✓ {item['email']} - {item.get('university')}")
        else:
            print(f"✗ {item['email']} - {item.get('reason')}")
            
except Exception as e:
    print(f"Error: {e}")
Django Integration
Integrate ClickyID validation into your Django application
Loading syntax highlighting...
Async Support with httpx
Use async/await for high-performance concurrent validations
Loading syntax highlighting...
Error Handling and Retry Logic
Robust error handling with automatic retry on failures
Loading syntax highlighting...

Next Steps

Quick Start

Get started with the ClickyID API in just a few minutes.

Authentication

Learn how to authenticate your API requests and manage API keys.

API Reference

Complete reference for all ClickyID API endpoints.

Error Handling

Learn best practices for handling API errors and rate limits.