class ApplicationCollection
A collection class for managing Application objects in a directory, providing methods to retrieve and manage applications with delta query support.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/applications/collection.py
6 - 18
moderate
Purpose
ApplicationCollection serves as a specialized collection container for Application objects within the Office 365 directory services. It extends DeltaCollection to provide delta query capabilities for tracking changes to applications over time. The primary use case is to manage and retrieve applications from a directory, particularly by their application client identifier (app_id). This class is part of the Office 365 SDK for interacting with Azure AD/Microsoft Graph application resources.
Source Code
class ApplicationCollection(DeltaCollection[Application]):
"""DirectoryObject's collection"""
def __init__(self, context, resource_path=None):
super(ApplicationCollection, self).__init__(context, Application, resource_path)
def get_by_app_id(self, app_id):
# type: (str) -> Application
"""Retrieves application by Application client identifier
:param str app_id: Application client identifier
"""
return Application(self.context, AppIdPath(app_id, self.resource_path))
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
DeltaCollection[Application] | - |
Parameter Details
context: The client context object that provides authentication and connection information for making API requests to the Office 365/Microsoft Graph service. This is typically an instance of ClientContext or similar authentication context.
resource_path: Optional parameter specifying the API endpoint path for the collection resource. If None, a default path will be used. This allows for custom resource paths when the collection is accessed from different API endpoints.
Return Value
The constructor returns an instance of ApplicationCollection. The get_by_app_id method returns an Application object corresponding to the specified application client identifier. The Application object is initialized with the provided context and a special AppIdPath that constructs the appropriate resource path for accessing the application by its app_id.
Class Interface
Methods
__init__(self, context, resource_path=None)
Purpose: Initializes the ApplicationCollection with the provided context and optional resource path
Parameters:
context: The client context object for API authentication and requestsresource_path: Optional custom resource path for the collection endpoint
Returns: None (constructor)
get_by_app_id(self, app_id: str) -> Application
Purpose: Retrieves a specific Application object by its application client identifier (app_id)
Parameters:
app_id: String containing the application's client identifier (GUID format)
Returns: An Application object instance configured with the appropriate resource path for the specified app_id
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
context |
ClientContext | Inherited from parent class. Stores the client context used for API authentication and making requests | instance |
resource_path |
str or None | Inherited from parent class. Stores the API endpoint path for this collection resource | instance |
Dependencies
office365
Required Imports
from office365.delta_collection import DeltaCollection
from office365.directory.applications.application import Application
from office365.runtime.paths.appid import AppIdPath
Usage Example
from office365.runtime.auth.client_credential import ClientCredential
from office365.graph_client import GraphClient
from office365.directory.applications.collection import ApplicationCollection
# Setup authentication
client_id = 'your-client-id'
client_secret = 'your-client-secret'
tenant_id = 'your-tenant-id'
credentials = ClientCredential(client_id, client_secret)
client = GraphClient(credentials, tenant_id)
# Get the applications collection
apps_collection = client.applications
# Retrieve a specific application by its app_id
app_id = '12345678-1234-1234-1234-123456789abc'
application = apps_collection.get_by_app_id(app_id)
# Load and access application properties
application.get().execute_query()
print(f'Application name: {application.display_name}')
print(f'Application ID: {application.app_id}')
Best Practices
- Always ensure the context object is properly authenticated before instantiating or using the collection
- Use get_by_app_id when you know the application's client identifier (app_id) for direct retrieval
- The collection inherits delta query capabilities from DeltaCollection, allowing efficient tracking of changes over time
- Remember to call execute_query() on the context after retrieving applications to actually fetch data from the API
- Handle potential exceptions for authentication failures, network errors, or when applications are not found
- The app_id parameter in get_by_app_id should be a valid GUID string representing the application's client identifier
- This collection is typically accessed through a GraphClient instance rather than instantiated directly
- Ensure appropriate Microsoft Graph API permissions are granted to the authenticated principal before querying applications
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class UserCollection 74.4% similar
-
class AppRoleAssignmentCollection 72.1% similar
-
class AppCollection 70.1% similar
-
class ServicePrincipalCollection 68.4% similar
-
class GroupCollection 68.3% similar