# Users - People - Contacts & Profiles - [Notes](#notes) - [API documentation](#api-documentation) - [Python Regular Expressions](Python-Regular-Expressions) Match function - [Definitions](#definitions) - [Special quoting for contact groups](#special-quoting-for-contact-groups) - [Select User Contacts](#select-user-contacts) - [Create User Contacts](#create-user-contacts) - [Update User Contacts](#update-user-contacts) - [Delete User Contacts](#delete-user-contacts) - [Clear Old Email Addresses From Contacts](#clear-old-email-addresses-from-contacts) - [Delete Duplicate Email Addresses Within Contacts](#delete-duplicate-email-addresses-within-contacts) - [Replace Domain Names in Contact Email Addresses](#replace-domain-names-in-contact-email-addresses) - [Display User Contacts](#display-user-contacts) - [Manage User Contact Photos](#manage-user-contact-photos) - [Copy User Other Contacts to My Contacts](#copy-user-other-contacts-to-my-contacts) - [Move User Other Contacts to My Contacts](#move-user-other-contacts-to-my-contacts) - [Update User Other Contacts](#update-user-other-contacts) - [Delete User Other Contacts](#delete-user-other-contacts) - [Display User Other Contacts](#display-user-other-contacts) - [Manage User Contact Groups](#manage-user-contact-groups) - [Display User Contact Groups](#display-user-contact-groups) - [Display User People Profile](#display-user-people-profile) - [Copy User Contacts to another User](#copy-user-contacts-to-another-user) ## Notes As of version `6.08.00`, GAM uses the People API to manage user contacts rather than the Contacts API. Most commands will work unchanged but Google has completely changed how the data is presented. If you have scripts that process the output from `print contacts` for example, they will have to be changed. You might want to keep an older version of GAM available so you can compare the output from the two versions and make adjustments as necessary. If you manage contacts in the contact group "Other Contacts", you will need to use an older version, as the People API has very little support for this. To use these commands you must add the `People API` to your project and authorize the appropriate scopes: * `Client Access` * `People API (supports readonly)` * `People Directory API - read only`. * `Service Account Access` * `OAuth2 API`: https://www.googleapis.com/auth/userinfo.profile * `People API (supports readonly)`: https://www.googleapis.com/auth/contacts * `People API - Other Contacts - read only`: https://www.googleapis.com/auth/contacts.other.readonly * `People Directory API - read only`: https://www.googleapis.com/auth/directory.readonly ``` gam update project gam oauth create gam user user@domain.com check serviceaccount ``` ## API documentation * https://developers.google.com/people/api/rest * https://developers.google.com/people/contacts-api-migration ## Definitions * [``](Collections-of-Users) ``` ::= (json [charset ] ) | (json file [charset ]) | ::= ::= people/ ::= "(,)*" ::= | | | See: https://github.com/GAM-team/GAM/wiki/Collections-of-Items ::= ::= (contactgroup/)| ::= | ::= "(,)*" ::= | | | See: https://github.com/GAM-team/GAM/wiki/Collections-of-Items ::= [(selectcontactgroup )| [query ]] [emailmatchpattern [emailmatchtype work|home|other|]] ::= [(selectcontactgroup )|(filtercontactgroup )| ([query ] [selectmaincontacts|selectothercontacts])] [emailmatchpattern [emailmatchtype work|home|other|]] ::= (additionalname|middlename )| (address clear|(work|home|other| ((formatted|unstructured )|(streetaddress )|(pobox )| (neighborhood )|(locality )|(region )|(postalcode )|(country ))* notprimary|primary))| (billinginfo )| (biography|biographies |(file [charset ])|(gdoc ))| (birthday )| (calendar clear|(work|home|free-busy| notprimary|primary))| (clientdata )| (directoryserver )| (email clear|(work|home|other| notprimary|primary))| (event clear|(anniversary|other| ))| (externalid clear|(account|customer|network|organization| ))| (familyname|lastname )| (fileas )| (gender female|male)| (givenname|firstname )| (im clear|(work|home|other| aim|gtalk|icq|jabber|msn|net_meeting|qq|skype|yahoo notprimary|primary))| (interests clear|)| (initials )| (jot clear|(work|home|other|keywords|user> ))| | (language )| (locale clear|)| (location clear|)| (maidenname )| (mileage )| (name )| (nickname )| (note |(file [charset ])|(gdoc ))| (occupation clear|)| (organization clear|(work|other| ((location )|(department )|(title )|(jobdescription )|(symbol ))* notprimary|primary))| (phone clear|(work|home|other|fax|work_fax|home_fax|other_fax|main|company_main|assistant|mobile|work_mobile|pager|work_pager|car|radio|callback|isdn|telex|tty_tdd| notprimary|primary))| (prefix )| (priority low|normal|high) (relation clear|(spouse|child|mother|father|parent|brother|sister|friend|relative|domestic_partner|manager|assistant|referred_by|partner| ))| (sensitivity confidential|normal|personal|private) (shortname )| (skills clear|)| (subject )| (suffix )| (userdefinedfield clear|( ))| (url|website clear|(app_install_page|blog|ftp|home|home_page|other|profile|reservations|work| notprimary|primary)) For address, email, phone and url, the type can be empty. address "" formatted "My Address" primary email "" user@gmail.com primary phone "" "510-555-1212" primary url "" "https://www.domain.com" primary ``` ``` ::= addresses| ageranges| biographies| birthdays| calendarurls| clientdata| coverphotos| emailaddresses| events| externalids| genders| imclients| interests| locales| locations| memberships| metadata| misckeywords| names| nicknames| occupations| organizations| phonenumbers| photos| relations| sipaddresses| skills| urls| updated|updatetime| userdefined ::= "(,)*" ``` ``` ::= (clientdata )| | name ::= clientdata| grouptype| membercount| metadata| name ::= "(,)*" ``` ``` ::= otherContacts/ ::= "(,)*" ::= | | | See: https://github.com/GAM-team/GAM/wiki/Collections-of-Items ::= [query ] [emailmatchpattern [emailmatchtype work|home|other|]] ::= emailaddresses| metadata| names| phonenumbers| photos ::= "(,)*" ``` ## Special quoting for contact groups As contact group names can contain spaces, some care must be used when entering `` and ``. Suppose you enter the command `gam info contactgroup "Sales Contacts"` The shell strips the `"` leaving a single argument `Sales Contacts`; as gam is expecting a list, it splits the argument on space leaving two items and then tries to process `Sales` and `Contacts`, not what you want. You must enter: `gam info contactgroups "'Sales Contacts'"` The shell strips the `"` leaving a single argument `'Sales Contacts'`; as gam is expecting a list, it splits the argument on space while honoring the `'` leaving one item `Sales Contacts` and correctly processes the item. For multiple names you must enter: `gam info contactgroup "'Sales Contacts','Tech Contacts'"` ## Select User Contacts You specify contacts by ID or by selection qualifiers. ### Selections for commands other than `print|show` ``` ::= [(selectcontactgroup )| (query )] [emailmatchpattern [emailmatchtype work|home|other|]] ``` Selections processed by People API * `selectcontactgroup ` - Specify a specific contact group * `query ` - Fulltext query on contacts data fields. See: https://developers.google.com/contacts/v3/reference#contacts-query-parameters-reference Selections processed by GAM * `emailmatchpattern ` - Select contacts that have an email address matching `` * `emailmatchpattern emailmatchtype work|home|other|` - Select contacts that have an email address matching `` and a specific type * `emailmatchpattern ".*" emailmatchtype work|home|other|` - Select contacts that have any email address with a specific type ### For `print|show` commands ``` ::= [(selectcontactgroup )|(filtercontactgroup )| ([query ] [selectmaincontacts|selectothercontacts])] [emailmatchpattern [emailmatchtype work|home|other|]] ``` Selections processed by People API * `selectcontactgroup ` - Specify a specific contact group; individual contacts downloaded * `query ` - Fulltext query on contacts data fields. See: https://developers.google.com/contacts/v3/reference#contacts-query-parameters-reference * `selectmaincontacts` - Specify "Contacts" * `selectothercontacts` - Specify "Other Contacts" Selections processed by GAM * `filtercontactgroup ` - Specify a specific contact group; all contacts downloaded, then filtered * `emailmatchpattern ` - Select contacts that have an email address matching `` * `emailmatchpattern emailmatchtype work|home|other|` - Select contacts that have an email address matching `` and a specific type * `emailmatchpattern ".*" emailmatchtype work|home|other|` - Select contacts that have any email address with a specific type When `selectcontactgroup ` is used in these commands, GAM makes an API call to get the list of contacts in `` and then makes an API call per contact to get the details; this may exceed quota limits. When `filtercontactgroup ` is used, GAM makes an API call to get all contacts and then filters the list to only those in ``; quota limits should not apply. ## Create User Contacts ``` gam create contact [+] (contactgroup )* [(csv [todrive *] (addcsvdata )*))| returnidonly] ``` You may specify zero or more contact groups with `(contactgroup )*`; these contact groups define the complete contact group list for the contact. By default, the user name and contact ID are displayed on stdout. * `csv [todrive *]` - Write user name and contact ID values to a CSV file. * `addcsvdata ` - Add additional columns of data from the command line to the output * `returnidonly` - Display just the contact ID on stdout To retrieve the contact ID with `returnidonly`: ``` Linux/MacOS contactId=$(gam user user@domain.com create contact ... returnidonly) Windows PowerShell $contactId = & gam user user@domain.com create contact ... returnidonly ``` ## Update User Contacts ``` gam update contacts |( endquery) [+] (contactgroup )*|((addcontactgroup )* (removecontactgroup )*) ``` User contacts may be assigned to Contact Groups or may be unassigned and appear under My Contacts. The People API allows selection of contacts by Contact Group; in Gam you specify `selectcontactgroup `. However, the API does not allow selection of contacts from the Other Contacts section. You may specify zero or more contact groups with `(contactgroup )*`; these contact groups define the complete contact group list for the contact. You may specify zero or more contact groups with `(addcontactgroup )*`; these contact groups will be added to the current contact group list for the contact. You may specify zero or more contact groups with `(removecontactgroup )*`; these contact groups will be removed from the current contact group list for the contact. When `contactgroup` is specified, `addcontactgroup` and `removecontactgroup` are ignored. You can clear all contact groups from a contact with `contactgroup clear`. ## Delete User Contacts ``` gam delete contacts | ``` User contacts may be assigned to Contact Groups or may be unassigned and appear under My Contacts. The People API allows selection of contacts by Contact Group; in Gam you specify `selectcontactgroup `. However, the API does not allow selection of contacts from the Other Contacts section. ## Clear Old Email Addresses From Contacts ``` gam clear contacts | [emailclearpattern ] [emailcleartype work|home|other|] [delete_cleared_contacts_with_no_emails] ``` Typically, you would select contacts by `emailmatchpattern ` (and optionally `emailmatchtype work|home|other|`), then the matching email addresses will be cleared from the user's contact's email list. The contact itself is updated, not deleted. Email addresses that don't match will be unaffected. If you want to clear all email addresses of a particular type, use `emailmatchpattern ".*" emailmatchtype work|home|other|`. You can specify `emailclearpattern ` (and optionally `emailcleartype work|home|other|`) if you want to clear email addresses other than the ones used to match the contacts or if you specify ``. A contact may contain no email addresses after matching email addresses are cleared. If you do not want to keep contacts with no email addresses after clearing, use the `delete_cleared_contacts_with_no_emails` option and they will be deleted. Contacts with no email addresses before clearing will not be affected. ### Example For example, you want to eliminate any contact email addresses that use your company's old domain name. First, do `show contacts emailmatchpattern ""` to verify that you're getting the right contacts. Then do `clear contacts emailmatchpattern ""` to clear the email addresses. ``` gam user user@domain.com show contacts emailmatchpattern ".*@olddomain.com" fields email gam user user@domain.com clear contacts emailmatchpattern ".*@olddomain.com" ``` ## Delete Duplicate Email Addresses Within Contacts If the same email address appears multiple times within a contact, all but the first will be deleted. ``` gam dedup contacts [|] [matchType []] ``` If neither `` or `` is specified, all contacts are checked for duplicates. By default, the email type `work|home|other|` is ignored, all duplicates, regardless of type, will be deleted. If `matchtype` is true, only duplicate email addresses with the same type will be deleted. ## Replace Domain Names in Contact Email Addresses This command replaces domain names in contact email addresses; this can be useful when merging/renaming domains; multiple `domain ` options can be specified. ``` gam replacedomain contacts [|] (domain )+ ``` If neither `` or `` is specified, all contact email addresses are updated as applicable. If `` specifies `emailmatchpattern `, only email addresses within the contact that match `` are updated. ## Display User Contacts ### User Contact Group information In the following commands, specifying `allfields` or including `memberships` in `fields ` yields contact group information but only gives the contact group ID. Use the `showgroups` option to have GAM make additional API calls to get the contact group name associated with the ID. ### Display as an indented list of keys and values. ``` gam info contacts [allfields|(fields )] [showgroups] [showmetadata] [formatjson] ``` By default, Gam displays the fields `names,emailaddresses,phonenumbers`. * `allfields|(fields )` - Select fields to display By default, Gam displays the information as an indented list of keys and values. * `formatjson` - Display the fields in JSON format. ``` gam show contacts [orderby firstname|lastname|(lastmodified ascending)|(lastnodified descending) [countsonly|allfields|(fields )] [showgroups] [showmetadata] [formatjson] ``` By default, Gam displays all of a user's people contacts. * `query ` - Display contacts based on the data in their fields A maximum of 10 contacts will be returned. `orderBy` is not used with `query`. By default, Gam displays the fields `names,emailaddresses,phonenumbers`. * `allfields|(fields )` - Select fields to display By default, Gam displays the information as an indented list of keys and values. * `formatjson` - Display the fields in JSON format. ### Display as a CSV file. ``` gam print contacts [todrive *] [orderby firstname|lastname|(lastmodified ascending)|(lastnodified descending) [countsonly|allfields|(fields )] [showgroups] [showmetadata] [formatjson [quotechar ]] ``` By default, Gam displays all of a user's people contacts. * `query ` - Display contacts based on the data in their fields A maximum of 10 contacts will be returned. `orderBy` is not used with `query`. By default, Gam displays the fields `names,emailaddresses,phonenumbers`. * `allfields|(fields )` - Select fields to display By default, Gam displays the information as columns of fields; the following option causes the output to be in JSON format, * `formatjson` - Display the fields in JSON format. By default, when writing CSV files, Gam uses a quote character of double quote `"`. The quote character is used to enclose columns that contain the quote character itself, the column delimiter (comma by default) and new-line characters. Any quote characters within the column are doubled. When using the `formatjson` option, double quotes are used extensively in the data resulting in hard to read/process output. The `quotechar ` option allows you to choose an alternate quote character, single quote for instance, that makes for readable/processable output. `quotechar` defaults to `gam.cfg/csv_output_quote_char`. When uploading CSV files to Google, double quote `"` should be used. ## Manage User Contact Photos ``` gam update contactphotos | [drivedir|(sourcefolder )] [filename ] gam get contactphotos | [drivedir|(targetfolder )] [filename ] gam delete contactphotos | ``` The default directory is the current working directory, `drivedir` specifies the value of drive_dir from gam.cfg and `sourcefolder/targetfolder ` specifies a user-chosen path. `` can contain the strings `#email#` and `#contactid#` which will be replaced by the the contact's primary emailaddress or the contact ID. If not specified, `` defaults to `#contactid#.jpg`. ## Copy User Other Contacts to My Contacts Copy Other Contacts to My Contacts; now you have the same contact in two places. ``` gam copy othercontacts | ``` ## Move User Other Contacts to My Contacts Move Other Contacts to My Contacts; there is no duplication. ``` gam move othercontacts | ``` ### Examples Move a single Other Contact to My Contacts. ``` gam user user@domain.com move othercontacts otherContacts/c5977555358312178721 User: user@domain.com, Move maximum of 1 Other Contact User: user@domain.com, Other Contact: otherContacts/c5977555358312178721, Moved to: My Contacts ``` Move a selection of Other Contacts to My Contacts. ``` gam user user@domain.com move othercontacts emailmatchpattern "test.*" Getting all Other Contacts for user@domain.com Got 15 Other Contacts... User: user@domain.com, Move maximum of 15 Other Contacts User: user@domain.com, Other Contact: otherContacts/c2813750813749807666, Moved to: My Contacts User: user@domain.com, Other Contact: otherContacts/c7887232007947329156, Moved to: My Contacts User: user@domain.com, Other Contact: otherContacts/c523029179688316095, Moved to: My Contacts User: user@domain.com, Other Contact: otherContacts/c4889739431064427541, Moved to: My Contacts User: user@domain.com, Other Contact: otherContacts/c6318452176100245073, Moved to: My Contacts ``` ## Update User Other Contacts Other contacts are updated and moved to My Contacts and other contact groups if specified. ``` gam update othercontacts | [+] (contactgroup )* ``` ### Examples Update a single Other Contact and move to My Contacts and contact group "Test". ``` gam user user@domain.com update othercontacts otherContacts/c5977555358312178721 contactgroup Test User: user@domain.com, Copy maximum of 1 Other Contact User: user@domain.com, Other Contact: otherContacts/c5977555358312178721, Updated/Moved to: My Contacts,Test ``` Update a selection of Other Contacts and move to My Contacts and contact group "Test". ``` gam user user@domain.com update othercontacts emailmatchpattern "test.*" contactgroup Test Getting all Other Contacts for user@domain.com Got 15 Other Contacts... User: user@domain.com, Copy maximum of 15 Other Contacts User: user@domain.com, Other Contact: otherContacts/c2813750813749807666, Updated/Moved to: My Contacts,Test User: user@domain.com, Other Contact: otherContacts/c7887232007947329156, Updated/Moved to: My Contacts,Test User: user@domain.com, Other Contact: otherContacts/c523029179688316095, Updated/Moved to: My Contacts,Test User: user@domain.com, Other Contact: otherContacts/c4889739431064427541, Updated/Moved to: My Contacts,Test User: user@domain.com, Other Contact: otherContacts/c6318452176100245073, Updated/Moved to: My Contacts,Test ``` ## Delete User Other Contacts Other contacts are deleted by moving them to My Contacts and deleting them from there. ``` gam delete othercontacts | ``` ### Examples Delete a single Other Contact. ``` gam user user@domain.com delete othercontacts otherContacts/c5977555358312178721 User: user@domain.com, Delete maximum of 1 Other Contact User: user@domain.com, Other Contact: otherContacts/c5977555358312178721, Deleted ``` Delete a selection of Other Contacts. ``` gam user user@domain.com delete othercontacts emailmatchpattern "test.*" Getting all Other Contacts for user@domain.com Got 15 Other Contacts... User: user@domain.com, Delete maximum of 15 Other Contacts User: user@domain.com, Other Contact: otherContacts/c2813750813749807666, Deleted User: user@domain.com, Other Contact: otherContacts/c7887232007947329156, Deleted User: user@domain.com, Other Contact: otherContacts/c523029179688316095, Deleted User: user@domain.com, Other Contact: otherContacts/c4889739431064427541, Deleted User: user@domain.com, Other Contact: otherContacts/c6318452176100245073, Deleted ``` ## Display User Other Contacts ### Display as an indented list of keys and values. ``` gam show othercontacts [] [countsonly|allfields|(fields )] [showmetadata] [formatjson] ``` By default, Gam displays all of a user's Other Contacts; use `` to display a selection of Other Contacts. By default, Gam displays the fields `names,emailaddresses,phonenumbers`. * `allfields|(fields )` - Select fields to display By default, Gam displays the information as an indented list of keys and values. * `formatjson` - Display the fields in JSON format. ### Display as a CSV file. ``` gam print othercontacts [todrive *] [] [countsonly|allfields|(fields )] [showmetadata] [formatjson [quotechar ]] ``` By default, Gam displays all of a user's Other Contacts; use `` to display a selection of Other Contacts. By default, Gam displays the fields `names,emailaddresses,phonenumbers`. * `allfields|(fields )` - Select fields to display By default, Gam displays the information as columns of fields; the following option causes the output to be in JSON format, * `formatjson` - Display the fields in JSON format. By default, when writing CSV files, Gam uses a quote character of double quote `"`. The quote character is used to enclose columns that contain the quote character itself, the column delimiter (comma by default) and new-line characters. Any quote characters within the column are doubled. When using the `formatjson` option, double quotes are used extensively in the data resulting in hard to read/process output. The `quotechar ` option allows you to choose an alternate quote character, single quote for instance, that makes for readable/processable output. `quotechar` defaults to `gam.cfg/csv_output_quote_char`. When uploading CSV files to Google, double quote `"` should be used. ## Manage User Contact Groups ``` gam create contactgroup + [(csv [todrive *] (addcsvdata )*))| returnidonly] ``` By default, the user name and contactgroup ID are displayed on stdout. * `csv [todrive *]` - Write user name and contactgroup ID values to a CSV file. * `addcsvdata ` - Add additional columns of data from the command line to the output * `returnidonly` - Display just the contactgroup ID on stdout To retrieve the contactgroup ID with `returnidonly`: ``` Linux/MacOS contactGroupId=$(gam user user@domain.com create contactgroup ... returnidonly) Windows PowerShell $contactGroupId = & gam user user@domain.com create contactgroup ... returnidonly ``` ``` gam update contactgroup + gam delete contactgroups ``` ## Display User Contact Groups ### Display as an indented list of keys and values. ``` gam info contactgroups [allfields|(fields )] [showmetadata] [formatjson] gam show contactgroups [allfields|(fields )] [showmetadata] [formatjson] ``` By default, Gam displays the fields `name,metadata,grouptype,membercount`. * `allfields|(fields )` - Select fields to display By default, Gam displays the information as an indented list of keys and values. * `formatjson` - Display the fields in JSON format. ### Display as a CSV file. ``` gam print contactgroups [todrive *] [allfields|(fields )] [showmetadata] [formatjson [quotechar ]] ``` By default, Gam displays the fields `name,metadata,grouptype,membercount`. * `allfields|(fields )` - Select fields to display By default, Gam displays the information as columns of fields; the following option causes the output to be in JSON format, * `formatjson` - Display the fields in JSON format. By default, when writing CSV files, Gam uses a quote character of double quote `"`. The quote character is used to enclose columns that contain the quote character itself, the column delimiter (comma by default) and new-line characters. Any quote characters within the column are doubled. When using the `formatjson` option, double quotes are used extensively in the data resulting in hard to read/process output. The `quotechar ` option allows you to choose an alternate quote character, single quote for instance, that makes for readable/processable output. `quotechar` defaults to `gam.cfg/csv_output_quote_char`. When uploading CSV files to Google, double quote `"` should be used. ## Display User People Profile ### Display as an indented list of keys and values. ``` gam show peopleprofile [allfields|(fields ]) [showmetadata] [formatjson] ``` By default, Gam displays the fields `names,emailaddresses,phonenumbers`. * `allfields|(fields )` - Select fields to display By default, Gam displays the information as an indented list of keys and values. * `formatjson` - Display the fields in JSON format. ### Display as a CSV file. ``` gam print peopleprofile [todrive *] [allfields|(fields )] [showmetadata] [formatjson [quotechar ]] ``` By default, Gam displays the fields `names,emailaddresses,phonenumbers`. * `allfields|(fields )` - Select fields to display By default, Gam displays the information as columns of fields; the following option causes the output to be in JSON format, * `formatjson` - Display the fields in JSON format. By default, when writing CSV files, Gam uses a quote character of double quote `"`. The quote character is used to enclose columns that contain the quote character itself, the column delimiter (comma by default) and new-line characters. Any quote characters within the column are doubled. When using the `formatjson` option, double quotes are used extensively in the data resulting in hard to read/process output. The `quotechar ` option allows you to choose an alternate quote character, single quote for instance, that makes for readable/processable output. `quotechar` defaults to `gam.cfg/csv_output_quote_char`. When uploading CSV files to Google, double quote `"` should be used. ## Copy User Contacts to another User To copy one user's contacts to another user perform the following steps. ``` # Copy contact groups gam redirect csv ./ContactGroups.csv user sourceuser@domain.com print contactgroups formatjson gam redirect stdout ./CopyContactGroups.txt multiprocess redirect stderr stdout csv ContactGroups.csv gam user targetuser@domain.com create contactgroup json "~JSON" # Copy contacts gam redirect csv ./Contacts.csv user sourceuser@domain.com print contacts selectmaincontacts allfields showgroups formatjson gam redirect stdout ./CopyContacts.txt multiprocess redirect stderr stdout csv Contacts.csv gam user targetuser@domain.com create contact json "~JSON" ```