Skip to content

fix: use the v2 REST API for page and space operations on Confluence Cloud - #298

Merged
pchuri merged 5 commits into
pchuri:mainfrom
k-k1:feature/cloud-v2-page-api
Nov 15, 2026
Merged

pchuri merged 5 commits into
pchuri:mainfrom
k-k1:feature/cloud-v2-page-api

Conversation

@k-k1

@k-k1 k-k1 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Pull Request Template

Description

Closes #296

Atlassian is removing the v1 content/space endpoints on Confluence Cloud. On a site where they are gone, with CLI 2.31.0 (OAuth 3LO token through the api.atlassian.com gateway) read, info, create, update and space-lookup fail with HTTP 410: com.atlassian.confluence.api.service.exceptions.pagesmodes.GoneException: This deprecated endpoint has been removed. for GET/POST /content, /content/{id}, /content/{id}/child/page, /content?spaceKey= and /space/{key}. v1 /search (CQL) still works.

Page and space operations get a /wiki/api/v2 implementation (pages, blogposts, folders, spaces) whose responses are adapted to the v1 shape the client and CLI already consume.

Routing is conservative: nothing changes for anyone whose v1 endpoints still work. In the default auto mode every client starts on v1, exactly as today. Only on Cloud (existing isCloud(): *.atlassian.net, api.atlassian.com, CONFLUENCE_FORCE_CLOUD), when a v1 page/space call answers 410 Gone, does the client switch to v2 for the rest of the command and re-run that operation there (a 410 means nothing was applied, so re-sending a write is safe). Server/Data Center never switches. CONFLUENCE_PAGE_API=auto|v1|v2 (or the pageApi option) forces a family; any other value is rejected. All existing test files pass unmodified.

The change is fairly large (most of it in lib/confluence-client.js plus a new test file). I'm happy to split it, change the approach, or drop parts if you prefer a different direction.

Ported

  • read (all formats, markdown page-link resolution and children macro), info, create, create-child (pages and folders), update, edit, move (PUT parentId), delete, space-lookup, spaces, children/copy-tree/export child listing, display-URL resolution, the page fetch of inline-comment creation.

How it works

  • Content-type lookup: v1 /content/{id} served pages, blog posts and folders; v2 splits them, so read/info/delete probe /pages, /blogposts, /folders. A 404 or 401/403 on one collection (e.g. a token without the blog post scope) does not stop the search. If nothing matches, a 404 from /pages is reported as not found (naming the collections that could not be checked), while a refusal from /pages itself is reported as the auth error; 5xx/network errors stop at once.
  • Pagination: cursor-based; the next cursor is taken from the Link: rel="next" header or body _links.next (only the cursor value is used, the URL is never followed); a repeated cursor ends the listing. The library getSpaces rejects options.start on v2 instead of silently returning the first page (the CLI has no --start).
  • Matching v1 placement, order and status: a page created without a parent is sent with root-level=true (v2 otherwise files it under the space homepage; v1 created it at the space root); child listings request sort=child-position (page-tree order, which copy-tree relies on for siblings); title lookups request status=current, as v1 matched current pages only.
  • Writes after a v1 read: update/move send their PUT through the same fallback, so a site that still serves the v1 GET but answers 410 on the PUT is written once through v2.
  • copy-tree plan: v2 child listings carry no version, so copy-tree --dry-run --json fetches the version of each listed page to build plannedTreeFingerprint.
  • Ancestors: full chain, continuing past the 250-item cap from the highest ancestor; folders use /folders/{id}/ancestors.
  • Links: the listing/title-search response's _links.base is used (gateway-safe), falling back to the configured siteUrl.
  • Errors: 401/403 on v2 endpoints point to the granular scopes.

Not ported (follow-ups): attachments, content properties, version list/purge, comment list/create/delete, user-key resolution. On a site where those v1 endpoints are gone as well they still fail (the site I tested answers 410 for attachments, versions and comments), so export there needs --skip-attachments; the README says so. I kept them out to keep this PR reviewable and can follow up.

Limitations on v2 (only where v1 is gone): child listings carry no version (children JSON version is null) and their URLs are built from space key + id; info shows account IDs instead of display names and ancestors have no titles; create/update return a smaller object (no _expandable, version.by has only accountId); update/move are pages only (as before); creating a blogpost through the library is rejected rather than silently creating a page.

Scopes (OAuth 3LO / scoped tokens). Sites still on v1 keep the existing classic scopes (the README table is unchanged). Once v2 is in use, the commands need granular scopes (the README has the full table): read:page, read:blogpost, read:folder, read:space, read:content.metadata (ancestors), write:page, write:folder, delete:page / delete:blogpost / delete:folder. read:hierarchical-content is needed only for folder direct-children listings (children --type folders|all); page child listings need read:page + read:space. Classic scopes no longer cover these commands; they still cover search, attachments, comments, properties and versions. A missing scope can surface as 401 or 403. Unscoped API tokens (basic auth) are not affected.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring

Testing

  • Tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

tests/cloud-v2-pages.test.js (mocked HTTP) covers the v2 helpers and core page operations (read, info, create, create-child, update, move, delete, spaces, children); page/blogpost/folder probing including missing-scope cases; Link-header and cursor pagination; >250 ancestors; gateway link/base handling (children, title search, siteUrl fallback); Server/DC still on v1; auto mode (a Cloud site serving v1 never touches v2, a 410 switches once and later calls go straight to v2, a 410 on create re-sends once through v2, other v1 errors and Server/DC 410s are not retried); API override, invalid values and forceCloud routing; child-position sort, status=current, repeated cursors, version filling for the copy-tree plan, inline-comment body fetch via v2; markdown -> storage -> markdown round trips for Japanese text, full-width punctuation, emoji (surrogate pairs, ZWJ), code/bold adjacent to CJK, lists and tables, plus entity assertions on the JSON request body. Existing test files are unchanged and pass; forcing v2 on Cloud makes 106 of them fail, which shows they still guard the v1 behaviour. A side-by-side probe of 23 client operations against a mocked adapter produced byte-identical requests and results to main for a Cloud site still serving v1 and for Server/DC. Full jest suite (2015 tests) and lint pass.

Partial live check against a Confluence Cloud site through the OAuth gateway (the site's v1 endpoints answer 410), read-only apart from two probe pages: children (text and JSON, page-tree order), spaces and find worked through the fallback, and sort=child-position, status=current and root-level=true were accepted (a page created without a parent landed under the homepage without root-level, at the root with it). Commands needing scopes our token lacks (read:content.metadata, read:hierarchical-content) returned the 401 with the scope hint as expected. Writes and edit/copy-tree/export were not exercised end-to-end against v2 from this branch.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules (n/a)

Additional Context

AI assistance (Claude Code) was used for the change, its review and validation.

🤖 Generated with Claude Code

k-k1 and others added 5 commits November 3, 2026 14:43
…Cloud

Atlassian removed the v1 /content and /space endpoints on Cloud; they now
answer 410 Gone, which breaks read, info, create, create-child, update,
edit, move, delete, children, spaces and space-lookup.

On Cloud, route these through /wiki/api/v2 (pages, folders, spaces) and
adapt the responses to the v1 shape the rest of the client and CLI already
consume. Server/Data Center keeps the v1 endpoints unchanged.
CONFLUENCE_PAGE_API=v1|v2 (or the pageApi option) overrides the automatic
choice.

Add tests for the v2 paths, including Japanese text, full-width
punctuation, emoji and ZWJ sequences, inline code/bold next to CJK, lists
and tables through markdown -> storage -> markdown. Existing v1-mocking
suites now pin pageApi: 'v1'.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- Document granular scopes per command (incl. delete and ancestors) and
  show v2-specific scope guidance on 401/403 from v2 endpoints.
- Read the Link rel="next" header (cursor only) as well as _links.next
  when paginating v2 lists.
- Use the listing's _links.base, or the configured siteUrl, for child
  page links so gateway usage no longer yields api.atlassian.com URLs.
- Resolve folder parent/ancestors via /folders/{id}/ancestors and honour
  the record's parentId in normalizePage.
- Continue ancestor chains beyond the 250-item cap from the highest
  ancestor.
- Resolve blog post ids via /blogposts/{id} for read/info/delete.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- Pass the title-search response _links.base into shaped pages so
  gateway usage yields site URLs.
- When probing /pages, /blogposts and /folders, keep searching after a
  401/403 on one collection and report the auth error (not a 404) if
  nothing matches; stop on 5xx/network errors. Applies to read, info
  and delete.
- Rewrite the README scope documentation per actual CLI call path and
  limit the classic scope table to the endpoints still on v1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…lder read

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Switching every Cloud client to v2 changed output for sites whose v1
endpoints still work (null child versions, account IDs instead of names,
ancestors without titles) and broke `copy-tree --dry-run --json`, whose
plan fingerprint needs a version per page.

In the default auto mode a client now starts on v1 everywhere. On Cloud a
v1 page/space call that answers 410 switches the client to v2 and re-runs
that operation there; a 410 applied nothing, so a write is sent once more.
Server/Data Center never switches. Unknown CONFLUENCE_PAGE_API values are
rejected.

Also from review:
- copy-tree dry-run JSON fills in missing versions from v2.
- v2 child listings ask for child-position order, title lookups for
  current pages, and a page created without a parent goes to the space
  root (root-level=true), as on v1.
- A wrong id is reported as not found when /pages answers 404 and only a
  later collection refuses.
- getSpaces rejects options.start on v2; creating a blog post through v2
  is refused instead of creating a page; repeated cursors end a listing.
- README keeps the classic scope table and documents the fallback.

Existing test files are back to upstream and pass unchanged. A probe
comparing requests and results with upstream/main for 23 operations is
byte-identical for Cloud (v1 working) and Server. Full jest suite (2015)
and lint pass. Live, read-only, against a site whose v1 answers 410:
children, spaces and find work through the fallback; root-level, sort
and status parameters were checked live.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pchuri

pchuri commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Thank you so much for this, @k-k1! Really appreciate the careful approach of staying on v1 until a 410 shows up, so nothing changes for anyone whose v1 endpoints still work, and the thorough test coverage for the v2 paths. This is a big help for Cloud users as the v1 endpoints go away. Merging now.

@pchuri
pchuri merged commit 470e0f2 into pchuri:main Nov 15, 2026
6 checks passed
github-actions Bot pushed a commit that referenced this pull request Nov 15, 2026
## [2.31.1](v2.31.0...v2.31.1) (2026-11-15)

### Bug Fixes

* use the v2 REST API for page and space operations on Confluence Cloud ([#298](#298)) ([470e0f2](470e0f2))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 2.31.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Page commands return 410 on Confluence Cloud: v1 content API removed

2 participants