It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

PUT Method not allowed, POST works, but I need to update an existing page not create one

Vidya Shevale Jan 07, 2019

I am running PHP script in tomcat to update page content in confluence REST API

$requestStorage = array(
"id" => $parentID,
"type" => "page",
"title" => $title,
"space" => array(
"key" => $workspaceKey
"body" => array(
"storage" => array(
"value" => "".$contentName."",
"representation" => "storage"
"version" => array(
"number"=> $version

$qbodyChild = json_encode($requestStorage);
$CURLOPT_URL= $GLOBALS['host'] ."rest/api/content/".$parentID ;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $CURLOPT_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $qbodyChild);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

$headers = array();
$headers[] = "Accept : application/json";
$headers[] = "Content-Type: application/json";
$headers[] = "Authorization: Basic ".base64_encode($GLOBALS['username'].":".$GLOBALS['password']);
$headers[] = "Cache-Control: no-cache";
$headers[] = "Content-length:".strlen($requestStorage);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch); die;
curl_close ($ch);die;


I also tried adding  "ancestors" => array(
"id" => $parentID


also work

curl -u admin:Abc@1234 -X PUT -H 'Content-Type: application/json' --data '{"id":"983786","type":"page","title":"title","body":{"storage":{"value":"<p>testNum</p>","representation":"storage"}},"version":{"number":2}}' http://localhost:8090/rest/api/content/983786


please help me ASAP


1 answer

0 votes
Stephen Sifers Atlassian Team Jan 08, 2019

Hello Vidya and welcome to the Community!

What is the error/response you’re receiving when you attempt the PUT method on /rest/api/content/{contentId}?

There should be either a 400 or 404 thrown if the PUT method is not successful. From the response, we should be able to see why it is failing.

Common causes of content updates (PUT) failing are;

  • Due to the version already being used or version is incorrect
  • The account used does not have edit rights to the page. (Check your page restrictions)
  • Malformed JSON data

Once we have an response it should give us further context as to the failure.

Stephen Sifers

Vidya Shevale Jan 08, 2019 • edited

Hello Stephen,

Thanks for your reply.

I am getting below response

HTTP Status 405 - Method Not Allowed

type Status report

message Method Not Allowed

description The specified HTTP method is not allowed for the requested resource.

Apache Tomcat/8.0.43

Working fine with curl request

curl -u admin:Abc@1234 -X PUT -H 'Content-Type: application/json' -d '{"id":"1378215","type":"page",
"title":"title","space":{"key":"NEOS"},"body":{"storage":{"value":"<p>This is the updated text for the new page</p>","representation":"storage"}},"version":{"number":5}}' http://localhost:8090/rest/api/content/1378215

also working in postman below is my request




Authorization:Basic YWRtaW46QWJjQDEyMzQ=

"id": "1378215",
"type": "page",
"title": "title",
"space": {
"key": "NEOS"
"body": {
"storage": {
"value": "<p>This is the updated text for the new page</p>",
"representation": "storage"
"version": {
"number": 5


Below is my  php code generated from postman, Which is working in XAMPP/WAMP server but not working with  tomcat server , all API's are working fine in tomcat server except this.

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_PORT => "8090",
CURLOPT_URL => "http://localhost:8090/rest/api/content/1378215",
CURLOPT_POSTFIELDS => "{\"id\":\"1378215\",\"type\":\"page\",\"title\":\"title\",\"space\":{\"key\":\"NEOS\"},\"body\":{\"storage\":{\"value\":\"<p>This is the updated text vid the new pageee</p>\",\"representation\":\"storage\"}},\"version\":{\"number\":5}}",
"authorization: Basic YWRtaW46QWJjQDEyMzQ=",
"cache-control: no-cache",
"content-type: application/json",

$response = curl_exec($curl);
$err = curl_error($curl);


if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;


Please suggest me any solution , I am stick here....


Stephen Sifers Atlassian Team Jan 09, 2019

Hello again Vidya,

Are you attempting to run this PHP file within Confluence or are you using a separate instance of apache tomcat? If you’re running this within Confluence, please ensure you review the following: How to use PHP inside Confluence pages.

I did confirm your PHP does work in XAMMP and confirmed the JSON payload is good. So there should not be an issue with the JSON payload, URL or authentication. Your error is stating the PUT method is not allowed, when in fact it is allowed as you and I have both verified. With this said, something is causing the method to be changed or not present during the API request.

In order to test further on this end, I need to understand how you’re accessing this PHP file and from which tomcat instance you’re using. From there we can figure out why the method is not allowed.

Stephen Sifers

Vidya Shevale Jan 09, 2019

Hello Stephen,

Please check above URL,&nbsp;
As per above URL I have created a blog folder in webapps folder .
Created script.php in it and accessing&nbsp; below URL in browser


Stephen Sifers Atlassian Team Jan 09, 2019

Hello again Vidya,

I went through your document and I have the PHP file running as you specified.

When I tested the PHP file, I am noticing the CURL option for request is set to PUT however, it is being ignored and POST is being instead. This would explain why your getting the 405 response. This seems to possibly be an issue with how Quercus is rendering the PHP itself (to include the variable for $curl). This would also explain why it works in XAMMP but not within Quercus within Tomcat.

To see which method is being used, simply add the following after the curl variable:

echo $curl;

The should present an output similar to:

CurlResource[POST http://localhost:8090/rest/api/content/2588691]

The PHP format you have may not be compatible with Quercus and may need to be changed. I found a another method to using PUT requests in PHP:

Stephen Sifers

Vidya Shevale Jan 10, 2019 • edited

Hello Stephen,

I Implemented script as per above URL 

$url = 'http://localhost:8090/rest/api/content/1378215';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PUT, true);
$data = http_build_query([

"id" => 1378215,
"type" => "page",
"title" => 'title',
"space" => [
"key" => 'NEOS'
"body" => [
"storage" => [
"value" => "This is the updated text WE",
"representation" => "storage"
"version" =>[
"number"=> 13

$tmpfile = '/opt/atlassian/confluence/webapps/blog/WEB-INF/tmp/test.txt';
file_put_contents($tmpfile, $data);
curl_setopt($ch, CURLOPT_INFILE, $tmpfile);
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($data));
$response = curl_exec($ch);
echo 'Status-Code: ' . curl_getinfo($ch, CURLINFO_HTTP_CODE);
$headers = array();
$headers[] = "Content-Type: application/json;";
$headers[] = "Content-Length:".sizeof($tmpfile);
$headers[] = "Authorization: Basic ".base64_encode($GLOBALS['username'].":".$GLOBALS['password']);
$headers[] = "Cache-Control: no-cache";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
echo '<pre>';print_r(json_decode($response, true));echo'</pre>';




HTTP Status 500 -

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Confluence

6 Awesome Ways to Apply Trello, JIRA and Confluence to your Project

I attended  Atlassian Summit 2019  and learned a lot from the presenters, attendees and knowledgeable Atlassian product managers. The presentations I attended focused on applying Agile, pla...

903 views 6 17
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you