Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,557,867
Community Members
 
Community Events
184
Community Groups

Get all pages for a confluence user via Forge

Here is my current code. It gets the first 250 page records (limit=250.) But it returns a 401 error ({ code: 401, message: 'Unauthorized; scope does not match' }) from the second request for the remaining pages.

here is my function ```

async function getAllPages(url: string, allPages: any[] = []): Promise<any[]> {
const confluenceUrl: Readonly<string> = url;
const routeUrl = route`${confluenceUrl}`;
//@prettier-ignore-next-line
let pagesFromApi = await api.asUser().requestConfluence(route`${url}`, {
headers: {
Accept: 'application/json',
},
});
console.log(await pagesFromApi.json(), 'this is pages from api');

console.log(
pagesFromApi.status,
pagesFromApi.statusText,
'this is pages from api',
);

const res = await pagesFromApi.json();
console.log(res.results, 'this is res');
console.log(url, 'this is the url');

allPages = allPages.concat(res.results);

if (pagesFromApi.headers.has('link')) {
const link = pagesFromApi.headers
.get('link')
?.match(/<([^>]+)>;\s*rel="next"/)?.[1]
.replace(/==/g, '');
if (link) {
console.log(`${link}`, 'this is the link');

allPages = await getAllPages(`${link.replace(/\s+/g, '')}`, allPages);
}
}

return allPages;
}

resolver.define('getText', async req => {
let pages = await getAllPages('/wiki/api/v2/pages');
// console.log(pages, 'this is pages');
console.log(pages.length, 'this is pages length');

return 'Hello, world!';
});

```
and here are the scopes ```

permissions:
scopes:
- read:confluence-space.summary
- read:confluence-props
- read:page:confluence
- read:confluence-content.all
- read:confluence-content.summary
- search:confluence
- read:confluence-content.permission
- read:confluence-user

```
Please help!

1 answer

0 votes
Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 02, 2023

Hi @shawn 

I would suggest to create a post at the developers' community, since you'll have more chances of getting a proper reply https://community.developer.atlassian.com/

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events