Why does Confluence REST API return html

Hi!

I am trying to test out the REST API provided by confluence. We are running confluence  version 5.5.6. (which is supposed to provide a REST API)

When I try to create a new page using curl, as described in this example https://developer.atlassian.com/confdev/confluence-server-rest-api/confluence-rest-api-examples

(see the "Create a new page" header) I get an http 200 code, along with the  the front page of our confluence site returned in html, and no new page is created in confluence

When I try to  "Find a page by title and space key"

I also get a standard confluence html page with containing the errormessage. "The page you were trying to reach could not be found."  (even though I'm pretty sure the title and space key is accurate), along with the 404 message

According to the documentation https://developer.atlassian.com/confdev/confluence-server-rest-api/confluence-rest-api-examples

I expected the response to be json structured (even when error codes are returned)

Remote API's are enable in the config, althought it only specifies XML-RPC & SOAP, not REST.

Any ideas to what I am doing wrong? to have html returned rather than JSON.

And why does my requests fail(is it related to the response format problem) ?

 

Thanks

 

Tor

6 answers

0 vote

It often means you have not logged in, or it's not recognised the user credentials you've given it.

Well. I tried using an invalid username/password combination when attempting to post a new page.

It resulted in an explicit http 401 error message , along with a html  message body.

So it does not seem to be an issue with using the  username and password which is supposed to work (which I can log into confluence with using a browser)....

Ok, I'm not sure. 

I get the login page when I'm trying to log in with auth data that has expired, but it's fine when I hit a valid page with the plain text user/password ("curl -D- -u admin:admin ..." type command).  I assume that's what you're doing, and I don't know why it might be returning a login page.

0 vote

Tor,

I installed a brand new instance of Confluence 5.5.6 and used the REST API example to create a new page. This worked as expected. I then used the example to find a page by name and space (to find the created page) and that also worked as expected. 

I'd really like to see the exact REST call being made, as it could explain why we aren't getting the results we expect.

Stephen Brannen

Hi!

The curl statement I've been using is :

curl -v -u admin:admin -X POST -H 'Content-Type: application/json' -d'{"type":"page","title":"Another new page 2","space":{"key":"DEMO,"body":{"storage":{"value":"<p>This is a new page created by a REST call</p>","representation":"storage"}}}' -L http://confluence/confluence/rest/api/content/ 

(I just modified username/password and the servername of our confluence instance)

I have added the -L option to follow redirects as I otherwise get no response.

 

Tor

0 vote

Tor,

The request being sent was malformed, try it with the following:

curl -v -u admin:admin -X POST -H 'Content-Type: application/json' -d'{"type":"page","title":"Another new page 2","space":{"key":"DEMO"},"body":{"storage":{"value":"&lt;p&gt;This is a new page created by a REST call&lt;/p&gt;","representation":"storage"}}}' -L http://confluence/confluence/rest/api/content/

You'll notice if you compare your request to mine, I added a "} to close out the space key tuple. I tested this against my test Confluence installation and it worked (I also noticed you don't have a port following the hostname, so I assume you are either running Confluence directly on port 80 or have some kind of redirection from 80 to the port Confluence is using).

You should receive the following response:

{"id":"622593","type":"page","title":"Another new page 2","space":{"id":491521,"key":"DEMO","name":"Test","type":"global","_links":{"self":"http://branno.local:5556/conf/rest/api/space/DEMO"},"_expandable":{"icon":"","description":"","homepage":"/rest/api/content/360452"}},"history":{"latest":true,"createdBy":{"type":"known","profilePicture":{"path":"/conf/s/en_GB/5527/d6c318572c182872608bdc1754f542eab16839cb.1/_/images/icons/profilepics/default.png","width":48,"height":48,"isDefault":true},"username":"admin","displayName":"admin"},"createdDate":"2016-12-16T15:10:15.792-0600","_links":{"self":"http://branno.local:5556/conf/rest/api/content/622593/history"},"_expandable":{"lastUpdated":""}},"version":{"by":{"type":"known","profilePicture":{"path":"/conf/s/en_GB/5527/d6c318572c182872608bdc1754f542eab16839cb.1/_/images/icons/profilepics/default.png","width":48,"height":48,"isDefault":true},"username":"admin","displayName":"admin"},"when":"2016-12-16T15:10:15.792-0600","message":"","number":1,"minorEdit":false},"ancestors":[],"container":{"id":491521,"key":"DEMO","name":"Demo","type":"global","_links":{"self":"http://branno.local:5556/conf/rest/api/space/DEMO"},"_expandable":{"icon":"","description":"","homepage":"/rest/api/content/360452"}},"body":{"storage":{"value":"&lt;p&gt;This is a new page created by a REST call&lt;/p&gt;","representation":"storage","_expandable":{"content":"/rest/api/content/622593"}},"_expandable":{"editor":"","export_view":"","view":""}},"_links":{"webui":"/display/DEMO/Another+new+page+2","tinyui":"/x/AYAJ","collection":"/rest/api/content","base":"http://branno.local:5556/conf","self":"http://branno.local:5556/conf/rest/api/content/622593"},"_expandable":{"children":"/rest/api/content/622593/child","descendants":"/rest/api/content/622593/descendant","metadata":""}}

Stephen

Stephen,

As you say my request was malformed, a "}" was missing. However using your version of the request, only substituting username/password and server fared no better. The response is still html, and as far as I can see the response is identical to the one I got when the "}" was missing.

Regarding the missing port, we are redirecting the standard url (to an https version)

 

Tor

Hi!

This issue is still unresolved sad

The current situation is that when I issue the curl statement

curl -v -u admin:admin -X POST -H 'Content-Type: application/json' -d'{"type":"page","title":"Another new page 2","space":{"key":"DEMO"},"body":{"storage":{"value":"&lt;p&gt;This is a new page created by a REST call&lt;/p&gt;","representation":"storage"}}}' -L https://confluence/confluence/rest/api/content/

 

I get a  302 message along with the following log message

"Issue another request to this URL: 'http://confluence.vps.no/confluence/rest/api/content/'
* Switch from POST to GET"

This is followed by the execution of the get , and the following log message is displayed

"Connection #1 to host confluence.vps.no left intact
* Issue another request to this URL: 'http://confluence/dashboard.action;jsessionid=933054514D00EB6A58978192640A2D29' "

 

HTTP 200 is returned by the GET along with an HTML body containing our confluence front page(more or less)

And No new confluence page has been created

I have also tried to execute the same curl (POST) statement although replacing the url with http://confluence/dashboard.action;jsessionid=933054514D00EB6A58978192640A2D29'

And HTTP 200 is returned by the POST along with the confluence front page  as an HTML body.

And no new page has been created

I know that we are redirecting http requests to confluence to https, but nothing else(to my knowledge).

Or could there be an redirection issue with the behaviour I am experiencing?

Any other ideas?

 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted yesterday in Confluence

Calling all marketing teams who use Confluence - we want to hear from you!

Hi Community! me again 🙂 If you’re a marketing team using Confluence, we want to hear your story! How did you start using Confluence? What are your use cases? What have been some of the benefits?...

107 views 3 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you