From c33e8e6f0a2f82c06fc758dde0513a4946df7989 Mon Sep 17 00:00:00 2001 From: Felix Schumacher Date: Thu, 10 Sep 2026 07:24:24 +0200 Subject: [PATCH] Fix attach_content on Confluence Server with an existing attachement On-Premise Confluence Server doesn't support PUT like the Cloud version. We have to use the old code path from 4.x, where we use POST on a path below the child. Fixes #1677 Follow-Up to #1666 --- atlassian/confluence/server/__init__.py | 27 +++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/atlassian/confluence/server/__init__.py b/atlassian/confluence/server/__init__.py index d0147df32..c42e7c927 100644 --- a/atlassian/confluence/server/__init__.py +++ b/atlassian/confluence/server/__init__.py @@ -1279,15 +1279,26 @@ def attach_content( pass if existing_attachment: - # Update existing attachment using PUT on the specific attachment ID + # Update existing attachment on the specific attachment ID attachment_id = existing_attachment["id"] - update_path = f"rest/api/content/{attachment_id}" - response = self.put( - path=update_path, - data=data, - headers=headers, - files={"file": (name, content, content_type)}, - ) + if self.api_version == "1.0": + # older API versions use POST on data path below the child + update_path = f"{path}/{attachment_id}/data" + response = self.post( + path=update_path, + data=data, + headers=headers, + files={"file": (name, content, content_type)}, + ) + else: + # newer API versions use PUT on a path derived from the attachment ID directly + update_path = f"rest/api/content/{attachment_id}" + response = self.put( + path=update_path, + data=data, + headers=headers, + files={"file": (name, content, content_type)}, + ) else: # Create new attachment using POST response = self.post(