Hi,
I am trying to use the Confluence REST API (Version 5.8.9) using a simple example with curl:
curl -u user:pass -X GET "http://my_host/confluence/rest/api/content/123456789?status=any"
When I call the proxied URL like above I just get this error response:
{"statusCode":404,"data":{"authorized":false,"valid":true,"errors":[]},"message":"No content found with id: ContentId{id=123456789}"}
When I make the same test using the native Confluence URL from localhost:
curl -u user:pass -X GET "http://localhost:8090/confluence/rest/api/content/123456789?status=any"
The response looks like expected:
{"id":"123456789","type":"page","status":"current","title":"Some Page","space":{"id":9876543,"key":"SOSP","name":"Some Space","type":"global","_links":{"self":"http://my_host/confluence/rest/api/space/SOSP"},"_expandable":{"icon":"","description":"","homepage":"/rest/api/content/123456789"}},"history":{"lates ...
When I open the regular proxied URL in my browser, the result also looks fine.
I think I have to tell Apache to pass the authentication to Confluence somehow but I don´t know how.
I already searched the Atlassian Developer docs, answers and google - no luck
Any hint pointing me to the right direction would be very much appreciated!
Regards,
Christian
Community moderators have prevented the ability to post new answers.
Ok - I got it working now. Using Atlassian´s 3-legged OAuth method did the trick
Especially the Atlassian OAuth Examples and the Jira Rest API Example OAuth Authentication Tutorial were very helpful.
It seems that the basic authentication is good for basic Rest API tests against plain un-proxied Atlassian tool URLs. For productive environments I would definitely recommend the OAUth way. One big advantage of OAuth over basic authentication is that it does not require any real or technical users with plain-text credentials stored insecurely in whatever scripts.
To be honest I found the OAuth way rather complicated (I would rank my technical skills as mediocre) - it took me 2 days fighting with perl and the atlassian docs - but it was worth the time
Hi Christian,
Do your confluence instance uses Context "confluence", if not then change REST URL to
http://my_host/rest/api/content/123456789?status=any instead of "http://my_host/confluence/rest/api/content/123456789?status=any"
Taha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Taha, yes - I am using the context "/confluence" and it already shows up in my example, which means I already tried what you suggest. But it is not working. Christian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are facing issue only with CURL or using other method as well. Login to Confluence and open new tab and run REST URL and check if you are getting same response or not http://my_host/confluence/rest/api/content/123456789?status=any
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did read my post carefully? I also mentioned: When I open the regular proxied (REST API) URL in my browser, the result also looks fine. ;-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Let me summarize: - Proxied REST API URL with curl => not working - Localhost REST API URL with curl => working - Proxied REST API URL in browser (logged in) => working
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So - there must a problem with the proxied URL I guess :-( But I don´t understand what it might be.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok. Run below command with -v option to get more verbose info. {code} curl -D -v -u user:pass -X GET -H "Content-Type: application/json" "http://my_host/confluence/rest/api/content/123456789?status=any"; {code}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Verbose output of the command:
* Trying ::1... * Connected to my_host (::1) port 80 (#0) * Server auth using Basic with user 'user' > GET /confluence/rest/api/content/123456789?status=any HTTP/1.1 > Authorization: Basic Y3NjaGxhZWZja2U6R3JQTjdrTW0= > User-Agent: curl/7.40.0 > Host: my_host > Accept: */* > X-my_hostsian-Token: nocheck > < HTTP/1.1 404 Not Found HTTP/1.1 404 Not Found < Date: Tue, 25 Aug 2015 18:58:20 GMT Date: Tue, 25 Aug 2015 18:58:20 GMT < Server: Apache-Coyote/1.1 Server: Apache-Coyote/1.1 < X-ASEN: SEN-2013843 X-ASEN: SEN-2013843 < X-Content-Type-Options: nosniff X-Content-Type-Options: nosniff < Content-Type: application/json Content-Type: application/json < Transfer-Encoding: chunked Transfer-Encoding: chunked < * Connection #0 to host my_host left intact {"statusCode":404,"data":{"authorized":false,"valid":true,"errors":[]},"message":"No content found with id: ContentId{id=123456789}"}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And by the way - the JIRA REST API has exactly the same behaviour
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Silly question: can you verify that your username and password are being sent correctly? If you have unusual characters in the password, ensure that they're escaped properly and/or wrapped in quotes (mainly in regard to the shell environment you're executing it). If possible can you double check with other account just to eliminate the possibility
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
sure - I already checked by performing the working examples with the same credentials ;-)
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.
Magnus: If you would be more specific, you would probably help other users as well
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In our case the first post of Taha worked for reaching REST:
if not then change REST URL to
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm - it looks like the cookie method like in JIRA (mentioned [here|https://answers.atlassian.com/questions/139869/cannot-authenticate-to-jira-5-1-8-using-restful-api-using-curl-command]) would be helpful but it does not seem to work the same in Confluence.
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.