Data - How to save and retrieve Google contacts

The ability to access Google contacts can be very useful, particularly for organisations that use GSuite, or cases where app builders want to provide an easy way to retrieve, access, or to sync contact records from an Android device.

In this post, we'll walk through the syntax that we can use to retrieve and to add contacts to a Google account.

Introduction to connector

To use this connector in a canvas app, the first step is to add a connection through the data panel.


This connector offers two key actions - one to retrieve contacts, and the other to create a contact record. These actions have undergone several revisions and at the time of writing, the latest version of the 'get' action is version 4.

Compared to previous versions, this offers an improvement because previous versions would return a result set with the most prominent details in child tables, which were not organised in a very obvious way.

Limitation of the connector

Unfortunately, there's a significant limitation with this connector in that it can retrieve a maximum of 1024 contacts only. Here's what the documentation says:
Known issues and limitations: Action "Get my contacts" currently does not support pagination. It returns 1024 contacts maximum. If you have more contacts, only first 1024 will be returned back by the action.

For further reading, the full documentation for the connector is here:
https://docs.microsoft.com/en-us/connectors/googlecontacts/

Retrieving contacts

To retrieve contacts, we call the PeopleApiListContactsV3 action. This returns a table called connections that contains the contact details.

For example, to display contacts in a gallery control, we would set the items property to the following formula:

GoogleContacts.PeopleApiListContactsV4().connections

The gallery control displays all available contacts (up to a maximum of 1024). As the screenshot beneath shows, the results table contains a child record called 'name'. This exposes attributes that include family name, display name, and given name.



To illustrate the the connections table, here's a screenshot that shows the result when we collect the return value into a collection. As this screenshot shows, each contact record includes child tables with email addresses and phone numbers.



This schema supports the data structure where each contact can have multiple email addresses and phone numbers (e.g., for work, business, and other). An easy way to display these child tables in a gallery control is to add nested gallery controls, and to set the items property of these controls to ThisItem.emailAddresses, and ThisItem.phoneNumbers.

Alternatively, to display the first email address or phone number that is associated with a contact, we can the set the text property of a label in the gallery control to the following formula:

//This returns the email type (eg, Home, work, other, etc)
First(ThisItem.emailAddresses).formattedType

//This returns email value (eg, [email protected])
First(ThisItem.emailAddresses).value

//This returns the phone number type (eg, Home, work, other, etc)
First(ThisItem.phoneNumbers).formattedType

//This returns phone number value (eg, 07985458965)
First(ThisItem.phoneNumbers).value

Searching contacts

To search for contacts, we can filter the  PeopleApiListContactsV4().connections table. As an example, here's how to return all contacts with a surname that starts with "sm" :

Filter(GoogleContacts.PeopleApiListContactsV4().connections, 
StartsWith(name.familyName, "sm")
)

Creating contacts

To create a contact, we call the PeopleApiCreateContactV3 action. Here's the formula we can add to the OnSelect property of a button to create a contact.


GoogleContacts.PeopleApiCreateContactV3(
"Tim",
{
familyName: "Leung",
workEmail: "[email protected]",
company: "Power Apps Guide Company",
jobTitle: "App Builder",
workPhoneNumber: "workPhoneNumber value",
mobilePhoneNumber: "mobilePhoneNumber value",
homeEmail: "homeEmail value",
otherEmail: "otherEmail value",
nickName: "nickName value",
homeAddress: "homeAddress value",
workAddress: "workAddress value",
otherAddress: "otherAddress value",
homePhoneNumber: "homePhoneNumber value",
otherPhoneNumber: "otherPhoneNumber value"
}
)
The first value we pass to is the "given name". This value is mandatory. We can optionally pass the additional contact attributes, which are shown in the code samle above.

Conclusion

Power Apps provides a connector that we can use to retrieve and to create Google contacts. This post described the formula that enables us to carry out the add and retrieval operations.

Related posts

Data - How to remove trailing comma all rows in a table
February 20, 2025
Data - How to find the common rows from 3 or more collections
October 06, 2024
Data - How to show the distinct rows from 2 data sources or collections
February 26, 2024
Data - How to implement circular rotational date sorting
February 21, 2024
Bug - What to do when the data section of the Power Apps Maker portal doesn't work
June 18, 2023
Data - Combine columns from separate tables into a single table
October 13, 2022
Formula - Transposing/converting rows to columns- an almost impossible task?
September 23, 2021
Data - How to rename field names in a record
July 14, 2021
Data - How to hide duplicate rows in a gallery / show distinct multiple columns in a gallery
July 09, 2021
Data - Retrieving news/forum/blog articles with RSS
June 26, 2021
Data - How to sort by partial numbers in a text field
June 23, 2021
Data - How to return the last record from a table
June 19, 2021
Data - How to create bulk test/dummy records with random values
June 18, 2021
Data - 3 things you should know before using the MySQL or PostgreSQL connectors
May 11, 2021
Data - A walkthrough of how to migrate the data source of an app from Excel to Sharepoint
April 26, 2021
Data - How to enforce unique values (or prevent duplicate values) in one or more columns
April 19, 2021
Data - How much mobile data does Power Apps consume? What ways can we minimise this?
March 28, 2021
Data - How to save and retrieve Google calendar entries
March 14, 2021
SQL - Caution! This is how users can hack shared SQL connections
January 23, 2021
SharePoint – 2 Mistakes to avoid when importing Excel data
January 10, 2021
SQL - Don't let this DateTime bug catch you out!
January 05, 2021
Settings - What's the purpose of the "Explicit Column Selection" Setting?
January 04, 2021
SQL Server for Beginners Part 3 - Installing On-Premises Gateway
January 24, 2019
SQL Server for Beginners Part 2 - Installing Management Studio
January 14, 2019
SQL Server for Beginners Part 1 - Installing SQL Server
January 04, 2019
Searching data–What you need to know about case sensitivity
December 27, 2018
Images - How to create images that can change depending on data
November 09, 2018
Excel - Reasons NOT to use Excel as a data source
September 25, 2018
SharePoint - What you need to know about Filtering Data
September 16, 2018
Formulas - Generating Row Numbers
April 05, 2018