Confluence REST API call with apache mod_proxy returns 404

Christian Schlaefcke
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.
August 25, 2015

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 sad

Any hint pointing me to the right direction would be very much appreciated!

Regards,

Christian

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Christian Schlaefcke
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.
August 26, 2015

Ok  - I got it working now. Using Atlassian´s 3-legged OAuth method did the trick smile

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 smile

2 votes
Taha Khanzada
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.
August 25, 2015

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

Christian Schlaefcke
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.
August 25, 2015

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

Taha Khanzada
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.
August 25, 2015

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

Christian Schlaefcke
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.
August 25, 2015

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. ;-)

Christian Schlaefcke
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.
August 25, 2015

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

Christian Schlaefcke
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.
August 25, 2015

So - there must a problem with the proxied URL I guess :-( But I don´t understand what it might be.

Taha Khanzada
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.
August 25, 2015

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}

Christian Schlaefcke
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.
August 25, 2015

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}"}
Christian Schlaefcke
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.
August 25, 2015

And by the way - the JIRA REST API has exactly the same behaviour

Taha Khanzada
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.
August 25, 2015

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

Christian Schlaefcke
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.
August 25, 2015

sure - I already checked by performing the working examples with the same credentials ;-)

Magnus Rode May 2, 2016

Thank You Taha!

You helped us very much!

Christian Schlaefcke
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.
May 2, 2016

Magnus: If you would be more specific, you would probably help other users as well wink

Magnus Rode May 2, 2016

In our case the first post of Taha worked for reaching REST:

if not then change REST URL to 

http://my_host/rest/api/content/123456789?status=any 

0 votes
Christian Schlaefcke
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.
August 25, 2015

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.

TAGS
AUG Leaders

Atlassian Community Events