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. firstname.lastname@example.org: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?
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.
Hello Confluence Community! What if i told you that you could have a healthier life and be 100% meet-less? This month, we're promoting a healthy, balanced work diet with Confluence. (Read m...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events