I am creating a script in python that can gather data from an atlassian confluence wiki page through an http request using the curl command. The confluence website I am trying to access is maintained by my company's server. The command I am currently using is:
curl -v -w -u admin:admin https://confluence.wdc.com/rest/api/content/494966598 | python -mjson.tool
In place of admin:admin I type my username which is my email then a colon and my password so for eg. ridwan.joshi@wdc.com:thisispassword@ai I know that the link is correct as when I click "https://confluence.wdc.com/rest/api/content/494966598" it directly takes me to the page which gets displayed in a JSON format with all the information but when I try to enter that command in the terminal I get an error saying.
How should I securely authenticate to my company's confluence page through the terminal and eventually through my Python script?
Hi,
I understand that you are using the REST API to try to extract some json data from Confluence, but that this is not working as expected here. I believe I know why this happening now.
The output of your curl by itself (without the pipe) tends to show some additional lines of output that are not really json. In this case, since you appear to be looking to format that output, we need to tell Confluence that we are wanting specific content type (json). Also using the -v switch provides a more verbose output than is usually wanted, unless you have to debug some aspect of the connection. With that in mind, try this instead:
curl -u admin:admin -H "Content-Type: application/json" https://confluence.example.com/rest/api/content/494966598 | python -mjson.tool
As for securely authenticating these REST calls, OAuth is the recommended means to do this, but it is considerably more complex to setup than a basic auth is.
An alternative to OAuth would be to use a personal access token, this is not as secure as OAuth, but is more secure than just using a password and less complex than configuring OAuth. As a side note about personal access tokens: These have only recently been made available to Server and Data Center editions of Jira (8.14 and higher) and Confluence (7.9 and higher). Atlassian Cloud has had API Tokens for quite a while longer. But in the case of using a python script, I'd suggest a personal access token if your version of Jira/Confluence supports it.
I hope this helps.
Andy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.