cancel
Showing results for 
Search instead for 
Did you mean: 

update blog via rest api

brogits
Champ in-the-making
Champ in-the-making
Hello,

I am trying to update a blog on Alfresco share site via Restful API but of no success for 2 days now. I had tried to search the internet but can't find a good place to start. I even bought Alfresco developer guide book hoping to get some information on how to correctly consume Alfresco Restful API.

I have successfully retrieve the list of my blogs coming from Alresco but now that I am trying to updating a particular blog it does not even return an error.

Any body here can point me to some resources that can help me figure out my issue?

For info this is the code i have which always returns null from the call:


$bizObj->draft=false;
$data = json_encode($bizObj);
$postUrl = $webServer. "/alfresco/service/api/blog/node/$bizObj->storeType/$bizObj->storeId/$bizObj->id";
try{
   $ch=curl_init();
   curl_setopt($ch,CURLOPT_URL,$postUrl);         
   curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
   curl_setopt($ch, CURLOPT_USERPWD, "$user:$pwd");
   curl_setopt($ch,CURLOPT_POST,1);
   curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
         
   $json=json_decode(curl_exec($ch),true,512);     
   curl_close($ch);
   if($json==null){
      …..
      …..
   }else{
      …..
      …..
   }
   }catch(Exception $e){
      ….
   }

Thank you.
1 REPLY 1

jpotts
World-Class Innovator
World-Class Innovator
I don't see where you are setting the content header. It needs to be "application/json" or the web script you are posting to will never see it.

Also, not sure if curl is a requirement. If it isn't, here's a snippet that uses OpenCMIS and the OpenCMIS extension for Alfresco to create a blog post via CMIS:
Map <String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,P:cm:titled,P:cm:syndication");
properties.put(PropertyIds.NAME, filename);
properties.put("cm:description", "");
properties.put("cm:title", "test blog cmis");
GregorianCalendar calendar = new GregorianCalendar();
properties.put("cm:published", calendar);
  
byte[] content = "<p>Hello World!</p>".getBytes();
InputStream stream = new ByteArrayInputStream(content);
ContentStream contentStream = new ContentStreamImpl(filename, BigInteger.valueOf(content.length), "text/html", stream);
return folder.createDocument(
         properties,
         contentStream,
         VersioningState.MAJOR
);
Jeff