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 11 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='your-email@example.com',
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 (batzel@upenn.edu) 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
CONFLUENCE_USERNAME=your-email@example.com
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.
23 changes: 23 additions & 0 deletions atlassian/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from .bitbucket import Bitbucket as Stash
from .cloud_admin import CloudAdminOrgs, CloudAdminUsers
from .confluence import Confluence
from .confluence_base import ConfluenceBase
from .confluence_v2 import ConfluenceV2
from .crowd import Crowd
from .insight import Insight
from .insight import Insight as Assets
Expand All @@ -13,8 +15,29 @@
from .service_desk import ServiceDesk as ServiceManagement
from .xray import Xray


# 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",
"ConfluenceV2",
"create_confluence",
"Jira",
"Bitbucket",
"CloudAdminOrgs",
Expand Down
10 changes: 4 additions & 6 deletions atlassian/confluence.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
ApiPermissionError,
ApiValueError,
)
from .rest_client import AtlassianRestAPI
from .confluence_base import ConfluenceBase

log = logging.getLogger(__name__)


class Confluence(AtlassianRestAPI):
class Confluence(ConfluenceBase):
content_types = {
".gif": "image/gif",
".png": "image/png",
Expand All @@ -40,10 +40,8 @@ class Confluence(AtlassianRestAPI):
}

def __init__(self, url, *args, **kwargs):
if ("atlassian.net" in url or "jira.com" in url) and ("/wiki" not in url):
url = AtlassianRestAPI.url_joiner(url, "/wiki")
if "cloud" not in kwargs:
kwargs["cloud"] = True
# Set default API version to 1 for backward compatibility
kwargs.setdefault('api_version', 1)
super(Confluence, self).__init__(url, *args, **kwargs)

@staticmethod
Expand Down
Loading
Loading