Access issue in Confluence On premise REST API end point
Asked by Thomas Ladefoged:

We are trying to invoke the Confluence REST API on-premise end point and it looks like it is not sufficient to provide only user id and password to get the content. When we provide a JSESSIONID cookie in the REST API end point as HTTP header then only we get the data.

The question is what could be the reason that we are not able to use userid and password combination as mentioned in the documentation ([https://developer.atlassian.com/server/confluence/confluence-rest-api-examples/](https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.com%2Fv3%2F__https%3A%2F%2Feur02.safelinks.protection.outlook.com%2F%3Furl%3Dhttps*3A*2F*2Furldefense.com*2Fv3*2F__https*3A*2F*2Fdeveloper.atlassian.com*2Fserver*2Fconfluence*2Fconfluence-rest-api-examples*2F__*3B!!GNpmbAs!To9qxPCD1I07PbMRIJZPLt6qF4tEfpRyotAsKB7KSpkpIUoP7bmyaBdypvU*24%26data%3D04*7C01*7C*7C823ec5e5b2af4e56618608d86c3fb1f9*7Ce8dcf6e63acc4af99cb277f688cb688b*7C0*7C0*7C637378368117896203*7CUnknown*7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0*3D*7C1000%26sdata%3Dq*2BRGCKU9MYhpjXkmFXEAaQAWj8R09xDpTntStv*2B6RLs*3D%26reserved%3D0__%3BJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJQ!!GNpmbAs!T0rOp3ZeQT_0cE8t5QVMWAjVng91PBIqbQny8BbZc0kTwlSlnehDAEJt7tY%24&data=04%7C01%7C%7Ce2a5462bca5f4271567608d87062a96d%7Ce8dcf6e63acc4af99cb277f688cb688b%7C0%7C0%7C637382916354641662%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=22GXNw5Bl%2FQ%2BahGA9gneqK4M4GGwL4y%2FuDXtAmYzz4s%3D&reserved=0) ) in consuming REST API from confluence on-premise solution.

For example -

The below command is not giving any data

curl -u \<userid\>:\<password\> -X GET "[https://](https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.com%2Fv3%2F__https%3A%2F%2Feur02.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%3A*2F*2Fwiki.tdc.dk*2Frest*2Fapi*2Fspace*3FspaceKey*3D*m42713%26data%3D04*7C01*7C*7C823ec5e5b2af4e56618608d86c3fb1f9*7Ce8dcf6e63acc4af99cb277f688cb688b*7C0*7C0*7C637378368117896203*7CUnknown*7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0*3D*7C1000%26sdata%3DAlWanxdV25ERMkYUSoiLa5Il6C2enqIvO2y8M804HDA*3D%26reserved%3D0__%3BJSUlJSUlJX4lJSUlJSUlJSUlJSU!!GNpmbAs!T0rOp3ZeQT_0cE8t5QVMWAjVng91PBIqbQny8BbZc0kTwlSlnehDZ1N9wVg%24&data=04%7C01%7C%7Ce2a5462bca5f4271567608d87062a96d%7Ce8dcf6e63acc4af99cb277f688cb688b%7C0%7C0%7C637382916354651617%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=bCq3lBRHYDU8Fx350OjjIIelO%2BMcUl2FeaW%2BaxJseuk%3D&reserved=0)[wiki.xxx.dk/rest/api/space?spaceKey=\~userid](https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.com%2Fv3%2F__https%3A%2F%2Feur02.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%3A*2F*2Fwiki.tdc.dk*2Frest*2Fapi*2Fspace*3FspaceKey*3D*m42713%26data%3D04*7C01*7C*7C823ec5e5b2af4e56618608d86c3fb1f9*7Ce8dcf6e63acc4af99cb277f688cb688b*7C0*7C0*7C637378368117896203*7CUnknown*7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0*3D*7C1000%26sdata%3DAlWanxdV25ERMkYUSoiLa5Il6C2enqIvO2y8M804HDA*3D%26reserved%3D0__%3BJSUlJSUlJX4lJSUlJSUlJSUlJSU!!GNpmbAs!T0rOp3ZeQT_0cE8t5QVMWAjVng91PBIqbQny8BbZc0kTwlSlnehDZ1N9wVg%24&data=04%7C01%7C%7Ce2a5462bca5f4271567608d87062a96d%7Ce8dcf6e63acc4af99cb277f688cb688b%7C0%7C0%7C637382916354651617%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=bCq3lBRHYDU8Fx350OjjIIelO%2BMcUl2FeaW%2BaxJseuk%3D&reserved=0)"

The below command provides us data.

curl -u m42713:xxxxxx --header 'Cookie: JSESSIONID=9DZZZZZZZZZZZZZZCCCCCCCCC1' \\

-X GET "[https://wiki.xxx.dk/rest/api/space?spaceKey=\~userid](https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.com%2Fv3%2F__https%3A%2F%2Feur02.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%3A*2F*2Fwiki.tdc.dk*2Frest*2Fapi*2Fspace*3FspaceKey*3D*m42713%26data%3D04*7C01*7C*7C823ec5e5b2af4e56618608d86c3fb1f9*7Ce8dcf6e63acc4af99cb277f688cb688b*7C0*7C0*7C637378368117916192*7CUnknown*7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0*3D*7C1000%26sdata%3DGDjVm2cUZoneP5*2Byx4w4D*2BrX6Wv7T*2FIeDQQbkNZ8Srs*3D%26reserved%3D0__%3BJSUlJSUlJX4lJSUlJSUlJSUlJSUlJSU!!GNpmbAs!T0rOp3ZeQT_0cE8t5QVMWAjVng91PBIqbQny8BbZc0kTwlSlnehD4x6fCtM%24&data=04%7C01%7C%7Ce2a5462bca5f4271567608d87062a96d%7Ce8dcf6e63acc4af99cb277f688cb688b%7C0%7C0%7C637382916354671532%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=zcWo%2Bqz239naGEHQJThEkIHntdEHviFfRJIJ2kRP9DI%3D&reserved=0)"


Answers:
author: Diego
body: Hello [@Thomas Ladefoged](/t5/user/viewprofilepage/user-id/3941819) !

As I understand, you are currently trying to authenticate using basic authentication in Confluence On-Premises (Server/Data Center) but is unable to.

I am not entirely sure what is the meaning of "The below command is not giving any data". Does it mean that:
> 1. *Are errors thrown when you try to authenticate?*
> 2. *Has this worked at some point?*
> 3. *Do you have some kind of SSO implemented on your instance?*
> 4. *Are you using userID or username to try and login to the instance?*
> 5. *Are there entries on your Confluence log file for when you try to login?*

Also, here we have some documentation that can help you on this setup:
> * [++***\[Confluence Server Developer\] Authentication and authorization for developers***++](https://developer.atlassian.com/developer-guide/auth/)
> * [++***\[Confluence Server Developer\] Using the REST APIs - prototype only***++](https://developer.atlassian.com/server/confluence/using-the-rest-apis-prototype-only/)

Let us hear from you!

comments: author: Gunnarsson Johan _2_
body: I had a similar problem with authentication REST APIs towards Confluence after Atlassian deprecated the user+pwd authentication June 2023. When I had to switch to using a Personal Access Token, I read everywhere I should be using "Authorization: Basic " + Encoded user name + ": " + PAT, but that's only for Cloud deployments, for on-premise installations I had to use "Authorization: Basic " + Encoded PAT-token.

Details are explained here: <https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html>.

So properly documented in the end, just I went by everyone else's solutions posted on in Atlassian chats. All in all - the documentation is correct, but perhaps a bit vague.


Tags: cloud

confluence-cloud