class GroupService
GroupService is a SharePoint service class that provides operations for managing SharePoint groups, including retrieving group images and synchronizing group properties.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/portal/groups/service.py
11 - 40
moderate
Purpose
This class serves as a service layer for interacting with SharePoint Portal's GroupService API. It inherits from Entity and provides methods to fetch group images with optional caching parameters and to trigger synchronization of group properties. The class is designed to work within the Office365 SharePoint client library context, handling service operation queries and HTTP requests to the SharePoint backend.
Source Code
class GroupService(Entity):
def get_group_image(
self, group_id, image_hash=None, image_color=None, return_type=None
):
# type: (str, str, str, ClientResult) -> ClientResult[AnyStr]
if return_type is None:
return_type = ClientResult(self.context)
if image_hash is None:
image_hash = random.getrandbits(64)
qry = ServiceOperationQuery(
self, "GetGroupImage", None, None, None, return_type
)
def _create_request(request):
# type: (RequestOptions) -> None
request.url += "?id='{0}'&hash={1}".format(group_id, image_hash)
request.method = HttpMethod.Get
self.context.add_query(qry).before_execute(_create_request)
return return_type
def sync_group_properties(self):
""" """
qry = ServiceOperationQuery(self, "SyncGroupProperties")
self.context.add_query(qry)
return self
@property
def entity_type_name(self):
return "Microsoft.SharePoint.Portal.GroupService"
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Entity | - |
Parameter Details
Entity: Base class parameter - GroupService inherits from Entity, which provides core functionality for SharePoint entities including context management and query execution capabilities
Return Value
Instantiation returns a GroupService object that can execute SharePoint group-related operations. The get_group_image method returns a ClientResult[AnyStr] containing the group image data. The sync_group_properties method returns self for method chaining. The entity_type_name property returns the string 'Microsoft.SharePoint.Portal.GroupService'.
Class Interface
Methods
get_group_image(self, group_id: str, image_hash: str = None, image_color: str = None, return_type: ClientResult = None) -> ClientResult[AnyStr]
Purpose: Retrieves the image associated with a SharePoint group by constructing and executing a service operation query
Parameters:
group_id: The unique identifier (GUID) of the SharePoint group whose image should be retrievedimage_hash: Optional hash value for cache-busting; if None, a random 64-bit value is generatedimage_color: Optional color parameter (currently not used in the implementation but may be for future API compatibility)return_type: Optional ClientResult object to store the result; if None, a new ClientResult is created with the current context
Returns: A ClientResult[AnyStr] object that will contain the group image data (as bytes or string) after the query is executed
sync_group_properties(self) -> GroupService
Purpose: Triggers synchronization of group properties with SharePoint, ensuring local and server-side group data is consistent
Returns: Returns self (the GroupService instance) to enable method chaining
@property entity_type_name(self) -> str
property
Purpose: Provides the fully qualified entity type name used by SharePoint's OData service to identify this service type
Returns: The string 'Microsoft.SharePoint.Portal.GroupService' representing the entity type in SharePoint's metadata
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
context |
ClientContext | Inherited from Entity base class; holds the SharePoint client context used for executing queries and managing authentication | instance |
Dependencies
office365typing
Required Imports
from office365.sharepoint.entity import Entity
from office365.runtime.client_result import ClientResult
from office365.runtime.queries.service_operation import ServiceOperationQuery
from office365.runtime.http.http_method import HttpMethod
from office365.runtime.http.request_options import RequestOptions
from typing import AnyStr
import random
Usage Example
from office365.sharepoint.portal.group_service import GroupService
from office365.runtime.client_result import ClientResult
from office365.sharepoint.client_context import ClientContext
# Authenticate and create context
ctx = ClientContext(site_url).with_credentials(credentials)
# Instantiate GroupService (typically done internally by the library)
group_service = GroupService(ctx)
# Get group image with specific hash
result = ClientResult(ctx)
group_service.get_group_image(
group_id='group-guid-here',
image_hash='hash-value',
return_type=result
)
ctx.execute_query()
image_data = result.value
# Sync group properties
group_service.sync_group_properties()
ctx.execute_query()
# Method chaining example
group_service.sync_group_properties().context.execute_query()
Best Practices
- Always call context.execute_query() after adding queries to actually execute the operations against SharePoint
- Use ClientResult objects to capture return values from service operations
- The image_hash parameter in get_group_image is used for cache-busting; if not provided, a random hash is generated
- sync_group_properties returns self, enabling method chaining patterns
- Ensure proper authentication context is established before instantiating or using this service
- The class is designed to be used within the Office365 library's context management system
- Group IDs should be valid SharePoint group GUIDs
- Handle potential HTTP errors and authentication failures when executing queries
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class Group_v1 65.6% similar
-
class SitePageService 65.4% similar
-
class UnifiedGroup 63.4% similar
-
class DocumentsSharedWithGroup 62.4% similar
-
class GroupSiteManager 62.2% similar