Blog
Data - How to save and retrieve Google contacts
March 10. 2021
Power Apps provides a connector to retrieve and to add contacts that are stored in Google. The syntax for this connector isn't very obvious so in this post, we'll walk through an example of how to display contacts in a gallery control, and how to add contacts to a Google account.
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.
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, tim@email.com)
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: "tim@workCompany.com",
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"
}
)
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 find the common rows from 3 or more collections
- Data - How to show the distinct rows from 2 data sources or collections
- Data - How to implement circular rotational date sorting
- Bug - What to do when the data section of the Power Apps Maker portal doesn't work
- Data - Combine columns from separate tables into a single table
- Formula - Transposing/converting rows to columns- an almost impossible task?
- Data - How to rename field names in a record
- Data - How to hide duplicate rows in a gallery / show distinct multiple columns in a gallery
- Data - Retrieving news/forum/blog articles with RSS
- Data - How to sort by partial numbers in a text field
- Data - How to return the last record from a table
- Data - How to create bulk test/dummy records with random values
- Data - 3 things you should know before using the MySQL or PostgreSQL connectors
- Data - A walkthrough of how to migrate the data source of an app from Excel to Sharepoint
- Data - How to enforce unique values (or prevent duplicate values) in one or more columns
- Data - How much mobile data does Power Apps consume? What ways can we minimise this?
- Data - How to save and retrieve Google calendar entries
- SQL - Caution! This is how users can hack shared SQL connections
- SharePoint – 2 Mistakes to avoid when importing Excel data
- SQL - Don't let this DateTime bug catch you out!
- Settings - What's the purpose of the "Explicit Column Selection" Setting?
- SQL Server for Beginners Part 3 - Installing On-Premises Gateway
- SQL Server for Beginners Part 2 - Installing Management Studio
- SQL Server for Beginners Part 1 - Installing SQL Server
- Searching data–What you need to know about case sensitivity
- Images - How to create images that can change depending on data
- Excel - Reasons NOT to use Excel as a data source
- SharePoint - What you need to know about Filtering Data
- Formulas - Generating Row Numbers