Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Confluence API: Trying to create a new page throws a 405 error

Steve Suranie
Contributor
July 25, 2022

I'm trying to create a new page that is a child of an existing page using the Confluence API. I'm writing this in Python but not using the Confluence Python API module. I keep getting a 405 error returned and am not sure why. Here's my code: 

In towu.py: 

def addPage(pageId, strCotent):

strURL = "https://kargo1.atlassian.net/wiki/rest/api/content/" + pageId + "?expand=body.storage,version"

#get current version of page
dictResults = AppManager.makeGetCall("https://kargo1.atlassian.net/wiki/rest/api/content/" + pageId + "?expand=version")
version = int(dictResults["data"]["version"]["number"]) + 1

#page data
dictPayload = {
"type":"page",
"title":"Tech Ops Weekly Update Test",
"ancestors":[{"id":draftsId}],
"space":{"key":"KTC"},
"body":{
"storage":{
"value":"<ac:layout><ac:layout-section ac:type=\"fixed-width\" ac:breakout-mode=\"default\"><ac:layout-cell><h2>Tech Ops Incident Report Wrap Up for Week Ending: 2022-07-25</h2>",
"representation":"storage"
}
}
}

dictResults = AppManager.makePostCall(strURL, dictPayload)
print(dictResults)

 

and in my AppManager.py file: 

def makePostCall(strURL, payload):

payloadJSON = json.dumps(payload)

response = requests.request("POST", strURL, data=payloadJSON, headers=strJiraHeader)

if response.status_code == 200:
return {"success":True, "data":response.json()}
elif response.status_code > 200:
return {"success":False, "msg":"There was an error with updating your file: " + str(response.status_code) + "\n" + response.reason}
and the return from makePostCall is: 

{'success': False, 'msg': 'There was an error with updating your file: 405\nMethod Not Allowed'} 

I have permission (I'm the site admin). I know the headers work as I can make a variety of GET calls with it. I also tried a PUT call to an existing page and got a 400 error back. 

Not sure what I am doing wrong here, any help would be appreciated.  

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events