I want to read content from my organization a confluence page using REST api through python

shantanu kumar
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!
February 5, 2021

my code looks like this:

import requests
from requests.auth import HTTPBasicAuth
contentApiUrl = '/rest/api/content'
# Change these based on your instance
confluenceBaseUrl = 'https://confluence.abc......'
pageId = '26586726'
username = '****'
password = '*****'

requestUrl = '{confluenceBaseUrl}{contentApiUrl}/{pageId}/?expand=body.storage'.format(confluenceBaseUrl = confluenceBaseUrl, contentApiUrl = contentApiUrl, pageId = pageId)
print (requestUrl)

requestResponse = requests.get(requestUrl, auth=HTTPBasicAuth(username, password))
print(requestResponse)
print(requestResponse.content)

 output:

<Response [404]>
b'{"statusCode":404,"data":{"authorized":false,"valid":true,"allowedInReadOnlyMode":true,"errors":[],"successful":false},"message":"No content found wit
h id: ContentId{id=26586726}","reason":"Not Found"}'

The pageId , userid and password is correct.

but the catch is when i hit the url mentioned in requestUrl through browser it return the JSON but when i call the url through it gives 404 error. 

1 answer

0 votes
Edwin Kyalangalilwa
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 5, 2021

Hi @shantanu kumar ,

Please confirm that you have access to the page. The documentation states:

STATUS 404 - Returned if there is no content with the given id, or if the calling user does not have permission to view the content.

shantanu kumar
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!
February 7, 2021

@Edwin Kyalangalilwa yes, I can access the confluence page through browser.   

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events