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 <noreply@anthropic.com>
This commit is contained in:
19
bot.py
19
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"]
|
||||
|
||||
Reference in New Issue
Block a user