Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,362,517
Community Members
 
Community Events
168
Community Groups

Create a New/Child Confluence page using Python API

I am Trying to Create a page in Confluence using Python.

This is the code I am using.

-----------------------------------------------

from atlassian import Confluence
import logging

conf = Confluence(
url='Path_url',
token="PERSONAL_ACCESS_TOKEN"
)
content1 = conf.get_page_by_title(space='SPACE', title='PARENT_PAGE_TITLE', expand="body.storage")

parent_id=conf.get_page_id('SPACE', 'Release PARENT_PAGE_TITLE')
SPAC = conf.get_page_space(parent_id)


status = conf.create_page(

space = SPAC,
title='This is the title',
parent_id=parent_id,
body='This is the body. You can use <strong>HTML tags</strong>!')
print(status)

-----------------------------------------------------------

But, I get an error:

 

raise HTTPError(error_msg, response=response)
requests.exceptions.HTTPError: Could not create content with type page

 

 

1 answer

1 accepted

0 votes
Answer accepted

@sriharsha 

 

I think you are using the wrong api function. Getting data from Confluence using the python api require to use this function

conf = Confluence(
url='http://localhost:8090',
username='admin',
password='admin')

https://pypi.org/project/atlassian-python-api/

 

You seem to use the wrong python api module.

I am able to get the data using this method, I mentioned.

And there is no issues with authentication as well.

I have no issues while I try to GET the Information.

I have issues while I try to POST /Create NEW_PAGE.

Does the user who create the page have permission to create page in the SPAC space ?

Yes, I can manually create a page in Confluence with my credentials.

But, When I try to do the same using Python API/Script, there is a Issue with statuscode: 403.

When I try to GET the data, the response is [200]. 

HTTP: GET rest/api/content/153359076 -> 200

 

But when I try to POST, 

HTTP: POST rest/api/content/ -> 403

Response text -> {"statusCode":403,"data":{"authorized":false,"valid":true,"allowedInReadOnlyMode":true,"errors":[],"successful":false},"message":"Could not create content with type page","reason":"Forbidden"}

You managed to get the page using the api but is your space open to anonymous users ?

 

Have you try with the following peace of code ? Even if your seems to work ?

 

conf = Confluence(
url='http://localhost:8090',
username='admin',
password='admin')

I am within the organization, so I am not anonymous.

 

I tried using the method you mentioned. And I have the authorization issue -> 401.

I am not able to get the access to the content with the method you mentioned. 

Thank you @Florian Bonniec  

I have come to know the issue. 

I am not in the Administrator's list.

Hence I was not authorized.

Thanks for the Help and Guidance.

Suggest an answer

Log in or Sign up to answer