Skip to content

Confluence v2 implementation (Cloud) #1521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ee75535
Add Confluence API v2 implementation checklist
batzel-upenn Apr 1, 2025
069d82c
Implement Phase 1: Core Structure for Confluence API v2 support
batzel-upenn Apr 1, 2025
8c42d8e
Implement Phase 2: Core Methods for Confluence API v2 support
batzel-upenn Apr 1, 2025
7c39517
Implement comment methods for Confluence V2 API
batzel-upenn Apr 1, 2025
3db6c24
Implement whiteboard and custom content methods for Confluence V2 API
batzel-upenn Apr 1, 2025
41eafe3
Implement Confluence V2 API compatibility layer and migration guide
batzel-upenn Apr 1, 2025
c066bf0
Complete Phase 4: Testing for Confluence v2 API implementation
batzel-upenn Apr 1, 2025
1631205
Add remaining Confluence v2 implementation files for Phases 1-4
batzel-upenn Apr 1, 2025
16f3b50
Complete Phase 5: Documentation for Confluence v2 API implementation
batzel-upenn Apr 1, 2025
e27d132
Improve security by removing hardcoded credentials and implement envi…
batzel-upenn Apr 1, 2025
9e17480
Update README.rst to add contributor credits for Confluence v2 API im…
batzel Apr 1, 2025
8b81956
refactor: reorganize Confluence module into proper directory structure
batzel Apr 2, 2025
f323c6e
security: improve URL validation in Confluence base class
batzel Apr 2, 2025
bc46a89
fix: update imports and test structure for new Confluence module orga…
batzel Apr 2, 2025
b1f313e
Fix hanging Confluence tests and improve test reliability
batzel Apr 2, 2025
0214848
Fix URL handling to prevent /wiki/wiki duplication in Confluence client
batzel Apr 2, 2025
bf7ba62
Merge master into confluence-v2-implementation
batzel Apr 2, 2025
bf54d8c
Add space-related methods from master to refactored Confluence structure
batzel Apr 2, 2025
eeb0d05
Complete refactoring of Confluence Cloud module with V2 API support
batzel Apr 2, 2025
53e3fde
Fix Codacy critical issues in examples - Fixed parameter names for AP…
batzel Apr 2, 2025
3391763
Fix string statement and unused variable in examples/confluence_v2_co…
batzel Apr 2, 2025
040394d
Fix unused variables and cleanup example files
batzel Apr 2, 2025
56cc3cf
Fix Codacy Critical issue - remove return statement outside function
batzel Apr 2, 2025
117820a
Fix Codacy code style issues - remove unused imports, fix parameter n…
batzel Apr 2, 2025
12c5927
Apply Black formatting to improve code style
batzel Apr 2, 2025
d15454d
Apply isort to fix import order issues
batzel Apr 2, 2025
1af094d
Add custom content label and property methods, fix compatibility laye…
batzel Apr 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,43 @@ The traditional jql method is deprecated for Jira Cloud users, as Atlassian has
data = jira.enhanced_jql(JQL)
print(data)

Using Confluence v2 API
_______________________

The library now supports Confluence's v2 API for Cloud instances. The v2 API provides improved performance, new content types, and more consistent endpoint patterns.

.. code-block:: python

from atlassian import Confluence

# Initialize with v2 API
confluence = Confluence(
url='https://your-instance.atlassian.net/wiki',
username='[email protected]',
password='your-api-token',
api_version=2, # Specify API version 2
cloud=True # v2 API is only available for cloud instances
)

# Get pages from a space
pages = confluence.get_pages(space_key='DEMO', limit=10)

# Create a new page
new_page = confluence.create_page(
space_id='DEMO',
title='New Page with v2 API',
body='<p>This page was created using the v2 API</p>'
)

# Use v2-only features like whiteboards
whiteboard = confluence.create_whiteboard(
space_id='DEMO',
title='My Whiteboard',
content='{"version":1,"type":"doc","content":[]}'
)

The library includes a compatibility layer to ease migration from v1 to v2 API. See the migration guide in the documentation for details.

Also, you can use the Bitbucket module e.g. for getting project list

.. code-block:: python
Expand Down Expand Up @@ -211,11 +248,12 @@ In addition to all the contributors we would like to thank these vendors:
* Atlassian_ for developing such a powerful ecosystem.
* JetBrains_ for providing us with free licenses of PyCharm_
* Microsoft_ for providing us with free licenses of VSCode_
* GitHub_ for hosting our repository and continuous integration
* Cursor.com_ for AI assistance in development
* John B Batzel ([email protected]) for implementing the Confluence Cloud v2 API support

.. _Atlassian: https://www.atlassian.com/
.. _JetBrains: http://www.jetbrains.com
.. _PyCharm: http://www.jetbrains.com/pycharm/
.. _GitHub: https://github.com/
.. _Microsoft: https://github.com/Microsoft/vscode/
.. _VSCode: https://code.visualstudio.com/
.. _Microsoft: https://www.microsoft.com
.. _VSCode: https://code.visualstudio.com
.. _Cursor.com: https://cursor.com
55 changes: 55 additions & 0 deletions README_TEST_SCRIPTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Test Scripts for Confluence V2 API

## Overview

These test scripts are used to test the Confluence V2 API implementation. They require credentials to connect to a Confluence instance.

## Setting Up Credentials

To run the test scripts, you need to set up your Confluence credentials.

### Step 1: Create a .env file

Create a `.env` file in the root directory of the project with the following format:

```
CONFLUENCE_URL=https://your-instance.atlassian.net
[email protected]
CONFLUENCE_API_TOKEN=your-api-token
CONFLUENCE_SPACE_KEY=SPACE
```

Replace the values with your own credentials:
- `CONFLUENCE_URL`: The URL of your Confluence instance
- `CONFLUENCE_USERNAME`: Your Confluence username (usually an email)
- `CONFLUENCE_API_TOKEN`: Your Confluence API token (can be generated in your Atlassian account settings)
- `CONFLUENCE_SPACE_KEY`: The key of a space in your Confluence instance that you have access to

### Step 2: Install required packages

Make sure you have all required packages installed:

```
pip install -r requirements-dev.txt
```

### Step 3: Run the scripts

Now you can run the test scripts:

```
python test_search.py
python test_pages.py
```

## Security Note

The `.env` file is listed in `.gitignore` to prevent accidentally committing your credentials to the repository. Never commit your credentials directly in code files.

If you need to find available spaces to use for testing, you can run:

```
python get_valid_spaces.py
```

This will output a list of spaces that you have access to, which can be used for the `CONFLUENCE_SPACE_KEY` environment variable.
36 changes: 35 additions & 1 deletion atlassian/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
"""
Atlassian Python API
"""

from .bamboo import Bamboo
from .bitbucket import Bitbucket
from .bitbucket import Bitbucket as Stash
from .cloud_admin import CloudAdminOrgs, CloudAdminUsers
from .confluence import Confluence
from .confluence import (
Confluence,
ConfluenceBase,
ConfluenceCloud,
ConfluenceServer,
)
from .crowd import Crowd
from .insight import Insight
from .insight import Insight as Assets
Expand All @@ -13,8 +22,33 @@
from .service_desk import ServiceDesk as ServiceManagement
from .xray import Xray

# Compatibility: ConfluenceV2 is now ConfluenceCloud
ConfluenceV2 = ConfluenceCloud


# Factory function for Confluence client
def create_confluence(url, *args, api_version=1, **kwargs):
"""
Create a Confluence client with the specified API version.

Args:
url: The Confluence instance URL
api_version: API version, 1 or 2, defaults to 1
args: Arguments to pass to Confluence constructor
kwargs: Keyword arguments to pass to Confluence constructor

Returns:
A Confluence client configured for the specified API version
"""
return ConfluenceBase.factory(url, *args, api_version=api_version, **kwargs)


__all__ = [
"Confluence",
"ConfluenceBase",
"ConfluenceCloud",
"ConfluenceServer",
"ConfluenceV2", # For backward compatibility
"Jira",
"Bitbucket",
"CloudAdminOrgs",
Expand Down
1 change: 1 addition & 0 deletions atlassian/bamboo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging

from requests.exceptions import HTTPError

from .rest_client import AtlassianRestAPI

log = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion atlassian/bitbucket/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import copy
import re
import sys

from datetime import datetime
from pprint import PrettyPrinter

from ..rest_client import AtlassianRestAPI

RE_TIMEZONE = re.compile(r"(\d{2}):(\d{2})$")
Expand Down
2 changes: 1 addition & 1 deletion atlassian/bitbucket/cloud/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# coding=utf-8

from .base import BitbucketCloudBase
from .workspaces import Workspaces
from .repositories import Repositories
from .workspaces import Workspaces


class Cloud(BitbucketCloudBase):
Expand Down
3 changes: 2 additions & 1 deletion atlassian/bitbucket/cloud/base.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# coding=utf-8

import logging
from ..base import BitbucketBase

from requests import HTTPError

from ..base import BitbucketBase

log = logging.getLogger(__name__)


Expand Down
5 changes: 3 additions & 2 deletions atlassian/bitbucket/cloud/repositories/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# coding=utf-8

from requests import HTTPError

from ..base import BitbucketCloudBase
from .issues import Issues
from .branchRestrictions import BranchRestrictions
from .commits import Commits
from .hooks import Hooks
from .defaultReviewers import DefaultReviewers
from .deploymentEnvironments import DeploymentEnvironments
from .groupPermissions import GroupPermissions
from .hooks import Hooks
from .issues import Issues
from .pipelines import Pipelines
from .pullRequests import PullRequests
from .refs import Branches, Tags
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# coding=utf-8

from ..base import BitbucketCloudBase
from six.moves.urllib.parse import urlsplit, urlunsplit

from six.moves.urllib.parse import urlunsplit, urlsplit
from ..base import BitbucketCloudBase


class DeploymentEnvironments(BitbucketCloudBase):
Expand Down
2 changes: 1 addition & 1 deletion atlassian/bitbucket/cloud/repositories/pipelines.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# coding=utf-8

from .pullRequests import PullRequest
from requests import HTTPError

from ..base import BitbucketCloudBase
from .pullRequests import PullRequest


class Pipelines(BitbucketCloudBase):
Expand Down
6 changes: 3 additions & 3 deletions atlassian/bitbucket/cloud/repositories/pullRequests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# coding=utf-8

from ..base import BitbucketCloudBase
from .diffstat import DiffStat
from ...cloud.repositories.commits import Commit
from ..base import BitbucketCloudBase
from ..common.builds import Build
from ..common.comments import Comment
from ..common.users import User, Participant
from ..common.users import Participant, User
from .diffstat import DiffStat


class PullRequests(BitbucketCloudBase):
Expand Down
4 changes: 2 additions & 2 deletions atlassian/bitbucket/cloud/workspaces/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# coding=utf-8

from requests import HTTPError
from ..base import BitbucketCloudBase

from ..base import BitbucketCloudBase
from ..repositories import WorkspaceRepositories
from .members import WorkspaceMembers
from .permissions import Permissions
from .projects import Projects
from ..repositories import WorkspaceRepositories


class Workspaces(BitbucketCloudBase):
Expand Down
2 changes: 1 addition & 1 deletion atlassian/bitbucket/cloud/workspaces/projects.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# coding=utf-8

from requests import HTTPError
from ..base import BitbucketCloudBase

from ..base import BitbucketCloudBase
from ..repositories import ProjectRepositories


Expand Down
2 changes: 1 addition & 1 deletion atlassian/bitbucket/server/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# coding=utf-8

from .base import BitbucketServerBase
from .projects import Projects
from .globalPermissions import Groups, Users
from .projects import Projects


class Server(BitbucketServerBase):
Expand Down
3 changes: 2 additions & 1 deletion atlassian/bitbucket/server/projects/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# coding=utf-8

from requests import HTTPError
from .repos import Repositories

from ..base import BitbucketServerBase
from ..common.permissions import Groups, Users
from .repos import Repositories


class Projects(BitbucketServerBase):
Expand Down
1 change: 1 addition & 0 deletions atlassian/bitbucket/server/projects/repos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding=utf-8

from requests import HTTPError

from ...base import BitbucketServerBase
from ...common.permissions import Groups, Users

Expand Down
Loading
Loading