Get Context Data
Get Context Data
- getContext retrieves app, user, and session metadata
- Enables runtime decision-making and personalized experiences
- Lightweight API focused on metadata and authentication
- Communicates with the Power Apps web player
Why Use Context Data?
- Enhanced telemetry & debugging:
- Track sessions using sessionId
- Correlate usage with platform logs
- Personalized experiences:
- Customize UI and logic based on user identity
- Feature control & conditional logic:
- Enable or disable features per user or environment
- Consistency with Canvas Apps:
- Access similar session details directly in code apps
Steps
- Import the initialize and getContext functions
-
Initialize
- You must call and wait for the initialize function to complete before making any data calls to ensure that the SDK is fully initialized
-
Retrieve context
- Call getContext as an asynchronous function to get the context object
API Response
IContext: The following table describes the properties available in the IContext interface:
| Property | Type | Description |
|---|---|---|
| app | IAppContext | The app's context |
| user | IUserContext | The user's context |
| host | IHostContext | The host's context |
IAppContext
The following table describes the properties available in the IAppContext interface:
| Property | Type | Description |
|---|---|---|
| appId | string | The ID of the app being played |
| environmentId | string | The ID of the environment where the app lives |
| queryParams | Record<string, string> | The query parameters added to the URL |
IUserContext
The following table describes the properties available in the IUserContext interface:
| Property | Type | Description |
|---|---|---|
| fullName | string | The full name of the user playing the app |
| objectId | string | The ID of the user playing the app |
| tenantId | string | The ID of the tenant where the app lives |
| userPrincipalName | string | The UPN of the user playing the app |
IHostContext
The following table describes the property available in the IHostContext interface:
| Property | Type | Description |
|---|---|---|
| sessionId | string | The ID of the current session. This changes every time the app is opened |
Benefits
- No extra data calls and secure, runtime-aware logic
- Better monitoring and personalization