Forums

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

Create a New/Child Confluence page using Python API

sriharsha August 8, 2022

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
Florian Bonniec
Community Champion
August 8, 2022

@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.

sriharsha August 8, 2022

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.

Florian Bonniec
Community Champion
August 8, 2022

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

sriharsha August 8, 2022

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"}

Florian Bonniec
Community Champion
August 8, 2022

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')
sriharsha August 8, 2022

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. 

sriharsha August 9, 2022

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