Forums

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

Editing page in confluence with requests throws status code 400 error

frank yify
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 5, 2020

The code I run is as mentioned below (Few information has been changed into dummy words for company confidentiality)

I need to write a page with multiple tables 

 

import requests
import json

user = 'dummy1'
password = 'dummy6'

page_title = 'Defect_density'
page_html = '<h2>This is test</h2>'
space_id = 49584054
page_id = 3045830530
space_key = 'Eleven'
url = 'https://<company>/confluence/rest/api/content/{}'.format(page_id)


headers = {
'Accept': 'application/json',
'Content-Type': 'application/json'
}

payload = {
'id': '{}'.format(page_id),
'type': 'page',
'title': '{}'.format(page_title),
'space': {"id": '{}', "key": "{}".format(space_id, space_key)},
'body': {'storage': {'representation': 'storage', 'value': '{}'.format(page_html)}},
'version': {'number': '3', 'minorEdit': False}}

try:
r = requests.put(url=url, data=json.dumps(payload), auth=(user, password), headers=headers)

if not r.status_code != 200:
print(r.content)
print("Error: Unexpected response {}".format(r))
else:
print(r.content)
print('Task ended')

except requests.exceptions.RequestException as e:
print("Error: {}".format(e))

 

Out put goes like this :

b'{"statusCode":400,"message":"Can not construct instance of java.lang.Long from String value \'[N/A]\': not a valid Long value\\n at [Source: com.atlassian.confluence.plugins.restapi.filters.LimitingRequestFilter$1@4b0db414; line: 1, column: 257] (through reference chain: com.atlassian.confluence.api.model.content.Content[\\"space\\"]->com.atlassian.confluence.api.model.content.Space[\\"id\\"])","reason":"Bad Request"}'

 

Need assistance to fix the failure

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events