I seem to be unable to access Confluence wiki pages via API.
I followed documentation for both V2 REST API and the deprecated original API:
https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-page/#api-pages-id-get
Following V2, I get 404 response - which according to the docs can also mean I'm not allowed to access the content.
Following V1, I get 403:
{"message": "Current user not permitted to use Confluence", "statusCode": 403}
Is this because I am trying to test on a Free plan?
I have confirmed that I am using the correct numerical page ID, and I have all the necessary scopes, both granular and classic, enabled on the token I'm using, so that's not the issue.
@deniszhenilov Welcome to the Atlassian community
Can you test and make sure you can access the API call in a browser and that it works there when you are logged in?
Do you have postman so you can test the call there next and make sure it is functioning when passing the credentials?
Just tested in my browser trying both V1 and V2 url patterns, both worked.
Hm.
I am trying to use API from Python, I am very closely following the original code in documentation. Here is what my invocation attempt looks like when using V1:
api_url = f"{base_domain}/wiki/rest/api/content/{page_id}"
print(f"Final api url: {api_url}")
auth = HTTPBasicAuth(token_dict["user_email"], token_dict["access_token"])
headers = {"Accept": "application/json"}
response = requests.get(api_url, auth=auth, headers=headers)
The API url it creates for a file I used to test is https://yashas1.atlassian.net/wiki/rest/api/content/17432577, which worked when opened in the browser, but produces previously referenced error when trying via the REST request in code.
Additionally, however, what seems very strange is that the "body" field in both V1 and V2 responses when tried from browser is empty... While the page, in reality, contains a bunch of lorem ipsum content for testing:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@deniszhenilov I would suggest downloading post man to test the structure of the API call. It will help capture information that you can not always capture in certain IDEs?
I noticed that you are Printing the URL do I am assuming that is correct. From what you are sharing on both errors above the credentials are the issue. Are you able to add break points when you run the code to see what is actually being sent as credentials? What happens if you hard code those in the code will it connect?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I figured out that the issue was caused by me using wrong URL altogether it seems.
I re-checked documentation here, which is what I followed for my OAUTH flow:
https://developer.atlassian.com/cloud/confluence/oauth-2-3lo-apps/
I noticed this bit:
Note that if you are copying the examples in the API documentation, you will need to amend the example URLs as they currently use
https://your-domain.atlassian.net/{api}
rather than the request URLs shown above.
After correcting my code to query for cloudid of available resource & adjusting my url to being https://api.atlassian.com/ex/confluence/55cdafe5-6bee-418b-868b-68065ec0ddeb/wiki/api/v2/pages/17432577 everything works great.
Out of curiosity, however: what OAUTH flow should I have been using to match the documentation examples?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@deniszhenilov can you mark the answer as accepted so others can see the solution?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.