require_once 'vendor/autoload.php';
Unirest\Request::auth('xxx', 'xxx');
$headers = array( 'Accept' => 'application/json', 'Content-Type' => 'application/json' );
$body = '
{
"id": "1234",
"title": "new apge",
"type": "page",
"space": {
"key": "page"
},
"status": "current",
"ancestors": [
{
"id": "page"
}
],
"body": {
"view": {
"value": "22",
"representation": "view"
},
"export_view": {
"value": "23",
"representation": "view"
},
"styled_view": {
"value": "24",
"representation": "view"
},
"storage": {
"value": "25",
"representation": "view"
},
"editor2": {
"value": "26",
"representation": "view"
},
"anonymous_export_view": {
"value": "27",
"representation": "view"
}
}
}
';
$response = Unirest\Request::post( 'http://localhost:8090/confluence/rest/api/content', $headers, $body );
var_dump($response);
above is my code and i am getting header of the confluence in return in broken html format
I want actual response which mentioned in confluence documentation so that I can implement further operations.
reply me as soon as possible
TIA
Hi @Vidya Shevale this is the code you need to use in PHP (simple HTTPRequest, no Unirest) to call Confluence with the POST Content operation as you specified:
<?php
$request = new HttpRequest();
$request->setUrl('http://confluenceURL/rest/api/content');
$request->setMethod(HTTP_METH_POST);$request->setHeaders(array(
'cache-control' => 'no-cache',
'Content-Type' => 'application/json'
));$request->setBody('{
"id": "1234",
"title": "new page",
"type": "page",
"space": {
"key": "page"
},
"status": "current",
"ancestors": [
{
"id": "page"
}
],
"body": {
"view": {
"value": "22",
"representation": "view"
},
"export_view": {
"value": "23",
"representation": "view"
},
"styled_view": {
"value": "24",
"representation": "view"
},
"storage": {
"value": "25",
"representation": "view"
},
"editor2": {
"value": "26",
"representation": "view"
},
"anonymous_export_view": {
"value": "27",
"representation": "view"
}
}
}');try {
$response = $request->send();echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
Be aware that you need to specify the right body format to create content, everything is detailed here: https://docs.atlassian.com/ConfluenceServer/rest/6.12.0/#content-createContent
Kind regards,
David
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.