Skip to content

fix(confluence): support scoped API tokens via the api.atlassian.com gateway - #798

Open
hrabal-myo wants to merge 1 commit into
kovetskiy:masterfrom
hrabal-myo:fix/scoped-token-gateway
Open

fix(confluence): support scoped API tokens via the api.atlassian.com gateway#798
hrabal-myo wants to merge 1 commit into
kovetskiy:masterfrom
hrabal-myo:fix/scoped-token-gateway

Conversation

@hrabal-myo

Copy link
Copy Markdown

Problem

Atlassian's scoped API tokens only authenticate against the gateway URL https://api.atlassian.com/ex/confluence/<cloudId>/wiki — used directly against <site>.atlassian.net they are treated as anonymous. Running mark in that setup currently fails in two places:

  1. FindHomePage fails with 404 — the v1 endpoint GET /rest/api/space/<key> answers 404 for scoped tokens (they lack the classic scopes), so every run aborts with can't obtain home page from space (mark cli command showing can't obtain home page from space TEST1 #341 reports this symptom).
  2. Folder support is rejectedIsCloud() only recognizes *.jira.com / *.atlassian.net, so with the gateway base URL mark refuses <!-- Folder: --> even though the gateway always fronts a Cloud instance.

Fix

  • FindHomePage: keep the v1 call, but on a non-OK response fall back to the v2 spaces API (GET /api/v2/spaces?keys=<key>) and resolve the homepage via GetPageByID. Behaviour for classic tokens / Server is unchanged (v1 still wins when it works).
  • IsCloud(): additionally recognize the host api.atlassian.com.

Testing

  • go build ./..., go vet, go test ./... all pass.
  • Running in production since 2026-07-03 (as a patch on v16.5.0) in a GitHub Actions pipeline publishing a docs repo to Confluence Cloud with a scoped token via the gateway, including folder parents — pages and folders sync correctly.

Fixes #341

🤖 Generated with Claude Code

Scoped Atlassian API tokens only work against the
https://api.atlassian.com/ex/confluence/<cloudId>/wiki gateway. Two
places in mark break in that setup:

1. FindHomePage uses the v1 space endpoint, which answers 404 for
   scoped tokens (they lack classic scopes). Fall back to the v2
   spaces API and resolve the homepage via its ID.

2. IsCloud() only recognizes *.jira.com and *.atlassian.net, so
   folder support is rejected as "not Cloud" even though the gateway
   always fronts a Cloud instance. Recognize api.atlassian.com.

Fixes kovetskiy#341

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Confluence client to properly support Atlassian scoped API tokens by working with the api.atlassian.com gateway behavior: it adds a v2 API fallback for resolving a space homepage and broadens Cloud detection to accept the gateway host.

Changes:

  • Add a fallback in FindHomePage from the v1 space endpoint to the v2 spaces API and resolve the homepage via GetPageByID.
  • Update IsCloud() to recognize api.atlassian.com as a Cloud host (gateway for scoped tokens).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread confluence/api.go
Comment on lines 237 to +242
request, err := api.rest.Res(
"space/"+space, &SpaceInfo{},
).Get(payload)
if err == nil && request.Raw.StatusCode == http.StatusOK {
return &request.Response.(*SpaceInfo).Homepage, nil
}
Comment thread confluence/api.go
Comment on lines +244 to +246
// Confluence Cloud answers 404 on the v1 space endpoint for tokens
// without classic scopes; fall back to the v2 spaces API.
v2Result := struct {
Comment thread confluence/api.go
Comment on lines +965 to +967
return strings.HasSuffix(host, "jira.com") ||
strings.HasSuffix(host, "atlassian.net") ||
host == "api.atlassian.com"
SelfSimon added a commit to SelfSimon/netbox-mcp that referenced this pull request Jul 19, 2026
mark's scoped-token/service-account support is stuck behind an
unmerged, buggy PR (kovetskiy/mark#798) as of 2026-07-18, which would
force paying for a full Atlassian user license. md2conf documents
first-class support for the api.atlassian.com scoped-token gateway,
so the Confluence bot can run on a free service account instead.

OBJECT_COVERAGE.md's mark-style header comments are replaced with
md2conf's HTML-comment front matter (title override + a
confluence-sync marker the CI workflow greps for).
@Jark

Jark commented Jul 28, 2026

Copy link
Copy Markdown

@hrabal-myo this PR seems 3 weeks old with suggestions from GH copilot on it.

Do you mind if I take a stab at fixing it?

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.

mark cli command showing can't obtain home page from space TEST1

3 participants