class ClientPeoplePickerWebServiceInterface
A SharePoint web service interface class that provides static methods for querying and resolving principals (users, groups) using the People Picker functionality.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/ui/applicationpages/peoplepicker/web_service_interface.py
16 - 169
moderate
Purpose
This class serves as a wrapper around SharePoint's ClientPeoplePickerWebServiceInterface, providing methods to search for principals, resolve user identities, and retrieve entity information. It's designed to work with SharePoint's people picker UI component and claims-based authentication. All methods are static and return ClientResult or PickerEntityInformation objects that can be used to retrieve principal data in JSON format.
Source Code
class ClientPeoplePickerWebServiceInterface(Entity):
"""Specifies an interface that can be used to query principals."""
@staticmethod
def get_search_results(
context,
search_pattern,
provider_id=None,
hierarchy_node_id=None,
entity_types=None,
):
"""
Specifies a JSON formatted CSOM String of principals found in the search.
:type context: office365.sharepoint.client_context.ClientContext
:param str search_pattern: Specifies a pattern used to search for principals.
The value is implementation-specific.
:param str provider_id: The identifier of a claims provider.
:param str hierarchy_node_id: The identifier of a node in the hierarchy. The search MUST be conducted under
this node.
:param str entity_types: The type of principals to search for.
"""
return_type = ClientResult(context, str())
payload = {
"searchPattern": search_pattern,
"providerID": provider_id,
"hierarchyNodeID": hierarchy_node_id,
"entityTypes": entity_types,
}
svc = ClientPeoplePickerWebServiceInterface(context)
qry = ServiceOperationQuery(
svc, "GetSearchResults", None, payload, None, return_type, True
)
context.add_query(qry)
return return_type
@staticmethod
def get_search_results_by_hierarchy(
context,
provider_id=None,
hierarchy_node_id=None,
entity_types=None,
context_url=None,
):
"""
Specifies a JSON formatted CSOM String of principals found in the search grouped by hierarchy.
:type context: office365.sharepoint.client_context.ClientContext
:param str provider_id: The identifier of a claims provider.
:param str hierarchy_node_id: The identifier of a node in the hierarchy. The search MUST be conducted under
this node.
:param str entity_types: The type of principals to search for.
:param str context_url: The URL to use as context when searching for principals.
"""
return_type = ClientResult(context, str())
payload = {
"providerID": provider_id,
"hierarchyNodeID": hierarchy_node_id,
"entityTypes": entity_types,
"contextUrl": context_url,
}
svc = ClientPeoplePickerWebServiceInterface(context)
qry = ServiceOperationQuery(
svc, "GetSearchResultsByHierarchy", None, payload, None, return_type, True
)
context.add_query(qry)
return return_type
@staticmethod
def client_people_picker_resolve_user(context, query_string):
"""
Resolves the principals to a string of JSON representing users in people picker format.
:param str query_string: Specifies the value to be used in the principal query.
:param office365.sharepoint.client_context.ClientContext context: SharePoint client context
"""
return_type = ClientResult(context, str())
binding_type = ClientPeoplePickerWebServiceInterface(context)
payload = {
"queryParams": ClientPeoplePickerQueryParameters(query_string=query_string)
}
qry = ServiceOperationQuery(
binding_type,
"ClientPeoplePickerResolveUser",
None,
payload,
None,
return_type,
True,
)
context.add_query(qry)
return return_type
@staticmethod
def client_people_picker_search_user(
context, query_string, maximum_entity_suggestions=100
):
"""
Returns for a string of JSON representing users in people picker format of the specified principals.
:param office365.sharepoint.client_context.ClientContext context: SharePoint client context
:param str query_string: Specifies the value to be used in the principal query.
:param int maximum_entity_suggestions: Specifies the maximum number of principals to be returned by the
principal query.
"""
return_type = ClientResult(context, str())
binding_type = ClientPeoplePickerWebServiceInterface(context)
params = ClientPeoplePickerQueryParameters(
query_string=query_string,
maximum_entity_suggestions=maximum_entity_suggestions,
)
payload = {"queryParams": params}
qry = ServiceOperationQuery(
binding_type,
"ClientPeoplePickerSearchUser",
None,
payload,
None,
return_type,
True,
)
context.add_query(qry)
return return_type
@staticmethod
def get_picker_entity_information(context, email_address):
"""
Gets information of the specified principal.
:param office365.sharepoint.client_context.ClientContext context: SharePoint client context
:param str email_address: Specifies the principal for which information is being requested.
"""
request = PickerEntityInformationRequest(
email_address=email_address, principal_type=PrincipalType.All
)
return_type = PickerEntityInformation(context)
binding_type = ClientPeoplePickerWebServiceInterface(context)
payload = {"entityInformationRequest": request}
qry = ServiceOperationQuery(
binding_type,
"GetPickerEntityInformation",
None,
payload,
None,
return_type,
True,
)
context.add_query(qry)
return return_type
@property
def entity_type_name(self):
return "SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface"
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Entity | - |
Parameter Details
context: A ClientContext instance representing the SharePoint client context, required for all operations to communicate with SharePoint services
search_pattern: A string pattern used to search for principals; implementation-specific and typically matches against user names, email addresses, or display names
provider_id: Optional string identifier of a claims provider to limit the search scope to a specific authentication provider
hierarchy_node_id: Optional string identifier of a node in the hierarchy under which the search should be conducted, used for organizational structure filtering
entity_types: Optional string specifying the type of principals to search for (e.g., 'User', 'Group', 'SharePointGroup')
context_url: Optional URL string to use as context when searching for principals, helps scope the search to a specific site or location
query_string: String value to be used in the principal query, typically a partial name or email address to search for
maximum_entity_suggestions: Integer specifying the maximum number of principals to return from the search query, defaults to 100
email_address: String email address of the principal for which detailed information is being requested
Return Value
For search methods (get_search_results, get_search_results_by_hierarchy, client_people_picker_resolve_user, client_people_picker_search_user), returns a ClientResult object containing a string of JSON-formatted principal data. For get_picker_entity_information, returns a PickerEntityInformation object containing detailed information about a specific principal. All return types are deferred execution objects that will be populated when the query is executed through the context.
Class Interface
Methods
get_search_results(context, search_pattern, provider_id=None, hierarchy_node_id=None, entity_types=None) -> ClientResult
static
Purpose: Searches for principals matching a pattern and returns results as JSON formatted string
Parameters:
context: ClientContext instance for SharePoint communicationsearch_pattern: Pattern string to search for principalsprovider_id: Optional claims provider identifierhierarchy_node_id: Optional hierarchy node to search underentity_types: Optional type filter for principals
Returns: ClientResult object containing a JSON string of matching principals
get_search_results_by_hierarchy(context, provider_id=None, hierarchy_node_id=None, entity_types=None, context_url=None) -> ClientResult
static
Purpose: Searches for principals and returns results grouped by hierarchy as JSON formatted string
Parameters:
context: ClientContext instance for SharePoint communicationprovider_id: Optional claims provider identifierhierarchy_node_id: Optional hierarchy node to search underentity_types: Optional type filter for principalscontext_url: Optional URL to use as search context
Returns: ClientResult object containing a JSON string of principals grouped by hierarchy
client_people_picker_resolve_user(context, query_string) -> ClientResult
static
Purpose: Resolves principals to a JSON string representing users in people picker format
Parameters:
context: ClientContext instance for SharePoint communicationquery_string: Value to use in the principal query for resolution
Returns: ClientResult object containing a JSON string of resolved users in people picker format
client_people_picker_search_user(context, query_string, maximum_entity_suggestions=100) -> ClientResult
static
Purpose: Searches for users and returns results as JSON string in people picker format
Parameters:
context: ClientContext instance for SharePoint communicationquery_string: Value to use in the principal search querymaximum_entity_suggestions: Maximum number of principals to return (default 100)
Returns: ClientResult object containing a JSON string of matching users in people picker format
get_picker_entity_information(context, email_address) -> PickerEntityInformation
static
Purpose: Retrieves detailed information about a specific principal identified by email address
Parameters:
context: ClientContext instance for SharePoint communicationemail_address: Email address of the principal to retrieve information for
Returns: PickerEntityInformation object containing detailed principal information
entity_type_name -> str
property
Purpose: Returns the SharePoint entity type name for this interface
Returns: String 'SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface'
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
entity_type_name |
str | The SharePoint entity type name identifier for this web service interface | instance |
Dependencies
office365
Required Imports
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.ui.applicationpages.peoplepicker.web_service_interface import ClientPeoplePickerWebServiceInterface
Usage Example
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.ui.applicationpages.peoplepicker.web_service_interface import ClientPeoplePickerWebServiceInterface
# Initialize SharePoint context
ctx = ClientContext('https://yourtenant.sharepoint.com/sites/yoursite').with_credentials(user_credentials)
# Search for users matching a pattern
result = ClientPeoplePickerWebServiceInterface.get_search_results(
context=ctx,
search_pattern='john',
entity_types='User'
)
ctx.execute_query()
print(result.value) # JSON string of matching users
# Resolve a specific user
resolved = ClientPeoplePickerWebServiceInterface.client_people_picker_resolve_user(
context=ctx,
query_string='john.doe@company.com'
)
ctx.execute_query()
print(resolved.value) # JSON string of resolved user
# Get detailed entity information
entity_info = ClientPeoplePickerWebServiceInterface.get_picker_entity_information(
context=ctx,
email_address='john.doe@company.com'
)
ctx.execute_query()
print(entity_info.entity_data) # Detailed principal information
Best Practices
- Always call ctx.execute_query() after invoking any method to actually execute the query and populate the return value
- All methods are static, so no instance creation is needed - call methods directly on the class
- The class internally creates instances for query binding but these are not exposed to the caller
- Return values are deferred execution objects - access the .value property only after execute_query()
- Use appropriate entity_types parameter to filter results and improve performance
- Consider setting maximum_entity_suggestions to limit result sets for better performance
- Ensure the ClientContext has appropriate permissions before querying principals
- The JSON strings returned contain SharePoint-specific principal formats - parse accordingly
- Use get_picker_entity_information for detailed information about a known principal
- Use search methods for discovering principals based on partial information
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class PickerEntityInformation 71.5% similar
-
class PeoplePickerQuerySettings 71.4% similar
-
class PickerSettings 66.7% similar
-
class PickerEntityInformationRequest 66.3% similar
-
class SharePointSharingSettings 65.9% similar