Forums

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

Confluence Rest API for authentication

ankita_mii March 27, 2018

I am using  https://docs.atlassian.com/ConfluenceServer/rest/6.8.0/ documentation for Creating a Space and writing the content into it. But i am facing authentication issue. If i put GET API in browser and login into confluence then Getting correct Response. 

 

But Same thing is not achieving by sending request from Postman/CURL. It is always returning 403 in response. because the documentation don't have an API for authentication. How i can achieve this?

1 answer

0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 27, 2018

Kindly have a look at the KB below:

https://developer.atlassian.com/cloud/confluence/basic-auth-for-rest-apis/

It is written there how to provide values for basic authenticaion.

ankita_mii March 27, 2018

Hi Alex,

Thanks for quick response. I am using my local confluence which is deploy on our local server. how i can generate token for confluence?

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 27, 2018

If you execute by curl then it must be like this

curl -D- \
   -X GET \
   -H "Authorization: Basic dXNlcjp1c2Vy" \
   -H "Content-Type: application/json" \
   "https://your-domain.atlassian.net/rest/api/2/issue/QA-31"

The Authorization part you do like this:

  1. Supply an Authorization header with content Basic followed by the encoded string. For example, the string user:userpassword encodes to dXNlcjp1c2Vy in base64, so you would make the request as follows:
ankita_mii March 27, 2018

Hi Alex,

With reference to this document https://developer.atlassian.com/server/confluence/confluence-rest-api-examples/

curl -u myuser:mypwd -X GET "http://localip/confluence/rest/api/content?type=blogpost&start=0&limit=10&expand=space,history,body.view,metadata.labels"

this is return very basic response below

{"results":[],"start":0,"limit":10,"size":0,"_links":{"self":"http://myip/confluence/rest/api/content?expand=space,history,body.view,metadata.labels&type=blogpost","base":"http://myip/confluence","context":"/confluence"}}

 

Now same API request i am sending using browser

http://localip/confluence/rest/api/content?type=blogpost&start=0&limit=10&expand=space,history,body.view,metadata.labels 

 

this is returning detailed response of content because i am logged in confluence.

 

What is the issue in my CURL?

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 27, 2018

Try not to login to confluence in your browser and execute the rest. Have a look at the returned value.

ankita_mii March 27, 2018

If i dont login in browser it also have same response as a CURL

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 27, 2018

It means that you are not authorised to Confluence. Try to authorize like in the article, which I provided.

ankita_mii March 27, 2018

Tried this both

curl -D- \
-u username:pwd \
-X GET \
-H "Content-Type: application/json" \
http://myip/confluence/rest/api/user?username=admin


curl -D- \
-X GET \
-H "Authorization: Basic base64==" \
-H "Content-Type: application/json" \
http://myip/confluence/rest/api/user?username=admin


Getting 403

{"statusCode":403,"data":{"authorized":false,"valid":true,"errors":[],"successful":false,"notSuccessful":true},"message":"User not permitted to view user profiles"}
ankita_mii March 27, 2018
http://myip/confluence/rest/api/user?username=admin

Same URL working in browser if i login to confluence

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 27, 2018

Make sure that you put user:userpassword correctly to base64. 

ankita_mii March 27, 2018

Yes it is correct . I have encoded my user:password to base64 correctly.Still it is not working for my local confluence.

ankita_mii March 27, 2018

Is it possible something is blocking from installed server?

ankita_mii March 27, 2018

Hi Alex,

The issue is been fixed. The issue was with my ipaddress . Out local Confluence was running in ip only but api call require port too. Appending port in request URL Fixed my issue.

Thanks,

Ankita

Suggest an answer

Log in or Sign up to answer