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.