使用API在HCL Connections中创建wiki页面。

问题描述 投票:0回答:1

使用Tampermonkey,我想在HCL Connections 6.6的现有wiki中创建一个wiki页面。根据文件我建立了这个函数。

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

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

为什么官方的例子不能用?

xml api wiki tampermonkey ibm-connections
1个回答
0
投票

我发现在正文中需要一些额外的数据(主要是使用 CDATA而这并没有记录在案。下面的条目给了我正确的提示。https:/andydunkel.net20170830use-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)
  }
© www.soinside.com 2019 - 2024. All rights reserved.