Skip to content

[Confluence] ConfluenceCloud: fix get_content_ancestors - #1711

Open
LuisFigueroaG wants to merge 1 commit into
atlassian-api:masterfrom
LuisFigueroaG:fix/confluence-cloud-content-ancestors
Open

LuisFigueroaG wants to merge 1 commit into
atlassian-api:masterfrom
LuisFigueroaG:fix/confluence-cloud-content-ancestors

Conversation

@LuisFigueroaG

Copy link
Copy Markdown
Contributor

ConfluenceCloud.get_content_ancestors(content_id) (and Confluence(url="https://<site>.atlassian.net").get_content_ancestors(...)) sends:

GET /wiki/rest/api/content/{id}/ancestors

The Confluence Cloud v1 REST API doesn't have that endpoint (it isn't in the v1 content reference or in the v1 OpenAPI spec), so the call always fails with a 404. In v1, ancestors are only exposed on the content itself through expand=ancestors (Content.ancestors in the spec).

This changes get_content_ancestors to:

  • request GET /wiki/rest/api/content/{id}?expand=ancestors, the same endpoint get_page_by_id() and get_page_space() already use;
  • return the ancestors list (top-level page first, direct parent last), the same thing the Server get_page_ancestors() returns. It returns [] for a top-level page;
  • keep any extra params passed by the caller and add expand=ancestors to them.

Tests: replaced test_get_content_ancestors in tests/confluence/test_confluence_cloud.py (it asserted the /ancestors path) and added two tests, one for extra params and one that checks the final URL is https://test.atlassian.net/wiki/rest/api/content/123?expand=ancestors. The three tests fail on master. The full pytest suite, bandit and doc8 pass, black and flake8 are clean on the changed files, and mypy reports nothing for confluence/cloud. I haven't run it against a real Confluence Cloud site.

Cloud.get_content_ancestors requests
/wiki/rest/api/content/{id}/ancestors, but the v1 content API has no
such endpoint, so the call always fails with a 404. Ancestors are only
available on the content itself through expand=ancestors.

Request /wiki/rest/api/content/{id}?expand=ancestors instead and return
the ancestors list, like the Server get_page_ancestors does. Extra
params passed by the caller are kept.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant