@@ -357,42 +357,62 @@ def remove(
357357 return resp
358358
359359 @classmethod
360- async def create_async (cls , params : CreateParams ) -> Contact :
360+ async def create_async (cls , params : CreateParams ) -> CreateContactResponse :
361361 """
362362 Create a new contact (async).
363+ Can create either a global contact or an audience-specific contact.
363364 see more: https://resend.com/docs/api-reference/contacts/create-contact
364365
365366 Args:
366367 params (CreateParams): The contact creation parameters
368+ - If audience_id is provided: creates audience-specific contact
369+ - If audience_id is omitted: creates global contact with optional properties field
367370
368371 Returns:
369- Contact : The new contact object
372+ CreateContactResponse : The created contact response
370373 """
371- path = f"/audiences/{ params ['audience_id' ]} /contacts"
372- resp = await AsyncRequest [Contact ](
374+ audience_id = params .get ("audience_id" )
375+
376+ if audience_id :
377+ path = f"/audiences/{ audience_id } /contacts"
378+ else :
379+ path = "/contacts"
380+
381+ resp = await AsyncRequest [Contacts .CreateContactResponse ](
373382 path = path , params = cast (Dict [Any , Any ], params ), verb = "post"
374383 ).perform_with_content ()
375384 return resp
376385
377386 @classmethod
378- async def update_async (cls , params : UpdateParams ) -> Contact :
387+ async def update_async (cls , params : UpdateParams ) -> UpdateContactResponse :
379388 """
380389 Update an existing contact (async).
390+ Can update either a global contact or an audience-specific contact.
381391 see more: https://resend.com/docs/api-reference/contacts/update-contact
382392
383393 Args:
384394 params (UpdateParams): The contact update parameters
395+ - If audience_id is provided: updates audience-specific contact
396+ - If audience_id is omitted: updates global contact with optional properties field
385397
386398 Returns:
387- Contact : The updated contact object
399+ UpdateContactResponse : The updated contact response.
388400 """
389401 if params .get ("id" ) is None and params .get ("email" ) is None :
390402 raise ValueError ("id or email must be provided" )
391403
392- val = params .get ("id" ) if params .get ("id" ) is not None else params .get ("email" )
404+ # Email takes precedence over id (matching Node.js behavior)
405+ contact_identifier = (
406+ params .get ("email" ) if params .get ("email" ) is not None else params .get ("id" )
407+ )
408+ audience_id = params .get ("audience_id" )
393409
394- path = f"/audiences/{ params ['audience_id' ]} /contacts/{ val } "
395- resp = await AsyncRequest [Contact ](
410+ if audience_id :
411+ path = f"/audiences/{ audience_id } /contacts/{ contact_identifier } "
412+ else :
413+ path = f"/contacts/{ contact_identifier } "
414+
415+ resp = await AsyncRequest [Contacts .UpdateContactResponse ](
396416 path = path , params = cast (Dict [Any , Any ], params ), verb = "patch"
397417 ).perform_with_content ()
398418 return resp
@@ -403,6 +423,7 @@ async def list_async(
403423 ) -> ListResponse :
404424 """
405425 List all contacts (async).
426+ Can list either global contacts or audience-specific contacts.
406427 see more: https://resend.com/docs/api-reference/contacts/list-contacts
407428
408429 Args:
@@ -426,25 +447,34 @@ async def list_async(
426447
427448 @classmethod
428449 async def get_async (
429- cls , audience_id : str , id : Optional [str ] = None , email : Optional [str ] = None
450+ cls ,
451+ audience_id : Optional [str ] = None ,
452+ id : Optional [str ] = None ,
453+ email : Optional [str ] = None ,
430454 ) -> Contact :
431455 """
432456 Get a contact (async).
457+ Can retrieve either a global contact or an audience-specific contact.
433458 see more: https://resend.com/docs/api-reference/contacts/get-contact
434459
435460 Args:
436- audience_id (str): The audience ID
437- id (Optional[str]): The contact ID
438- email (Optional[str]): The contact email
461+ audience_id (Optional[ str] ): The audience ID. If not provided, retrieves global contact.
462+ id (Optional[str]): The contact ID. Either id or email must be provided.
463+ email (Optional[str]): The contact email. Either id or email must be provided.
439464
440465 Returns:
441466 Contact: The contact object
442467 """
443- contact = email if id is None else id
444- if contact is None :
468+ # Email takes precedence over id (matching Node.js behavior)
469+ contact_identifier = email if email is not None else id
470+ if contact_identifier is None :
445471 raise ValueError ("id or email must be provided" )
446472
447- path = f"/audiences/{ audience_id } /contacts/{ contact } "
473+ if audience_id :
474+ path = f"/audiences/{ audience_id } /contacts/{ contact_identifier } "
475+ else :
476+ path = f"/contacts/{ contact_identifier } "
477+
448478 resp = await AsyncRequest [Contact ](
449479 path = path , params = {}, verb = "get"
450480 ).perform_with_content ()
@@ -459,6 +489,7 @@ async def remove_async(
459489 ) -> RemoveContactResponse :
460490 """
461491 Remove a contact by ID or by Email (async).
492+ Can remove either a global contact or an audience-specific contact.
462493 see more: https://resend.com/docs/api-reference/contacts/delete-contact
463494
464495 Args:
0 commit comments