I am trying to create a new page using the API and python from terminal but so far nothing has been working. I tried this first:
import requests
import json
from requests.auth import HTTPBasicAuth
# set auth token and get the basic auth code
auth_token = "token"
basic_auth = HTTPBasicAuth('user', auth_token)
# Set the title and content of the page to create
page_title = 'My New Page pls work'
page_html = '<p>This page was created with Python!</p>'
parent_page_id = parent_id
space_key = 'space_key'
# get the confluence home page url for your organization {confluence_home_page}
url = 'https://company.atlassian.net/rest/api/content/'
# Request Headers
headers = {
'Content-Type': 'application/json;charset=iso-8859-1',
}
# Request body
data = {
'type': 'page',
'title': page_title,
'ancestors': [{'id':parent_page_id}],
'space': {'key':space_key},
'body': {
'storage':{
'value': page_html,
'representation':'storage',
}
}
}
# We're ready to call the api
try:
r = requests.post(url=url, data=json.dumps(data), headers=headers, auth=basic_auth)
# Consider any status other than 2xx an error
if not r.status_code // 100 == 2:
print("Error: Unexpected response {}".format(r))
else:
print('Page Created!')
except requests.exceptions.RequestException as e:
# A serious problem happened, like an SSLError or InvalidURL
print("Error: {}".format(e))
It would say page created but no page was created when I checked.