How to get the URL of a Forge app in Jira?

I have a forge app that’s being loaded as jira:projectPage. Its name and link show up in the nav bar in Jira. How can I programatically produce the URL to take a user to the page with my app selected? E.g

https://.atlassian.net/jira/software/projects/TEST/apps/<id 1>/<id 2>

I’m redirecting the user to a new page to do something - and would like to redirect them back to Jira with my app selected, to pick up where they left off.

2 Likes

Hi @aliakhtar

If your app is a Custom UI app, you might be able to leverage the createHistory method to allow to redirect to where your user was.

See the documentation here: https://developer.atlassian.com/platform/forge/custom-ui-bridge/view/#createhistory

As noted, the jira:projectPage is one of the supported modules.

Hope this helps.

1 Like

Thanks @XavierCaron but I actually need to open a popup window via resolver.open (a workaround to get microphone access) - so users will be on a site outside of Jira where I’ll get their voice command via microphone. Then I need to redirect them back to Jira.

So I can’t use the createHistory bridge as they will be on an external site outside of Jira. I need an independent way to generate the URL that’ll take them back to Jira with my app selected. How can I do that?

I’m also interested in this. My use case is that I’m using Custom UI for a Jira project page, and I want to generate a URL which the user can share as a link, but I couldn’t see anything in the docs about how to do this.

The createHistory bridge only provides relative paths, and the window.location object appears to maintain a reference to a CDN (e.g. f79f0bb1-0f9b-4ce1-82b6-6af0ecd669bb.cdn.prod.atlassian-dev.net) so I need to figure out the actual Jira app root (i.e. the url of the project page).

I did notice how I can potentially piece together the URL, but it’s based on a few assumptions:

  1. Suppose my project page is at https://example.atlassian.net/jira/software/projects/MYPROJ/apps/app-id/other-id.
  2. Suppose also that I navigate to /my-page?foo=bar using react-router in my custom UI. (The full URL would then be https://example.atlassian.net/jira/software/projects/MYPROJ/apps/app-id/other-id/my-page?foo=bar.)
  3. Then the result of view.getContext() (from the @forge/bridge package) looks like the below.
{
  extension: {
    project: {key: "MYPROJ", type: "software", id: "10000"}
  },
  type: "jira:projectPage",
  localId: "ari:cloud:ecosystem::extension/app-id/other-id/static/my-app"
}
  1. Therefore, I can get the project key from context.extension.project.key, and I can parse context.localId to get the application id and the “other id”. (Anyone know what this second ID is called or is for btw?)
  2. I can get the baseUrl (https://example.jira.com) from the /rest/api/3/serverInfo URL.
  3. This allows me to piece together the full URL of the app, assuming a template of {baseUrl}/jira/software/projects/{projectKey}/{appId}/{otherId}.
  4. I can then simply append the relative URL of my custom UI page (/my-page?foo=bar) to this URL for the app in order to get the link to share.

So this looks like it should work. However, I have a couple of questions:

  1. Is this approach guaranteed to work in future, or am I making assumptions about the format of the localId and the URL scheme?
  2. Is there a better way to get the app URL? (Certainly, this seems a lot of work.)
5 Likes

Hi @XavierCaron,

Any update on this topic? I also have the need for a static Forge app URL (ProjectPage) that I can share with others and/or open in another tab.

Thank you,
Paulo

1 Like

Hi @jbrunton & @PauloMichels

Thanks for reaching out. I have confirmed with my team that unfortunately there is no easy way to derive this value today.

It has been put on our radar and it is now tracked internally.

2 Likes

@XavierCaron Any update on this?

We have a connect app we’re trying to move to Forge and one of the features is the ability to create a shareable link. This relies on being able to read URL parameters inside the app context. The connect app currently uses Context parameters to set the URL parameters and they are then read inside the app.

Any idea when/if this feature is coming to Forge?

Best Regards,
Rhys

Hi @RhysDiab,

It is possible to read the current URL parameters using the createHistory API.

const history = await view.createHistory();
console.log(history.location.search);

e.g. with a URL of https://my-site.atlassian.net/wiki/spaces/<space-key>/apps/<id>/<id2>/<route>?a=b&c=d this would log ?a=b&c=d

3 Likes

That looks helpful @RyanBraganza - thanks.

FYI, in light of @RhysDiab 's last comment and the recently created FRGE-706: Access URL parameters in Forge Context, there also seems to an additional aspect of this issue which relates to the formalisation of the URL contract and the ability to inject parameters into the URL as can be done in Connect.

2 Likes

@RyanBraganza The history API looks like it returns any parameters added to the URL which is perfect. That’s what I’m looking for.

As @dmorrow mentioned the other part of creating a shareable link is reconstructing the rest of the URL. Is the method mentioned above by @jburgoyn safe to use going forward?

Thanks for the response!

Yes, that should be fine.

The “other-id” is the environment ID and differs based on if you’re looking at the development/staging/production environments of your app.

4 Likes

is that environment id consistent across different atlassian instances?

Say I have two instances for company foo and company bar

If my app id is e246da2c-2411-46b3-9a3d-9fd0c9f9af0d
and my dev env id is 822d093a-a2cb-4382-8861-7a83afa3e77b

Will the urls for my app in these instances be:

https://bar.atlassian.net/jira/software/projects/TEST/apps/e246da2c-2411-46b3-9a3d-9fd0c9f9af0d/822d093a-a2cb-4382-8861-7a83afa3e77b