You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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!
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/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.