Hi there,
I recently came across a strange issue with the search api in Confluence. I use it in my custom UI Confluence app.
It works fine like this:
response = await api
.asUser()
.requestConfluence(route`/wiki/rest/api/search?cql=${cql}&limit=50&expand=body.storage,body.dynamic,version`, {
headers: {
'Accept': 'application/json'
}
});
The cql variable has the value ‘space=DEV AND type=page’
When a query returns more than 50 pages, I want to send another request which gives me the next 50 pages. I read in the documentation that I should use the next-URL in the response. However, I realized that the expand part does not work with the next-URL as I have to use ‘expand=content.body.storage,content.body.dynamic,content.version’ instead (the results array entries have a content child element).
I tried to define the part after route as variable define the “next”-request like this
response = await api
.asUser()
.requestConfluence(route`${request}`, {
headers: {
'Accept': 'application/json'
}
});
The request variable has the value of the “next”-url:
/wiki/rest/api/search?next=true&cursor=_sa_WyJcdDMxMDQ3OTggaUIoXz1eXkVGM1ZgYnVSaExNbmogY3AiXQ%3D%3D&expand=content.body.storage%2Ccontent.body.dynamic%2Ccontent.version&limit=50&start=50&cql=space%3DDEV+AND+type%3Dpage
When I execute this, I always get this error
{"code":401,"message":"Unauthorized; scope does not match"}
I have the search:confluence permission scope in my manifest and it is the same error for asUser() and asApp().
On the other hand, when I try it like this (without variable) it works fine and I get a 200 status and a result.
response = await api
.asUser()
.requestConfluence(route`/wiki/rest/api/search?next=true&cursor=_sa_WyJcdDMxMDQ3OTggaUIoXz1eXkVGM1ZgYnVSaExNbmogY3AiXQ%3D%3D&expand=content.body.storage%2Ccontent.body.dynamic%2Ccontent.version&limit=50&start=50&cql=space%3DDEV+AND+type%3Dpage`, {
headers: {
'Accept': 'application/json'
}
});
Has anyone an idea what I need to do to make it work also with a variable? The 401 error doesn’t make much sense here. I already tried a lot like using request as request.toString() or JSON.stringify(request), asUser(), asApp()
nothing worked so far
Any help is appreciated.