Forums

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

curl http request returning bad/illegal format or missing URL for REST Api

Rchowdhury1
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 3, 2021

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. 

confluence server error.png

How should I securely authenticate to my company's confluence page through the terminal and eventually through my Python script?

1 answer

0 votes
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 12, 2021

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events