Newbie. I am trying to understand Confluence plugin development from the documentation and whatever I can find. Starting from the hello world forge example I've ended up with this:
import api, { route } from "@forge/api";import ForgeUI, { render, Fragment, Text, Macro, useProductContext, useState } from '@forge/ui';const fetchPages = async (spaceKey) => { const sres = await api .asUser() .requestConfluence(route`/wiki/api/v2/spaces?keys=${spaceKey}`); const sdata = await sres.json(); console.log(`Space data: ${sdata.results}`); const pres = await api .asUser() .requestConfluence(route`/wiki/api/v2/spaces/${sdata.results.id}/pages`); const pdata = await pres.json(); return pdata.results;};const App = () => { const context = useProductContext(); const pages = useState(async () => await fetchPages(context.spaceKey)); console.log(`Received spaces and pages`); return ( <Fragment> <Text>All info about my context: {JSON.stringify(context, null, 2)}</Text> <Text>All info about my pages: {JSON.stringify(pages, null, 2)}</Text> </Fragment> );};export const run = render( <Macro app={<App />} />);
I've got two questions:
[null, null]
while a similar fetchSpaces (containing the first part) worked.
Basically, it does work (though I need to use the data different). There is a permissions problem. I'm creating a new question and closing this one.
This example contains the working fetchSpaces and the not working fetchPages
import api, { route } from "@forge/api";import ForgeUI, { render, Fragment, Text, Macro, useProductContext, useState } from '@forge/ui';const fetchSpaces = async (spaceKey) => { const res = await api .asUser() .requestConfluence(route`/wiki/api/v2/spaces?keys=${spaceKey}`); const data = await res.json(); return data.results;};const fetchPages = async (spaceKey) => { const sres = await api .asUser() .requestConfluence(route`/wiki/api/v2/spaces?keys=${spaceKey}`); const sdata = await sres.json(); console.log(`Space data: ${sres}`); const pres = await api .asUser() .requestConfluence(route`/wiki/api/v2/spaces/${sdata.id}/pages`); const pdata = await pres.json(); return pdata.results;};const App = () => { const context = useProductContext(); const spaces = useState(async () => await fetchSpaces(context.spaceKey)); const pages = useState(async () => await fetchPages(context.spaceKey)); console.log(`Received spaces and pages`); return ( <Fragment> <Text>All info about my context: {JSON.stringify(context, null, 2)}</Text> <Text>All info about my spaces: {JSON.stringify(spaces, null, 2)}</Text> <Text>All info about my pages: {JSON.stringify(pages, null, 2)}</Text> </Fragment> );};export const run = render( <Macro app={<App />} />);
One answer: the console.log did not show up in "forge logs" but it did show up in the developer portal.
It looks like you're new here. Sign in or register to get started.