I created a forge app, using custom ui. The app is primarily for importing changes and then modifying Confluence pages.
I initially created it using the jira admin page module, forgetting that the app is for Confluence, but thought this wouldn’t really be an issue, because the app is just for once off use.
Anyway, I’m calling the below from the index.js using resolver as follows:
const fetchConfluencePage = async (spaceKey, pageTitle) => {
console.log(`fetching for ${spaceKey} and page: ${pageTitle}`);
const res = await api
.asUser()
.requestConfluence(route`/rest/api/content?type=page&spaceKey=${spaceKey}&title=${pageTitle}`);
console.log(`Res: ${JSON.stringify(res)}`);
const data = await res.json();
console.log(`data found: ${JSON.stringify(data)}`);
return data.results;
};
resolver.define('fetchConfluencePage', async (req) => {
console.log(`Doing it: ${JSON.stringify(req)}`);
return await fetchConfluencePage(req.payload.spaceKey, req.payload.pageTitle);
})
You can see I’m logging everything so that I can help myself debug this issue.
This is what I see in the logs.
But let me share what I found, in case someone else has this issue.
Turns out, what may actually be obvious, is that you need to create the app, according to the product you want to use it in. Since I created it as a Jira app, turns it out, it would never work.
I needed to recreate the app, as a confluence app. Simply changing the module in the manifest, doesn’t seem to work either. I’m guessing it has something to do with the app id. So it actually needs to be completely recreated.
Hope this helps anyone else in the world having this issue.
Thanks for providing so much detail and your resolution for others to benefit from!
Sorry for the delayed response. To clarify a little, I believe the solution lies more in where the app was installed. For example, in order to have Confluence scopes apply, you will need to run forge install for Confluence on sites you wish to use the app in, even if your app is only displayed in Jira.
I actually tried that. I saw the app appear on the “Manage Apps” screen, but it didn’t appear on the left navigation section, with another one of my test apps? Strange right?
I also noticed that when the app was asking for my approval (when it was installed on Jira), it wasn’t mentioning all the scopes I had added, it only had the “user read me” one, even after running the “forge install --upgrade” command.
However, when I recreated the app from the cli, choosing Confluence initially, then manually copied over all my code, including the scopes - after deploying and the app asked for my permission, I now saw all the scopes that I had added.
I’m not sure if you’re able to check logs or anything on your side perhaps to confirm? But that was my experience.
I created this app originally this morning and ran into this issue. Then assumed I had done something wrong, so uninstalled and deleted the app from the Developer Console, then proceeded to recreate it and still seem to be experiencing this issue.
From my experience, it would seem like you can’t interact with one product within another, does anyone else have this issue and was able to overcome it?
I recently faced this type of issue in Confluence and got it resolved.
In my case, I noticed that if there is a typo in the URL or the URL generated is not done properly the API returns a 401 response even if the correct scopes are in the manifest.
For example, instead of this;
const res = await api
.asUser()
.requestConfluence(route`/rest/api/content?type=page&spaceKey=${spaceKey}&title=${pageTitle}`);
Try this;
const res = await api
.asUser()
.requestConfluence(route`/rest/api/content?type=page&spaceKey=replaceWithSpaceKey`);
And then is if it works. This will help you generate/pass in the accepted URL.