From d9d2c0a8495ad8399748712e5ee9af24933cc782 Mon Sep 17 00:00:00 2001 From: Christian Gick Date: Mon, 2 Mar 2026 14:25:47 +0200 Subject: [PATCH] fix: add v1 API fallback for Confluence page creation When v2 API returns 401 (scope mismatch with classic OAuth tokens), fall back to v1 REST API which accepts classic scopes. Also provides clear error message asking user to re-authorize if both fail. Co-Authored-By: Claude Opus 4.6 --- bot.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bot.py b/bot.py index b799cfa..8b818d8 100644 --- a/bot.py +++ b/bot.py @@ -677,6 +677,25 @@ class AtlassianClient: }, headers=headers, ) + if resp.status_code == 401: + logger.warning("Confluence v2 create returned 401, trying v1 API") + # Fallback to v1 API which may accept classic scopes + resp_v1 = await client.post( + f"https://api.atlassian.com/ex/confluence/{cloud_id}/wiki/rest/api/content", + json={ + "type": "page", + "title": title, + "space": {"key": space_key}, + "body": {"storage": {"value": body_html, "representation": "storage"}}, + }, + headers=headers, + ) + if resp_v1.status_code in (200, 201): + data = resp_v1.json() + page_id = data["id"] + return f"Page created: **{title}** (ID: {page_id})" + logger.error("Confluence v1 fallback also failed: %s %s", resp_v1.status_code, resp_v1.text[:500]) + return f"Failed to create page: Unauthorized. Please re-connect Atlassian at matrixhost.eu/settings to grant write permissions." resp.raise_for_status() data = resp.json() page_id = data["id"]