1

Using Tampermonkey, I want to create a wiki page in an existing wiki in HCL Connections 6.6. According to the documentation, I build this function:

function createWikiPage(cnxBase) {
    let wikiLabel = 'API Test Wiki'
    let url = `${cnxBase}/wikis/basic/api/wiki/${wikiLabel}/feed`
    let body = `
<entry xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Matt's Page6</title>
  <summary type="text">My test</summary>
  <content type="text">This is James's wiki page.</content>
  <category term="wikipagetag1" />
  <category term="wikipagetag2" />
  <category term="wikipagetag3" />
  <category scheme="tag:ibm.com,2006:td/type" term="page" label="page" />
</entry>
`
    let args = {
        method: "POST",
        url: url,
        data: body,
        headers: {
            "Content-Type": "application/atom+xml"
        },
        onload: function(response) {
            alert(response.status + ' ' + response.responseText);
        }
    }
    GM_xmlhttpRequest(args)
}

The wiki page with tags got created after calling createWikiPage('https://cnx-host') but without any content. Also when I edit the page in the browser and switch to html sourcecode I can't see any character in the content.

Why the official example doesn't work?

Lion
  • 16,606
  • 23
  • 86
  • 148

1 Answers1

2

I figured out that some additional data is required in the body (mainly use CDATA, which wasn't documented. The following entry gave me the right hints: https://andydunkel.net/2017/08/30/use-c-to-post-to-ibm-connections-blogs-and-wikis/

  function createWikiPage(wikiLabel, title, text) {
    let url = `${cnxBase}/wikis/basic/api/wiki/${wikiLabel}/feed`
    console.log(`Post to ${url}`)
    let body = `
      <entry xmlns="http://www.w3.org/2005/Atom">
      <category term="page" label="page" scheme="tag:ibm.com,2006:td/type"></category>
      <label xmlns="urn:ibm.com/td">${title}</label>
      <category term="etherpad" />
      <category term="notizen" />
      <category term="entwurf" />
      <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>${text}</div>]]></content>
      </entry>`
    let args = {
      method: "POST",
      url: url,
      data: body,
      headers: {
        "Content-Type": "application/atom+xml"
      },
      onload: function (response) {
        // ToDo: Return status
        alert(response.status + ' ' + response.responseText);
        console.log(response.responseText)
      }
    }
    GM_xmlhttpRequest(args)
  }
Lion
  • 16,606
  • 23
  • 86
  • 148