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.