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

8 answers

This widget could not be displayed.

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

This widget could not be displayed.

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.

This widget could not be displayed.

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

This widget could not be displayed.

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

This widget could not be displayed.

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

This widget could not be displayed.

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?

 

This widget could not be displayed.
Gregory L I'm New Here Jul 04, 2018

same here

This widget could not be displayed.

This is happening fo me as well.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Tuesday in Confluence

Add-on evaluation with confluence templates

Atlassian market place contains number of Apps/Addons which improves the capability of out of the box Atlassian products. It is good to follow a plugin evaluation process before install add-ons. So t...

101 views 12 6
Read article

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