-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_complete.py
More file actions
489 lines (391 loc) · 17.2 KB
/
example_complete.py
File metadata and controls
489 lines (391 loc) · 17.2 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
#!/usr/bin/env python3
"""
Comprehensive example demonstrating all Dotloop API endpoints.
This example shows how to use every implemented endpoint in the Dotloop API wrapper.
Make sure to set your DOTLOOP_API_KEY environment variable or pass it directly.
"""
import os
from typing import Any, Dict, List
from dotloop import AuthClient, DotloopClient
from dotloop.enums import (
LoopStatus,
ParticipantRole,
ProfileType,
TransactionType,
WebhookEventType,
)
def main() -> None:
"""Demonstrate all Dotloop API functionality."""
# Initialize the main client
# Option 1: Use environment variable DOTLOOP_API_KEY
client = DotloopClient()
# Option 2: Pass API key directly
# client = DotloopClient(api_key="your_api_key_here")
print("🚀 Dotloop API Wrapper - Complete Example")
print("=" * 50)
try:
# 1. ACCOUNT ENDPOINTS
print("\n📋 1. ACCOUNT INFORMATION")
print("-" * 30)
account = client.account.get_account()
print(f"Account ID: {account['data']['id']}")
print(f"Account Name: {account['data']['name']}")
# 2. PROFILE ENDPOINTS
print("\n👤 2. PROFILE MANAGEMENT")
print("-" * 30)
# List all profiles
profiles = client.profile.list_profiles()
print(f"Found {len(profiles['data'])} profiles")
if profiles["data"]:
profile_id = profiles["data"][0]["id"]
print(f"Using profile ID: {profile_id}")
# Get specific profile
profile = client.profile.get_profile(profile_id=profile_id)
print(f"Profile: {profile['data']['name']}")
# Create a new profile (commented out to avoid creating test data)
# new_profile = client.profile.create_profile(
# name="Test Profile",
# company="Test Company",
# phone="+1 (555) 123-4567"
# )
# Update profile (commented out)
# updated_profile = client.profile.update_profile(
# profile_id=profile_id,
# phone="+1 (555) 999-8888"
# )
# 3. LOOP ENDPOINTS
print("\n🔄 3. LOOP MANAGEMENT")
print("-" * 30)
if profiles["data"]:
# List loops
loops = client.loop.list_loops(profile_id=profile_id)
print(f"Found {len(loops['data'])} loops")
if loops["data"]:
loop_id = loops["data"][0]["id"]
print(f"Using loop ID: {loop_id}")
# Get specific loop
loop = client.loop.get_loop(profile_id=profile_id, loop_id=loop_id)
print(f"Loop: {loop['data']['name']}")
print(f"Status: {loop['data']['status']}")
print(f"Transaction Type: {loop['data']['transactionType']}")
# Create a new loop (commented out)
# new_loop = client.loop.create_loop(
# profile_id=profile_id,
# name="Example Transaction",
# transaction_type=TransactionType.PURCHASE_OFFER,
# status=LoopStatus.PRE_OFFER
# )
# 4. LOOP-IT ENDPOINT (Create loop from template)
print("\n⚡ 4. LOOP-IT (Template-based Loop Creation)")
print("-" * 30)
# Create loop with Loop-It (commented out)
# loop_it_result = client.loop_it.create_loop(
# name="Quick Transaction",
# transaction_type=TransactionType.PURCHASE_OFFER,
# status=LoopStatus.PRE_OFFER,
# profile_id=profile_id,
# street_number="123",
# street_name="Main Street",
# city="San Francisco",
# state="CA",
# zip_code="94105"
# )
print("Loop-It endpoint available for quick loop creation from templates")
# 5. CONTACT ENDPOINTS
print("\n📞 5. CONTACT MANAGEMENT")
print("-" * 30)
# List contacts
contacts = client.contact.list_contacts()
print(f"Found {len(contacts['data'])} contacts")
if contacts["data"]:
contact_id = contacts["data"][0]["id"]
# Get specific contact
contact = client.contact.get_contact(contact_id=contact_id)
print(
f"Contact: {contact['data']['firstName']} {contact['data']['lastName']}"
)
# Create a new contact (commented out)
# new_contact = client.contact.create_contact(
# first_name="John",
# last_name="Doe",
# email="john.doe@example.com",
# phone="+1 (555) 123-4567"
# )
# 6. LOOP DETAILS
print("\n📝 6. LOOP DETAILS")
print("-" * 30)
if profiles["data"] and loops["data"]:
# Get loop details
details = client.loop_detail.get_loop_details(
profile_id=profile_id, loop_id=loop_id
)
print("Loop details retrieved successfully")
# Update loop details (commented out)
# updated_details = client.loop_detail.update_loop_details(
# profile_id=profile_id,
# loop_id=loop_id,
# purchase_price=500000,
# listing_price=525000
# )
# 7. FOLDER MANAGEMENT
print("\n📁 7. FOLDER MANAGEMENT")
print("-" * 30)
if profiles["data"] and loops["data"]:
# List folders
folders = client.folder.list_folders(profile_id=profile_id, loop_id=loop_id)
print(f"Found {len(folders['data'])} folders")
if folders["data"]:
folder_id = folders["data"][0]["id"]
# Get specific folder
folder = client.folder.get_folder(
profile_id=profile_id, loop_id=loop_id, folder_id=folder_id
)
print(f"Folder: {folder['data']['name']}")
# 8. DOCUMENT MANAGEMENT
print("\n📄 8. DOCUMENT MANAGEMENT")
print("-" * 30)
if profiles["data"] and loops["data"]:
# List documents
documents = client.document.list_documents(
profile_id=profile_id, loop_id=loop_id
)
print(f"Found {len(documents['data'])} documents")
if documents["data"]:
document_id = documents["data"][0]["id"]
# Get specific document
document = client.document.get_document(
profile_id=profile_id, loop_id=loop_id, document_id=document_id
)
print(f"Document: {document['data']['name']}")
print(f"Size: {document['data']['size']} bytes")
# 9. PARTICIPANT MANAGEMENT
print("\n👥 9. PARTICIPANT MANAGEMENT")
print("-" * 30)
if profiles["data"] and loops["data"]:
# List participants
participants = client.participant.list_participants(
profile_id=profile_id, loop_id=loop_id
)
print(f"Found {len(participants['data'])} participants")
if participants["data"]:
participant_id = participants["data"][0]["id"]
# Get specific participant
participant = client.participant.get_participant(
profile_id=profile_id,
loop_id=loop_id,
participant_id=participant_id,
)
print(f"Participant: {participant['data']['fullName']}")
print(f"Role: {participant['data']['role']}")
# 10. TASK MANAGEMENT
print("\n✅ 10. TASK MANAGEMENT")
print("-" * 30)
if profiles["data"] and loops["data"]:
# List task lists
task_lists = client.task.list_task_lists(
profile_id=profile_id, loop_id=loop_id
)
print(f"Found {len(task_lists['data'])} task lists")
if task_lists["data"]:
tasklist_id = task_lists["data"][0]["id"]
# Get specific task list
task_list = client.task.get_task_list(
profile_id=profile_id, loop_id=loop_id, tasklist_id=tasklist_id
)
print(f"Task List: {task_list['data']['name']}")
# List tasks in the task list
tasks = client.task.list_tasks(
profile_id=profile_id, loop_id=loop_id, tasklist_id=tasklist_id
)
print(f"Found {len(tasks['data'])} tasks in list")
# 11. ACTIVITY FEED
print("\n📊 11. ACTIVITY FEED")
print("-" * 30)
if profiles["data"] and loops["data"]:
# List loop activity
activities = client.activity.list_loop_activity(
profile_id=profile_id, loop_id=loop_id
)
print(f"Found {len(activities['data'])} activities")
# Get activity summary
summary = client.activity.get_activity_summary(
profile_id=profile_id, loop_id=loop_id
)
print(f"Total activities: {summary['total_activities']}")
print(f"Unique users: {summary['unique_users']}")
# 12. TEMPLATE MANAGEMENT
print("\n📋 12. TEMPLATE MANAGEMENT")
print("-" * 30)
if profiles["data"]:
# List loop templates
templates = client.template.list_loop_templates(profile_id=profile_id)
print(f"Found {len(templates['data'])} templates")
if templates["data"]:
template_id = templates["data"][0]["id"]
# Get specific template
template = client.template.get_loop_template(
profile_id=profile_id, template_id=template_id
)
print(f"Template: {template['data']['name']}")
print(f"Type: {template['data']['type']}")
print(f"Default: {template['data']['isDefault']}")
# 13. WEBHOOK MANAGEMENT
print("\n🔗 13. WEBHOOK MANAGEMENT")
print("-" * 30)
# List webhook subscriptions
subscriptions = client.webhook.list_subscriptions()
print(f"Found {len(subscriptions['data'])} webhook subscriptions")
if subscriptions["data"]:
subscription_id = subscriptions["data"][0]["id"]
# Get specific subscription
subscription = client.webhook.get_subscription(
subscription_id=subscription_id
)
print(f"Webhook: {subscription['data']['url']}")
print(f"Enabled: {subscription['data'].get('enabled')}")
# List events for subscription
events = client.webhook.list_events(subscription_id=subscription_id)
print(f"Found {len(events['data'])} webhook events")
# Create a new webhook subscription (commented out)
# new_webhook = client.webhook.create_subscription(
# url="https://your-app.com/webhook",
# target_type="PROFILE",
# target_id=15637525,
# event_types=[WebhookEventType.LOOP_CREATED, WebhookEventType.CONTACT_CREATED],
# enabled=True,
# )
print("\n✅ All endpoint demonstrations completed successfully!")
except Exception as e:
print(f"❌ Error: {e}")
print("Make sure you have set your DOTLOOP_API_KEY environment variable")
def demonstrate_oauth_flow() -> None:
"""Demonstrate OAuth authentication flow."""
print("\n🔐 OAUTH AUTHENTICATION FLOW")
print("-" * 30)
# Initialize OAuth client
auth_client = AuthClient(
client_id="your_client_id",
client_secret="your_client_secret",
redirect_uri="https://your-app.com/callback",
api_key="dummy_key", # OAuth client doesn't need real API key for auth flow
)
# Get authorization URL
auth_url = auth_client.get_authorization_url(
scope=["account", "profile", "loop"], state="csrf_protection_token"
)
print(f"Authorization URL: {auth_url}")
# Get OAuth flow helper
flow_helper = auth_client.get_oauth_flow_helper(
scope=["account", "profile"], state="csrf_token"
)
print("\nOAuth Flow Instructions:")
for i, instruction in enumerate(flow_helper["instructions"], 1):
print(f"{i}. {instruction}")
# After user authorizes and you get the code:
# token_response = auth_client.exchange_code_for_token("authorization_code_here")
# access_token = token_response["access_token"]
# Use the access token with the main client:
# client = DotloopClient(api_key=access_token)
def demonstrate_advanced_features() -> None:
"""Demonstrate advanced features and convenience methods."""
print("\n🚀 ADVANCED FEATURES")
print("-" * 30)
client = DotloopClient()
try:
# Get account info
account = client.account.get_account()
profiles = client.profile.list_profiles()
if profiles["data"]:
profile_id = profiles["data"][0]["id"]
loops = client.loop.list_loops(profile_id=profile_id)
if loops["data"]:
loop_id = loops["data"][0]["id"]
# Convenience methods for participants
print("Participant convenience methods:")
# Add different types of participants (commented out)
# buyer = client.participant.add_buyer(
# profile_id=profile_id,
# loop_id=loop_id,
# full_name="John Buyer",
# email="buyer@example.com"
# )
# seller = client.participant.add_seller(
# profile_id=profile_id,
# loop_id=loop_id,
# full_name="Jane Seller",
# email="seller@example.com"
# )
# agent = client.participant.add_agent(
# profile_id=profile_id,
# loop_id=loop_id,
# full_name="Bob Agent",
# email="agent@realty.com",
# role=ParticipantRole.BUYING_AGENT
# )
# Template filtering
print("Template filtering:")
# Get templates by type
purchase_templates = client.template.get_templates_by_type(
profile_id=profile_id, template_type="PURCHASE"
)
print(f"Found {len(purchase_templates['data'])} purchase templates")
# Get default templates
default_templates = client.template.get_default_templates(
profile_id=profile_id
)
print(f"Found {len(default_templates['data'])} default templates")
# Activity filtering
print("Activity filtering:")
# Get recent activity
recent_activity = client.activity.get_recent_activity(
profile_id=profile_id, loop_id=loop_id, limit=5
)
print(f"Found {len(recent_activity['data'])} recent activities")
# Filter activity by type
doc_activities = client.activity.get_activity_by_type(
profile_id=profile_id,
loop_id=loop_id,
activity_type="DOCUMENT_UPLOADED",
)
print(f"Found {len(doc_activities['data'])} document upload activities")
# Task management
print("Task management:")
# Get all tasks in loop
all_tasks = client.task.get_all_tasks_in_loop(
profile_id=profile_id, loop_id=loop_id
)
print(f"Found {len(all_tasks['data'])} total tasks in loop")
# Get task summary
task_summary = client.task.get_task_summary(
profile_id=profile_id, loop_id=loop_id
)
print(f"Task completion rate: {task_summary['completion_rate']:.1%}")
# Webhook management
print("Webhook management:")
# Get webhook summary
webhook_summary = client.webhook.get_all_subscriptions_summary()
print(f"Total webhooks: {webhook_summary['total_subscriptions']}")
print(f"Active webhooks: {webhook_summary['active_subscriptions']}")
print("✅ Advanced features demonstration completed!")
except Exception as e:
print(f"❌ Error in advanced features: {e}")
if __name__ == "__main__":
# Check if API key is available
api_key = os.getenv("DOTLOOP_API_KEY")
if not api_key:
print("⚠️ Warning: DOTLOOP_API_KEY environment variable not set")
print("Some examples may not work without a valid API key")
print()
# Run main demonstration
main()
# Demonstrate OAuth flow (doesn't require API key)
demonstrate_oauth_flow()
# Demonstrate advanced features
if api_key:
demonstrate_advanced_features()
else:
print("\n⚠️ Skipping advanced features demo - API key required")
print("\n🎉 Complete Dotloop API demonstration finished!")
print(
"\nFor more information, check the documentation and individual endpoint examples."
)