How to query page url value from forge UI KIT

Am trying to query confluence Page URL from forge UI KIT app.

I want to get value Jackoba and MyPage from the url

I have tried

const queryParams = new URLSearchParams(window.location.search);

but it throws error
windows not defined

Hey @NkemjikaGwacham

You cannot access the window object in UI kit as the Javascript executes on the server.

While you cannot access the URL directly, you can get the context of an app within a given extension point.

import ForgeUI, { useProductContext, Text, Macro, render } from '@forge/ui';

const App = () => {
  const context = useProductContext();
  return <Text>All info about my context: {JSON.stringify(context)}</Text>;
};

export const run = render(<Macro app={<App />} />);
1 Like

When will it possible. ??
I have that problem too.
My Background:
My App should connect with the “Tempo Timetracking” App.
I just only want to make some call to their API too.

But the Authorization with OAuth2 cant be done, because the Redirect URL has also the code parameter. Which I should send to get an access token.

Hi @anon72326184,

Forge apps will never have access to the window object of the product. This would be a security issue.

Can you explain your use case a little more for talking to another app?

Hello Daniel,

im happy to do :slight_smile:
At first I need to setup the Authorization between my App and the Tempo API:
https://apidocs.tempo.io/

I use the OAuth2 Verification. My goal is to send some GET Requests to the Endpoints
/account-links/project/{projectKey} and maybe in the future some more :slight_smile:

ATM I need the default Tempo Account for the Project, because after I clone some Issues, I want to link the Account to the Issue.

My problem is that the normal OAuth2 Flow is not possible with a Forge App.

Hi @danielwinterw,

thank you for helping with this issue. I tried your approach, but useProductContext doesn’t have information about the instance where the app is running, right?

My JSON.stringify(useProductContext) looks as following:

{
   "accountId": "61025aa84e8d8d841d6",
   "cloudId": "a2a1c27f-e6ce-4722-b68e",
   "contentId": "70492",
   "localId": "8888b559-6096-4101-8e31",
   "spaceKey": "~2513008",
   "installContext": "ari:cloud:confluence::site/a2a1c27f-e6ce-4722-b68e",
   "isConfig": false,
   "extensionContext": {
      "type": "macro",
      "isEditing": false
   },
   "moduleKey": "hello-world"
}

So there is nothing about URI, right? Or am I doing anything wrong?

Thank you,
Vaclav

1 Like