Get Context Data

Get Context Data

Why Use Context Data?
  1. Enhanced telemetry & debugging:
    • Track sessions using sessionId
    • Correlate usage with platform logs
  2. Personalized experiences:
    • Customize UI and logic based on user identity
  3. Feature control & conditional logic:
    • Enable or disable features per user or environment
  4. Consistency with Canvas Apps:
    • Access similar session details directly in code apps

Steps
  1. Import the initialize and getContext functions
  2. 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
  3. 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

Related Information