Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

creating a page in confluence using the Curl PHP

Chris Johnson March 23, 2022

Hi this is my sample code to test adding a new page.

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://*******.atlassian.net/wiki/rest/api/content/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"type":"page","title":"inserttitle","space":{"key":"insertspace"},"ancestors":[{"type":"page","id":insertancestor}],"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}}');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "myemail" . ":" . "mykey");

$headers = array();
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

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


 it gives me an error:

string(316) "{"statusCode":500,"message":"org.codehaus.jackson.JsonParseException: Unexpected character ('i' (code 105)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: com.atlassian.plugins.rest.common.limitrequest.jersey.LimitingRequestFilter$1@2305a82c; line: 1, column: 102]"}"

Any ideas what the issue is?

 

Thanks

2 answers

1 accepted

0 votes
Answer accepted
Chris Johnson March 23, 2022

Ok so I have resolved this: 

 insertspace

is not the name of a space on my instance of Confluence.

I changed it to a valid space name and it worked.

 

Thanks

0 votes
Chris Johnson March 23, 2022

I also made the ancestors into an empty array.

 

Thanks

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events