I may be going about this the wrong way, but I am trying to build a multi-app forge app, where a confluence page is created when an action occurs in Jira. I looked at the “cross app” example tutorial but it requires a hard-coded server id and has no indication of how to get the linked confluence server id in a real world app.
I have the following permissions in manifest.yml:
permissions:
scopes:
- read:jira-work
- write:page:confluence
- storage:app
- manage:jira-configuration
- manage:jira-webhook
I get a 401 error with response of { code: 401, message: 'Unauthorized; scope does not match' }
. I have researched but can not find an alternative scope that may work here.
I can confirm the REST endpoint works and returns expected JSON response with the confluence server id as needed, using CURL on the CLI. On the surface this looks like a scope/perms error, but I can figure out what the correct scope should be.
Is this simply not possible in forge and forge is displaying an incorrect error (i.e. there is no scope that makes this possible and it’s not a scope problem), is it something I have missed, or is there an alternative working way to get dynamically get the correct server id for confluence? Or can one post and create pages without the server id of the linked confluence instance?
This is the code I am using in order to try to get the server ID of the linked confluence server:
async function configureLinkedConfluence() {
const response = await api.asApp().requestJira(route`/rest/applinks/2.0/listApplicationlinks`, {
method: 'GET',
});
if (!response.ok) {
throw new Error(`Failed to fetch application links: ${response.status} ${response.statusText}`);
}
const responseBody = await response.json();
const appLinks = responseBody.list;
// Find the Confluence server ID
const confluenceLink = appLinks.find(link => link.application.typeId === 'confluence');
if (!confluenceLink) {
throw new Error('No linked Confluence site found in Jira application links.');
}
const serverId = confluenceLink.application.id;
await storage.set('linkedConfluenceServerId', serverId);
console.log(`Linked Confluence URL stored: ${serverId}`);
return serverId;
}