Skip to content

[Confluence] Get all paginated CQL search results  #1127

Open
@p-rinnert

Description

@p-rinnert

Hey,

I am using Confluence Cloud and have a CQL query that intentionally results in many results (>1000) in our Confluence space. The response of the Confluence API to my Confluence.cql() call is a paginated response, where the first 250 items (seems to be the max for our Cloud instance) are contained in the [results] and the next 250 results can be retrieved by calling the next link defined in ['_links']['next'].
I was able to use the Confluence._get_paged() function in my code to retrieve all results but it seems that Confluence.cql() should (or at least could) return all results directly.

This is my solution as minimal example:

from atlassian import Confluence
import itertools

confluence = Confluence(url="https://MYCOMPANY.atlassian.net/",
                        username="name@company.com",
                        password="password")

cql_query = 'type=page' # CQL query with for all pages = many results

response = confluence.cql(cql, limit=250) # response contains first 250 results and link to the next 250 results

url_next = response.get('_links', {}).get('next') # get relative next result address

if url_next is not None:
        results_generator = itertools.chain(response.get('results'),
                                            confluence._get_paged(url=url_next))
        results = list(results_generator)
else:
        results = response.get('results', [])

Is there another way to directly get all results that I did not see yet? Or a more efficient or elegant?
Confluence._get_paged() seems to be build for exactly this use case but is not integrated in Confluence.cql(). Could this be integrated into Confluence.cql()? I am new to the topic and therefore not sure about implications or expected behavior.

Thanks in advance
Paul

Metadata

Metadata

Assignees

No one assigned

    Labels

    confluenceAtlassian Confluence (Cloud, Server or Dataceneter)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions