-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_usage.py
More file actions
83 lines (65 loc) · 2.92 KB
/
example_usage.py
File metadata and controls
83 lines (65 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
"""
GetResponse API Integration - Example Usage
===========================================
This script demonstrates how to use the GetResponseClient class
for common email marketing operations.
Setup Instructions:
1. Install dependencies: pip install -r requirements.txt
2. Create a .env file with your API key:
GETRESPONSE_API_KEY=your_api_key_here
3. Run this script to test the integration
Author: Agent Zero
Date: 2025-11-06
"""
import os
from getresponse_client import GetResponseClient
def main():
"""Demonstrate GetResponse API operations."""
try:
# Initialize client (will load API key from .env file)
client = GetResponseClient()
print("🚀 GetResponse API Integration Demo")
print("=" * 50)
# Test connection
if client.test_connection():
print("✅ Connection successful!")
else:
print("❌ Connection failed. Please check your API key.")
return
# Get account information
account_info = client.get_account_info()
print(f"\n👤 Account: {account_info.get('firstName', 'N/A')} {account_info.get('lastName', 'N/A')}")
print(f"📧 Email: {account_info.get('email', 'N/A')}")
# Get all campaigns
campaigns = client.get_campaigns()
print(f"\n📋 Found {len(campaigns)} campaigns:")
for i, campaign in enumerate(campaigns[:5], 1): # Show first 5
print(f" {i}. {campaign['name']} (ID: {campaign['campaignId']})")
if len(campaigns) > 5:
print(f" ... and {len(campaigns) - 5} more campaigns")
# Example: Search for contacts
print(f"\n🔍 Searching for contacts...")
contacts = client.search_contacts(limit=5)
print(f" Found {len(contacts)} contacts (showing first 5)")
for i, contact in enumerate(contacts[:3], 1):
print(f" {i}. {contact.get('name', 'No Name')} - {contact.get('email', 'No Email')}")
print("\n" + "=" * 50)
print("📚 Available Methods:")
print(" • add_contact(email, campaign_id, name=None)")
print(" • remove_contact_by_email(email)")
print(" • get_campaigns()")
print(" • search_contacts(query=None)")
print(" • get_contact_by_email(email)")
print(" • update_contact(contact_id, name=None, campaign_id=None)")
print("\n💡 Check getresponse_client.py for complete documentation!")
except ValueError as e:
print(f"❌ Error: {e}")
print("\n🔧 Setup Instructions:")
print("1. Create a .env file in the same directory")
print("2. Add: GETRESPONSE_API_KEY=your_actual_api_key")
print("3. Get your API key from: https://app.getresponse.com/api")
except Exception as e:
print(f"❌ Unexpected error: {e}")
if __name__ == "__main__":
main()