How to use AP.request inside Jira Forge

Hello,

is there any way to use AP.request inside of Jira Forge? I made the experience that it somehow TypeError: AP.request is not a function shows up as an error.

I already required https://connect-cdn.atl-paas.net/all.js as a script inside of index.html of the modle (using custom ui)

Are you trying to call a product API from inside your Custom UI app? If so, you’ll need to use requestConfluence or requestJira from the Forge bridge

1 Like

Hello, i had some issues with requestJira and wanted to try AP.request so i can investiage further.

I don’t think AP.request is available for Forge apps. When I tried including the AP script in my custom UI app and logging out the available methods, I only get the following list which is a lot less compared to a connect app.

[
    "_xdm",
    "parentTargets",
    "_data",
    "_hostOrigin",
    "_top",
    "_host",
    "_topHost",
    "_initTimeout",
    "_initReceived",
    "_initCheck",
    "_isKeyDownBound",
    "_eventHandlers",
    "_pendingCallbacks",
    "_keyListeners",
    "_version",
    "_apiTampered",
    "_isSubIframe",
    "_onConfirmedFns",
    "_promise",
    "_messageHandlers",
    "resize",
    "container",
    "size",
    "registerAny",
    "register",
    "_hostModules",
    "defineGlobal",
    "defineModule",
    "subCreate",
    "Dialog",
    "define",
    "require",
    "Meta",
    "meta",
    "localUrl",
    "_util"
]

Regarding the TypeError, I don’t believe the AP library provide types so you’ll have to declare your own e.g. create a file called ap.d.ts where your app’s frontend custom UI code is located.

declare interface AP {
  context: APContext;
}

declare interface APContext {
  getContext(callback?: (result: Context) => void): void;
}

declare interface Context {
  confluence: {
    content: {
      id: string;
      type: 'page' | 'blogpost' | 'custom';
      version: string;
    };
    macro: {
      hash: string;
      id: string;
      outputType: 'display';
    };
    space: {
      id: string;
      key: string;
    };
  };
}

declare const AP: AP;

Then, you can call AP.context.getContext() in your code base.