atlassian-api / atlassian-python-api

Atlassian Python REST API wrapper
https://atlassian-python-api.readthedocs.io
Apache License 2.0
1.29k stars 642 forks source link

CQL endpoint #1312

Open ZlobinaElena opened 5 months ago

ZlobinaElena commented 5 months ago

I faced an issue with retrieving the body.storage field in your request using the CQL method in Confluence's REST API.

Issue Description: I'm trying to retrieve the body.storage field in my request using the CQL method in Confluence's REST API. I have set expand=body.storage in my request, but unfortunately, the body key is not present in the result.

Investigation: Upon researching, I found that the endpoint for CQL content search is /wiki/rest/api/content/search?cql=type=page&limit=25. Could you please comment the problem?

gkowalc commented 5 months ago

Do you want to get storage format of each returned page returned by cql? If so this won' work with this single api call:

test = confleunce_cloud.cql(cql='space = "TEST"', limit=25, expand='content.body.storage')
json = json.dumps(test, indent=4)
print(json)

you will get something like:

    "results": [
        {
            "content": {
                "id": "448972356",
                "type": "page",
                "status": "current",
                "title": "test",
                "macroRenderedOutput": {},
                "body": {
                    "storage": {
                        "value": "test",
                        "representation": "storage",
                        "embeddedContent": [],
                        "_expandable": {
                            "content": "/rest/api/content/448972356"
                        }
                    },
                    "_expandable": {
                        "editor": "",
                        "atlas_doc_format": "",
                        "view": "",
                        "export_view": "",
                        "styled_view": "",
                        "dynamic": "",
                        "editor2": "",
                        "anonymous_export_view": ""
                    }

As you can see body.storage. doesn't include any valuable information returned by the API.

However, you can try doing something like this instead:

import json
test = confleunce_cloud.cql(cql=' type=page AND title  ~ "test"', limit=25)
for issue in test['results']:
       page_storage_form =  confleunce_cloud.get_page_by_id(issue['content']['id'], expand='body.storage')
       print(page_storage_form['body']['storage']['value'])

this will return all the storage formats from pages returned by cql. Let me know if this works.

ZlobinaElena commented 5 months ago

Thank you for your response. I have encountered a challenge while attempting to retrieve all pages using the start and limit parameters. Unfortunately, the current implementation does not seem to be working as expected, as I keep receiving the same pages in each iteration. It appears that the start parameter is not functioning correctly. Code Snippet:

res = []
start = 0
limit = 5

while True:
    test = confluence.cql(cql='space = "TEST" and type = page', start=start, limit=limit, expand='content.body.storage')
    test = test.get("results", [])
    res.extend(test)
    if len(test) < 5:
        break
    start += limit

print(len(res))

Could you please help me identify the issue and provide guidance on how to correctly use the start parameter to fetch all pages? Your assistance is greatly appreciated.