How to read confluence page content using OAuth 2.0

I am building a custom app that allows a user to connect to Atlassian via OAuth. The signup flow works. I have a token with the scope. However, when i using token to access any page in confluence, I get the following error:

response is: <Response [401]>
Error: 401
Error details: {“code”:401,“message”:“Unauthorized; scope does not match”}

The source code is:

	cloudId = getAtlassianCloudId(access_token, 'confluence')
	print ('cloudId is: ', cloudId)

	if cloudId:
		# Call Confluence API
		headers = {
				'Authorization': f'Bearer {access_token}',
				'Accept': 'application/json'
		}
		api_url = f'https://api.atlassian.com/ex/confluence/{cloudId}/rest/api/v2/pages/{pageId}'
		print(api_url)

		response = requests.get(api_url, headers=headers)
		print('response is: ', response)

		if response.status_code != 200:					
			print(f"Error: {response.status_code}")
			print(f"Error details: {response.text}")
			return None

Any suggestions on what I should differently?

Thanks!

Hi @VermaVijay , that’s interesting, are you able to give me a traceId of one of your requests (should be the value of the atl-traceid response header)?

Hi, I just figured out the issue. I had to use ‘/wiki/api/v2/pages/{pageId}’ instead of ‘/rest/api/v2/pages/{pageId}’.

Now I get the header of page, but not the content. The body attribute of response is blank. Is this the best place for documentation.

The Confluence Cloud REST API

Thanks!

1 Like