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"]