AnsweredAssumed Answered

Posting reply to discussion

Question asked by delius on Apr 25, 2015

I have successfully integrated some Alfresco Discussions into a Wordpress site. I can see the discussions themselves and the replies by using Curl and these functions:

GET /alfresco/s/api/forum/site/{site-name}//posts (for discussions)
GET /alfresco/s/api/forum/post/site/{site-name}//$post_id/replies (for replies)

However, now I am trying to add a POST function for adding an reply to the Alfresco discussion from Wordpress.
This is my code:

$url    = "http://{server}/alfresco/s/api/forum/post/node/workspace/SpacesStore/b99f269e-685d-428f-8872-166353484739/replies";
// SpacesStore/b99f269e-685d-428f-8872-166353484739 is the node of the discussion I like to add the response to
$postfields = array(
   'title'    =>'my Title',
   'content'   => 'my Response'
$json_fields   =      json_encode($postfields);
$curl       =       curl_init();
curl_setopt         ($curl, CURLOPT_URL, $url);
curl_setopt         ($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt         ($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt         ($curl, CURLOPT_POST, 1);
curl_setopt         ($curl, CURLOPT_POSTFIELDS, $jsonfields);
$return    =       curl_exec($curl);   

if($errno = curl_errno($return)) {
       $error_message = curl_strerror($errno);
       echo "cURL error ({$errno}):\n {$error_message}";

curl_close                  ($curl);


Does anyone have any idea how to make this work? I have tried several options, none seem to do the job. Mostly errors 500 are returned.

Thanks in advance
Delius Pit – The Netherlands

Solved this one. PHP json_encode and alfresco webservices don't always get along I discovered.  So after creating a json message manually it works.