Search code examples
pythongoogle-contacts-api

Specifying custom fields for contacts in Google Contacts API v3


How do I specify custom fields while creating/updating a contact with the API (also retrieving it)? I'm using the Python API.


Solution

  • import gdata.contacts.data
    
    new_contact = gdata.contacts.data.ContactEntry()
    
    # Set the contact's name.
    new_contact.name = gdata.data.Name(
        given_name=gdata.data.GivenName(text='Elizabeth'),
        family_name=gdata.data.FamilyName(text='Bennet'),
        full_name=gdata.data.FullName(text='Elizabeth Bennet')
    )
    
    # Set user defined fields
    new_contact.user_defined_field.append(
        gdata.contacts.data.UserDefinedField(
            key='Field Name',
            value='Field Value'
        )
    )