Forums

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

Rest API using personal access token returning 404 but URL is valid

StuartJames.McIntosh October 14, 2022

I've tried various ways to get this working, but although I can view the confluence_url in a browser with no issue (so the URL is valid), I'm not able to return the contents of the page in Python v3. Where am I going wrong? any obvious issues? I'm guessing the issue is authentication.

note: I use the same authentication method for Jira and have no issue.


import base64
import requests

personal_access_token = "xxxxxxxx"
organizational_url = "https://confluence.global.xxx.com/"
authorization = str(base64.b64encode(bytes(':'+personal_access_token, 'ascii')),'ascii')
headers = { 'Accept': 'application/json', 'Authorization': 'Bearer '+authorization }
confluence_url = organizational_url+'rest/api/content/123456789?expand=body.storage'
response = requests.get(url=confluence_url, headers=headers, verify=False)
print(response.status_code)
print(response.text)


response.status_code is 404,
response.text is {"statusCode":404,"data":{"authorized":false,"valid":true,"allowedInReadOnlyMode":true,"errors":[],"successful":false},"message":"No content found with id: ContentId{id=123456789}","reason":"Not Found"}

2 answers

1 accepted

0 votes
Answer accepted
StuartJames.McIntosh November 6, 2022

Solved! The issue was that I didn't need to encode the personal_access_token. Solution is to remove the line "authorization = str(base64.b64encode(bytes(':'+personal_access_token, 'ascii')),'ascii')" and replace with simply "authorization = personal_access_token"

0 votes
Fabio Racobaldo _Herzum_
Community Champion
October 15, 2022

Hi @StuartJames.McIntosh ,

are u sure that user used for authentication is able to access that page?

Fabio

StuartJames.McIntosh October 16, 2022

yes, because I can copy and paste the confluence_url to a browser and it returns the data.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events