【问题标题】:Create wiki page in HCL Connections programatically using API使用 API 以编程方式在 HCL Connections 中创建 wiki 页面
【发布时间】:2020-05-19 08:28:19
【问题描述】:

使用 Tampermonkey,我想在 HCL Connections 6.6 中的现有 wiki 中创建一个 wiki 页面。 According to the documentation,我构建了这个函数:

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)
}

在调用createWikiPage('https://cnx-host') 后创建了带有标签的wiki 页面,但没有任何内容。此外,当我在浏览器中编辑页面并切换到 html 源代码时,我在内容中看不到任何字符。

为什么官方的例子不起作用?

【问题讨论】:

    标签: xml api wiki tampermonkey ibm-connections


    【解决方案1】:

    我发现正文中需要一些额外的数据(主要使用CDATA,没有记录。以下条目给了我正确的提示: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)
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-16
      • 1970-01-01
      • 2012-03-08
      • 2015-10-27
      • 1970-01-01
      相关资源
      最近更新 更多