Skip to end of metadata
Go to start of metadata

About

If you already have a wiki page you can edit it content (body) by sending a request to the wiki page feed. Here's one easy way to do it with an asynchronous HTTP (Ajax) request using jQuery. Also, I explain some important elements that are not mentioned in the official documentation.

IBM Connections 4.5 documentation:

Note

The official documentation only mention the next basic steps:
  1. Retrieve the existing wiki page Atom document. See Retrieving a wiki page for more details.
  2. Edit the wiki page Atom document to include the information you want to change.
  3. Send the updated Atom document using the following request...

But in the second step, Edit the wiki page Atom document to include the information you want to change, a lot of info is missed, as example, it doesn´t explain that if you want to update the content of a wiki page (body), in the entry atom the content inside the tag <content type="text/html"></content> MUST be inside "<![CDATA["  "]]>", example:

<content type="text/html"><![CDATA[<?xml
 version="1.0" encoding="UTF-8"?><!DOCTYPE html [<!ENTITY amp 
"&#38;#38;"><!ENTITY lt "&#60;#60;"><!ENTITY gt 
"&#62;#62;"><!ENTITY nbsp "&#160;"><!ENTITY apos 
"&#39;"><!ENTITY quot "&#34;">]> ]]></content>
</entry>

Also, Connections API returns a status code: 200 OK event if the content inside the tag <content type="text/html"></content> is NOT valid, in that case the body of wiki page will be updated empty, also, only one <div></div> tag is allowed at the top level of the body, you can´t add something like <div>Hello Word</div><div>More Content</div> in that case the <content type="text/html"></content> in the entry atom should look like:

<content type="text/html"><![CDATA[<?xml
 version="1.0" encoding="UTF-8"?><!DOCTYPE html [<!ENTITY amp 
"&#38;#38;"><!ENTITY lt "&#60;#60;"><!ENTITY gt 
"&#62;#62;"><!ENTITY nbsp "&#160;"><!ENTITY apos 
"&#39;"><!ENTITY quot "&#34;">]><div><div>Hello Word</div><div>More Content</div></div>]]></content>
</entry>
Atom API Request Details

HeaderContent-Type: application/atom+xml;type=entry;charset=UTF-8
TypePUT
URL

/basic/api/wiki/{wiki-label}/page/{page-label}/entry

  • where {wiki-label} is the value of the <td:label> element in the wiki definition Atom entry document and {page-label} is the value of the <td:label> element in the wiki page Atom document.

Example

http://www.mysite.com/wikis/basic/api/wiki/9492-2d-4a4-881-e480618/page/19de7-34-b1-98ee-fcd6ca4/entry?includeNotification=true&createVersion=true&sendNotification=false

ResponseStatus Code: 200 OK


Example of a valid entry atom


<entry xmlns="http://www.w3.org/2005/Atom">
<category term="page" label="page" scheme="tag:ibm.com,2006:td/type"></category>
<title>test</title>
<label xmlns="urn:ibm.com/td">my wiki page</label>
<visibility xmlns="urn:ibm.com/td">public</visibility>
<propagation xmlns="urn:ibm.com/td">false</propagation>
<summary>edited via API</summary>
<content type="text/html"><![CDATA[<?xml
 version="1.0" encoding="UTF-8"?><!DOCTYPE html [<!ENTITY amp 
"&#38;#38;"><!ENTITY lt "&#60;#60;"><!ENTITY gt 
"&#62;#62;"><!ENTITY nbsp "&#160;"><!ENTITY apos 
"&#39;"><!ENTITY quot "&#34;">]><div>Hello Word</div>]]></content>
</entry>
Example using jQuery

 var entry = '<entry xmlns="http://www.w3.org/2005/Atom">' +
 '<category term="page" label="page" scheme="tag:ibm.com,2006:td/type"></category>' + 
 '<title>test</title>' + 
 '<label xmlns="urn:ibm.com/td">my wiki page</label>' + 
 '<visibility xmlns="urn:ibm.com/td">public</visibility>'+
 '<propagation xmlns="urn:ibm.com/td">false</propagation>' + 
 '<summary></summary>' + 
 '<content type="text/html"><![CDATA[<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html [<!ENTITY amp "&#38;#38;"><!ENTITY lt "&#60;#60;"><!ENTITY gt "&#62;#62;"><!ENTITY nbsp "&#160;"><!ENTITY apos "&#39;"><!ENTITY quot "&#34;">]><div>Hello Word</div>]]></content>' +
 '</entry>';

 jQuery.ajax({
  url : "http://www.mysite.com/wikis/basic/api/wiki/9492-2d-4a4-881-e480618/page/19de7-34-b1-98ee-fcd6ca4/entry?includeNotification=true&createVersion=true&sendNotification=false",
  type : "PUT",
  contentType: "application/atom+xml;type=entry;charset=UTF-8",
  async : true,
  data: entry,
  statusCode : {
    200 : function() {
      console.log("done!");  
    }
  },
  error: function(jqXHR, textStatus, errorThrown) {
    console.log("error");
  }
});

Note:  console.log can throw errors in IE, they are there for illustrative purposes only and should be changed as required.

About the author

Enterprise Web Developer
Joaquin is an Enterprise Web Developer at Base22 with over seven years of experience designing and developing web solutions for enterprise clients. He is a well rounded web developer with skills building interfaces in IBM WebSphere Portal and WCM, IBM Connections, and many others. He is an Oracle Certified Java Developer and a Microsoft Certified Visual Studio Developer. He blogs at http://j-arellano.com