After you've completed the steps in Get Ready to Use the People API, you are ready to read directory contacts and profiles.
The following code samples demonstrate how to send a few simple requests:
- List the directory.
- Search the directory.
For a full list of methods, see the reference documentation.
Reading domain data requires that the domain admin must have enabled external contact and profile sharing of domain-scoped data for their domain.
List the directory
To get a list of contacts and profiles in the user's domain directory, use the following code:
Protocol
GET /v1/people:listDirectoryPeople?sources=DIRECTORY_SOURCE_TYPE_DOMAIN_CONTACT&sources=DIRECTORY_SOURCE_TYPE_DOMAIN_PROFILE&readMask=names,emailAddresses HTTP/1.1 Host: people.googleapis.com
Java
Listsources = new ArrayList<>(); sources.add("DIRECTORY_SOURCE_TYPE_DOMAIN_CONTACT"); sources.add("DIRECTORY_SOURCE_TYPE_DOMAIN_PROFILE"); ListDirectoryPeopleResponse response = peopleService.people().listDirectoryPeople() .setSources(sources) .setReadMask("metadata,names,emailAddresses") .execute(); List<Person> people = response.getPeople();
Search the directory
To get a list of contacts and profiles in the user's domain directory matching a prefix query, use the following code:
Protocol
POST /v1/people:searchDirectoryPeople?query=John&sources=DIRECTORY_SOURCE_TYPE_DOMAIN_CONTACT&sources=DIRECTORY_SOURCE_TYPE_DOMAIN_PROFILE&readMask=names,emailAddresses HTTP/1.1 Host: people.googleapis.com
Java
Listsources = new ArrayList<>(); sources.add("DIRECTORY_SOURCE_TYPE_DOMAIN_CONTACT"); sources.add("DIRECTORY_SOURCE_TYPE_DOMAIN_PROFILE"); SearchDirectoryPeopleResponse response = peopleService.people().searchDirectoryPeople() .setQuery("John") .setSources(sources) .setReadMask("metadata,names,emailAddresses") .execute(); List<Person> people = response.getPeople();