fix: use Confluence v2 API for page creation (v1 returns 410 Gone)
Switch from /wiki/rest/api/content to /wiki/api/v2/pages. V2 requires space ID instead of key, so resolve via /api/v2/spaces first. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
27
bot.py
27
bot.py
@@ -651,18 +651,31 @@ class AtlassianClient:
|
|||||||
if not cloud_id:
|
if not cloud_id:
|
||||||
return "Error: Could not determine Atlassian Cloud instance."
|
return "Error: Could not determine Atlassian Cloud instance."
|
||||||
try:
|
try:
|
||||||
paragraphs = [p.strip() for p in content.split("\n") if p.strip()]
|
headers = {"Authorization": f"Bearer {token}"}
|
||||||
body_html = "".join(f"<p>{p}</p>" for p in paragraphs) if paragraphs else f"<p>{content}</p>"
|
|
||||||
async with httpx.AsyncClient(timeout=15.0) as client:
|
async with httpx.AsyncClient(timeout=15.0) as client:
|
||||||
|
# Resolve space key to space ID (v2 API requires ID)
|
||||||
|
space_resp = await client.get(
|
||||||
|
f"https://api.atlassian.com/ex/confluence/{cloud_id}/wiki/api/v2/spaces",
|
||||||
|
params={"keys": space_key},
|
||||||
|
headers=headers,
|
||||||
|
)
|
||||||
|
space_resp.raise_for_status()
|
||||||
|
spaces = space_resp.json().get("results", [])
|
||||||
|
if not spaces:
|
||||||
|
return f"Space '{space_key}' not found."
|
||||||
|
space_id = spaces[0]["id"]
|
||||||
|
|
||||||
|
paragraphs = [p.strip() for p in content.split("\n") if p.strip()]
|
||||||
|
body_html = "".join(f"<p>{p}</p>" for p in paragraphs) if paragraphs else f"<p>{content}</p>"
|
||||||
resp = await client.post(
|
resp = await client.post(
|
||||||
f"https://api.atlassian.com/ex/confluence/{cloud_id}/wiki/rest/api/content",
|
f"https://api.atlassian.com/ex/confluence/{cloud_id}/wiki/api/v2/pages",
|
||||||
json={
|
json={
|
||||||
"type": "page",
|
"spaceId": space_id,
|
||||||
|
"status": "current",
|
||||||
"title": title,
|
"title": title,
|
||||||
"space": {"key": space_key},
|
"body": {"representation": "storage", "value": body_html},
|
||||||
"body": {"storage": {"value": body_html, "representation": "storage"}},
|
|
||||||
},
|
},
|
||||||
headers={"Authorization": f"Bearer {token}"},
|
headers=headers,
|
||||||
)
|
)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
|
|||||||
Reference in New Issue
Block a user