Runtimes
Web triggers
Async functions
Product REST APIs
Fetch APIs

getAppContext

This API is not available in the legacy runtime.

Use getAppContext to get a Forge function's context details, including the app environments and versions it is executing in.

Method signature

1
2
export declare function getAppContext(): AppContext;

export type AppContext = {
    appAri: AppAri;
    appVersion: string;
    environmentAri: EnvironmentAri;
    environmentType: string;
    invocationId: string;
    installationAri: InstallationAri;
    moduleKey: string;
    license?: LicenseDetails;
};

export type AppAri = {
    appId: string;
    toString: () => string;
};
export type EnvironmentAri = {
    environmentId: string;
    toString: () => string;
};
export type InstallationAri = {
    installationId: string;
    toString: () => string;
};

interface LicenseDetails {
  active: boolean;
  billingPeriod: string;
  ccpEntitlementId: string;
  ccpEntitlementSlug: string;
  isEvaluation: boolean;
  subscriptionEndDate: string | null;
  supportEntitlementNumber: string | null;
  trialEndDate: string | null;
  type: string;
}

Returns

This API returns the following string values:

NamePropertiesDescription
appAritoString()The app's unique Atlassian Resource Identifier (ARI), as defined in the app.id field of the manifest.yml file.
appIdThe UUID part of the full appAri string.
appVersionApp Version.
environmentAritoString()The app environment's full ARI.
environmentIdThe UUID part of the full environmentAri string.
environmentTypeThe environment in which the app is running (for example, DEVELOPMENT, STAGING, or PRODUCTION).
invocationIdA unique identifier for the current invocation.
installationAritoString()The app installation's full ARI.
installationIdThe UUID part of the full installationAri string
moduleKeyThe key for the module as defined in the manifest.yml file.
licenseContains information about the license of the app. This field is only present for paid apps in the production environment.
license is undefined for free apps, apps in DEVELOPMENT and STAGING environments, and apps that are not listed on the Atlassian Marketplace. See the LicenseDetails type in the Method Signature for what information is available.

Example

1
2
import { getAppContext } from "@forge/api";

const { appAri, appVersion, environmentAri, environmentType, invocationId, installationAri, moduleKey } = getAppContext();

console.log(appAri.toString());
// 'ari:cloud:ecosystem::app/00000000-0000-0000-0000-000000000000'

console.log(appAri.appId);
// '00000000-0000-0000-0000-000000000000'

console.log(appVersion);
// '1.0.0'

console.log(environmentAri.toString());
// 'ari:cloud:ecosystem::environment/00000000-0000-0000-0000-000000000000/11111111-1111-1111-0111-111111111111'

console.log(environmentAri.environmentId);
// '11111111-1111-1111-0111-111111111111'

console.log(environmentType);
// 'DEVELOPMENT'

console.log(invocationId);
// '33333333-3333-3333-0333-333333333333'

console.log(installationAri.toString());
// 'ari:cloud:ecosystem::installation/22222222-2222-2222-0222-222222222222'

console.log(installationAri.installationId);
// '22222222-2222-2222-0222-222222222222'

console.log(moduleKey);
// 'hello-world'

console.log(JSON.stringify(license));
//{"isActive":true,"billingPeriod":"MONTHLY","ccpEntitlementId":"NULL","ccpEntitlementSlug":"NULL","isEvaluation":"NULL","subscriptionEndDate":"NULL","supportEntitlementNumber":"NULL","trialEndDate":"NULL","type":"commercial"}

Rate this page: