Skip to content

[Confluence Cloud] api.atlassian.com users get 401 'scope does not match' with default wiki/api/v2 settings #1618

@Zircoz

Description

@Zircoz

Description

Users accessing Confluence Cloud via the OAuth2 API gateway (https://api.atlassian.com/ex/confluence/<tenant-id>) get a 401 Unauthorized; scope does not match error with the current Cloud defaults.

Root cause

The ConfluenceCloud client defaults to api_root="wiki/api/v2" and api_version="2". The Confluence v2 REST API requires a different OAuth scope set (read:content:confluence) compared to v1. Standard Atlassian API tokens (issued via id.atlassian.com) are scoped for the v1 REST API and fail against v2 endpoints.

GET https://api.atlassian.com/ex/confluence/<tenant-id>/wiki/api/v2/content
→ 401 Unauthorized; scope does not match

Workaround (currently required)

Pass api_root and api_version explicitly to force v1:

confluence = Confluence(
    url="https://api.atlassian.com/ex/confluence/<tenant-id>",
    username=email,
    password=api_token,
    cloud=True,
    api_root="wiki/rest/api",   # override default wiki/api/v2
    api_version="latest",        # must match api_root
)

This is not discoverable and causes silent failures for new users.

Proposed fix

Auto-detect the appropriate api_root based on the URL when not explicitly set. For api.atlassian.com gateway URLs, fall back to wiki/rest/api (v1) since standard API tokens are issued for v1 scopes. Users with proper v2 OAuth app credentials can still override explicitly.

Alternatively, improve the error message to guide users toward the correct api_root setting when a 401 scope error is detected.

Environment

  • Library version: master (post Confluence v2 implementation #1523 new Confluence implementation)
  • Confluence Cloud via api.atlassian.com OAuth2 gateway
  • Standard Atlassian API token (not an OAuth2 app with custom scopes)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions