Hi All,
I am trying to use REST API Calls to Confluence (Data Center version), but cannot figure out how to pass basic authentication in request call.
Below is example code taken from Confluence REST API Documentation.
import requests
import json
url = "https://your-domain.atlassian.net/wiki/rest/api/content"
headers = { "Accept": "application/json" }
response = requests.request( "GET", url, headers=headers ) print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
Below is the python request module code I am using.
import requests
import json
from requests.auth import HTTPBasicAuth
auth = HTTPBasicAuth("username","password")
url = "http://confluenceurl:8090/confluence/rest/api/content"
headers = {"Accept": "application/json"}
response = requests.request("GET",url,headers=headers,auth=auth)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
But, I get 404 Response code
(404=Returned if the calling user does not have permission to view the requested content.A schema has not been defined for this response code.)
Thanks in Advance for helping and teaching.
Your headers has to be content-type.you can simply use below.
import requests
import json
from requests.auth import HTTPBasicAuth
auth = HTTPBasicAuth("username","password")
url = "http://confluenceurl:8090/confluence/rest/api/content"
headers = {"Content-type": "application/json"}
response = requests.request("GET",url,headers=headers,auth=auth)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
Hi @Prince Nyeche ,
Thank you the response, I modified header data, still same response.
>>> headers = {"Content-type": "application/json"}
>>> requests.request("GET",url,headers=headers,auth=('user','passwd'))
<Response [404]>
>>>
>>> headers = {"Content-type": "application/json"}
>>> requests.request("GET",url,headers=headers,auth=auth)
<Response [404]>
>>>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think the issue is not the authentication but most probably the endpoint being used. Is that endpoint url accessible via the browser?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, I tried below two urls.
http://jirasdconfluence.technicolor.com:8090/confluence/rest/api/content
http://jirasdconfluence.technicolor.com:8090/wiki/rest/api/content
I am using Confluence Data Center on own premises.
Page Not Found.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There's the problem. the endpoint doesn't search any space. Please use
http://jirasdconfluence.technicolor.com:8090/wiki/rest/api/content/search?cql=space=NAME_OF_A_SPACE
This is explained here on Advanced searching with CQL.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Prince Nyeche ,
I am still unable to understand, which url should i make call using REST API.
I want to fetch some data or post any data to any space/page in Confluence using REST API, but don't know how to pass user authentication.
None of the URLs are working.
I am using Confluence Data Center Version.
>>>url='http://jirasdconfluence.technicolor.com:8090/wiki/rest/api/content/search?cql=space=TECHPST'
>>> headers = {"Accept": "application/json"}
>>> requests.request("GET",url,headers=headers,auth=auth)
<Response [404]>
>>>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think you're using the directory wrong. If your confluence is not installed in any directory, it should be like
http://jirasdconfluence.technicolor.com:8090/rest/api/content/search?cql=space=TECHPST'
"wiki" -> is a directory mostly used by Cloud Infrastructure for confluence. So try the above url and see if you can get the content of that space.
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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.