Create Google Contact via API and Add To My Contacts System Group

When you create a new Contact via the Google Contacts API, by default it will not appear in the list of contacts on the Google Contacts webpage, however, if you search for the contact there, it will appear. If you then click the "Add to contacts" button, it will appear in that contacts list, and increase your contact count in the top left of the page.




There is a way to add new contacts via the API and have them show up in this list, it is just not well documented within the API documentation. The code below demonstrates how to do this is C#.

What appears to be a list of all contacts on the Google Contacts page is actually just a subset of all your contacts, it is actually the "My Contacts" System Group. When you create a new contact via the API, you must specify that this new contact is part of that system group for it to appear on the contacts page without searching.

Steps:
 1. Create a ContactsRequest
 2. Get a list of all groups and search for the "My Contacts" System Group.
 3. Create a new `Contact`
 4. Add a `GroupMembership` with an HRef equal to the "My Contacts" System Group Id.
 5. Insert the new contact via the ContactsRequest.


Create Contact Gist


Hope this helps,
Aaron


p.s. I created a tool to sync contacts between gmail accounts. Check it out here: https://www.gmailcontactsync.com/



Comments

Popular posts from this blog

Search iPhone Text Messages with SQLite SQL Query

How to Turn Off Microsoft Arc Touch Mouse Scroll Sound Vibration

Configure SonarAnalyzer.CSharp with .editorconfig, no need for SonarCloud or SonarQube