glam/scripts/test_unipile_api.py
2025-12-10 13:01:13 +01:00

63 lines
No EOL
2 KiB
Python

#!/usr/bin/env python3
"""
Test Unipile API endpoints and authentication.
"""
import os
import httpx
import json
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv('UNIPILE_API_KEY')
dsn = os.getenv('UNIPILE_DSN', 'api1.unipile.com:13111')
print(f"API Key: {api_key[:20]}..." if api_key else "NOT SET")
print(f"DSN: {dsn}")
# Test different endpoints
base_urls = [
f"https://{dsn}/api/v1",
f"https://api1.unipile.com:13111/api/v1",
f"https://api.unipile.io/api/v1"
]
headers_options = [
{"X-API-KEY": api_key},
{"Authorization": f"Bearer {api_key}"},
{"accept": "application/json", "X-API-KEY": api_key},
{"accept": "application/json", "Authorization": f"Bearer {api_key}"}
]
test_identifier = "giovannafossati" # Known profile
for base_url in base_urls:
print(f"\n--- Testing base URL: {base_url} ---")
for headers in headers_options:
print(f"\nHeaders: {json.dumps(headers, indent=2)}")
# Test endpoints
endpoints = [
f"/users/{test_identifier}",
f"/linkedin/profile/{test_identifier}",
f"/profile/{test_identifier}",
f"/person/{test_identifier}",
f"/contact/{test_identifier}"
]
for endpoint in endpoints:
url = base_url + endpoint
try:
with httpx.Client(timeout=10.0) as client:
response = client.get(url, headers=headers)
print(f" {endpoint}: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f" SUCCESS! Found: {data.get('full_name', data.get('name', 'Unknown'))}")
break
elif response.status_code in [401, 403]:
print(f" AUTH ERROR")
break
except Exception as e:
print(f" {endpoint}: EXCEPTION - {e}")