1- #!/usr/bin/env python3
21import os
32from datetime import datetime
43
1110
1211
1312def main ():
14- """
15- Demonstrate contact groups management capabilities.
16-
17- Shows how to create, read, update and delete contact groups
18- using the Contact Groups API.
19- """
20-
2113 # Initialize the client
2214 api_key = os .getenv ("DEVO_API_KEY" )
2315 if not api_key :
@@ -28,11 +20,13 @@ def main():
2820
2921 print ("🗂️ Devo Global Communications - Contact Groups Management Example" )
3022 print ("=" * 75 )
23+ print ("📋 Using services namespace: client.services.contact_groups" )
24+ print ()
3125
3226 # Example 1: List existing contact groups
3327 print ("\n 📋 Listing existing contact groups..." )
3428 try :
35- groups_list = client .contact_groups .list (page = 1 , limit = 5 )
29+ groups_list = client .services . contact_groups .list (page = 1 , limit = 5 )
3630 print (f"✅ Found { groups_list .total } total groups" )
3731 print (f" Page: { groups_list .page } /{ groups_list .total_pages } " )
3832 print (f" Showing: { len (groups_list .groups )} groups" )
@@ -63,7 +57,7 @@ def main():
6357 },
6458 )
6559
66- new_group = client .contact_groups .create (new_group_data )
60+ new_group = client .services . contact_groups .create (new_group_data )
6761 print ("✅ Contact group created successfully!" )
6862 print (f" 📁 Name: { new_group .name } " )
6963 print (f" 🆔 ID: { new_group .id } " )
@@ -88,7 +82,7 @@ def main():
8882 metadata = {"updated_by" : "api_example" , "updated_at" : datetime .now ().isoformat (), "version" : "2.0" },
8983 )
9084
91- updated_group = client .contact_groups .update (created_group_id , update_data )
85+ updated_group = client .services . contact_groups .update (created_group_id , update_data )
9286 print ("✅ Contact group updated successfully!" )
9387 print (f" 📁 New name: { updated_group .name } " )
9488 print (f" 📝 New description: { updated_group .description } " )
@@ -102,7 +96,7 @@ def main():
10296 if created_group_id :
10397 print (f"\n 🔍 Retrieving specific group { created_group_id } ..." )
10498 try :
105- specific_group = client .contact_groups .get_by_id (created_group_id )
99+ specific_group = client .services . contact_groups .get_by_id (created_group_id )
106100 print ("✅ Group retrieved successfully!" )
107101 print (f" 📁 Name: { specific_group .name } " )
108102 print (f" 📝 Description: { specific_group .description } " )
@@ -115,7 +109,9 @@ def main():
115109 # Example 5: Search contact groups
116110 print ("\n 🔎 Searching contact groups..." )
117111 try :
118- search_results = client .contact_groups .search (query = "demo" , fields = ["name" , "description" ], page = 1 , limit = 10 )
112+ search_results = client .services .contact_groups .search (
113+ query = "demo" , fields = ["name" , "description" ], page = 1 , limit = 10
114+ )
119115 print (f"✅ Search completed! Found { search_results .total } matching groups" )
120116
121117 for i , group in enumerate (search_results .groups , 1 ):
@@ -130,7 +126,7 @@ def main():
130126 # Example 6: Advanced listing with filters
131127 print ("\n 🔧 Advanced group listing with filters..." )
132128 try :
133- filtered_groups = client .contact_groups .list (
129+ filtered_groups = client .services . contact_groups .list (
134130 page = 1 , limit = 3 , search = "demo" , search_fields = ["name" , "description" ]
135131 )
136132 print ("✅ Filtered listing completed!" )
@@ -157,7 +153,7 @@ def main():
157153 metadata = {"bulk_demo" : True , "group_number" : i + 1 },
158154 )
159155
160- bulk_group = client .contact_groups .create (bulk_group_data )
156+ bulk_group = client .services . contact_groups .create (bulk_group_data )
161157 bulk_group_ids .append (bulk_group .id )
162158 print (f" ✅ Created bulk group { i + 1 } : { bulk_group .name } " )
163159
@@ -170,7 +166,7 @@ def main():
170166 if created_group_id :
171167 print (f"\n 🗑️ Deleting individual group { created_group_id } ..." )
172168 try :
173- deleted_group = client .contact_groups .delete_by_id (created_group_id , approve = "yes" )
169+ deleted_group = client .services . contact_groups .delete_by_id (created_group_id , approve = "yes" )
174170 print ("✅ Individual group deleted successfully!" )
175171 print (f" 📁 Deleted group: { deleted_group .name } " )
176172
@@ -185,17 +181,17 @@ def main():
185181 backup_group_data = CreateContactsGroupDto (
186182 name = "Backup Group for Bulk Delete Demo" , description = "Temporary group to receive transferred contacts"
187183 )
188- backup_group = client .contact_groups .create (backup_group_data )
184+ backup_group = client .services . contact_groups .create (backup_group_data )
189185
190186 # Perform bulk deletion
191187 bulk_delete_data = DeleteContactsGroupsDto (group_ids = bulk_group_ids , transfer_contacts_to = backup_group .id )
192188
193- bulk_delete_result = client .contact_groups .delete_bulk (bulk_delete_data , approve = "yes" )
189+ bulk_delete_result = client .services . contact_groups .delete_bulk (bulk_delete_data , approve = "yes" )
194190 print ("✅ Bulk deletion completed successfully!" )
195191 print (f" 📊 Operation result: { bulk_delete_result .name } " )
196192
197193 # Clean up backup group
198- client .contact_groups .delete_by_id (backup_group .id , approve = "yes" )
194+ client .services . contact_groups .delete_by_id (backup_group .id , approve = "yes" )
199195 print (" 🧹 Cleaned up backup group" )
200196
201197 except Exception as e :
@@ -205,7 +201,7 @@ def main():
205201 print ("\n ⚠️ Error handling demonstration..." )
206202 try :
207203 # Try to get a non-existent group
208- client .contact_groups .get_by_id ("non_existent_group_id" )
204+ client .services . contact_groups .get_by_id ("non_existent_group_id" )
209205
210206 except Exception as e :
211207 print (f"✅ Properly handled expected error: { type (e ).__name__ } " )
@@ -277,7 +273,7 @@ def contact_group_management_workflow():
277273 name = group_type ["name" ], description = group_type ["description" ], metadata = group_type ["metadata" ]
278274 )
279275
280- group = client .contact_groups .create (group_data )
276+ group = client .services . contact_groups .create (group_data )
281277 created_groups .append (group )
282278 print (f" ✅ Created: { group .name } " )
283279
@@ -310,7 +306,7 @@ def contact_group_management_workflow():
310306 },
311307 )
312308
313- client .contact_groups .update (vip_group .id , update_data )
309+ client .services . contact_groups .update (vip_group .id , update_data )
314310 print (" ✅ Updated VIP group with enhanced metadata" )
315311
316312 except Exception as e :
@@ -326,16 +322,16 @@ def contact_group_management_workflow():
326322 temp_group_data = CreateContactsGroupDto (
327323 name = "Temporary Archive" , description = "Temporary group for workflow cleanup"
328324 )
329- temp_group = client .contact_groups .create (temp_group_data )
325+ temp_group = client .services . contact_groups .create (temp_group_data )
330326
331327 # Bulk delete with contact transfer
332328 delete_data = DeleteContactsGroupsDto (group_ids = group_ids , transfer_contacts_to = temp_group .id )
333329
334- client .contact_groups .delete_bulk (delete_data , approve = "yes" )
330+ client .services . contact_groups .delete_bulk (delete_data , approve = "yes" )
335331 print (f" ✅ Bulk deleted { len (group_ids )} demonstration groups" )
336332
337333 # Delete temporary group
338- client .contact_groups .delete_by_id (temp_group .id , approve = "yes" )
334+ client .services . contact_groups .delete_by_id (temp_group .id , approve = "yes" )
339335 print (" ✅ Cleaned up temporary archive group" )
340336
341337 except Exception as e :
0 commit comments