如何使用他们的REST API来创建新的Confluence的页面? [英] How to create new page in Confluence using their REST API?

查看:3899
本文介绍了如何使用他们的REST API来创建新的Confluence的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用REST API在融合创造新的维基页面的工作示例。我preFER根据特定的空间和特定的页面来创建新的一页。我看了他们的API文档,看着他们过去和现在未来短几个例子。

I need working example of creating new wiki page in confluence using rest api. I prefer the new page to be created under specific space and specific page. I read their api documentation and looked at few examples they had and still coming short.

下面是他们不得不在其网站上的例子。

Here is an example they had on their site

curl -u admin:admin -X POST -H 'Content-Type: application/json' -d'{"type":"page","title":"new page","space":{"key":"TST"},"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}}' http://localhost:8080/confluence/rest/api/content/ | python -mjson.tool

我和我的空间名称,新的标题上面尝试,改变了网址的mysite / REST / API /内容
和返回的内容基本上是html页面话说页面不存在或页面存在,但您没有权限。我已经证实,我曾访问维基汇合,并可以使用我的凭据创建新的维基。

I tried above with my space name, new title and changed the url to mysite/rest/api/content and returned content was basically html page saying the page does not exist or the page exists but you do not have permission. I have confirmed that I have access to confluence wiki and can create new wiki using my credentials.

什么也看不清是在它上面是怎么调用创建该页面的特定API的例子吗?它没有意义。

What is also not clear is in the example above how is it calling the specific api that creates the page? It does not make sense.

类似的问题,有人问他们的论坛,但没有合理的答案
<一href=\"https://answers.atlassian.com/questions/149561/simple-confluence-rest-api-usage-what-am-i-missing\">https://answers.atlassian.com/questions/149561/simple-confluence-rest-api-usage-what-am-i-missing

similar question was asked on their forum, but no reasonable answer https://answers.atlassian.com/questions/149561/simple-confluence-rest-api-usage-what-am-i-missing

(我想我的最终目标是能够在汇合自动创建新的wiki页面)我没关系,如果有必要的汇合REST API放弃其他的解决方案。

(I guess my end goal is to be able to create new wiki page on confluence automatically) I am okay to give up on confluence REST API to other solution if necessary.

推荐答案

我怀疑是不使用汇流的新版本不够。创建新页面的REST API的合流5.5(就是出17天以前)进行了介绍。 API文档的版本,并且你应该总是使用相应的汇流发行的版本。该 5.5 API文档包括你需要页面创建API,但旧版本没有。您可以在上面的网址更改版本,以获得API版本匹配您的合流发布。

My suspicion is that you are not using a new-enough version of Confluence. The REST API for creating a new page was introduced in Confluence 5.5 (which came out 8 days ago). The API documentation is versioned, and you should always use the version corresponding to your Confluence release. The 5.5 API docs include the page creation API you need, but older versions do not. You can change the version in the above URL to get the API version matching your Confluence release.

合流5.4及以前也采用了不同的根preFIX的REST API(/ REST / 原型/ 1 /内容),这是一个可能的原因是越来越找不到错误的页面。

Confluence 5.4 and prior also used a different root prefix for the REST API (/rest/prototype/1/content) which is one possible reason for getting a page not found error.

在Atlassian的网站的例子也令人困惑,因为它包含在URL中,这要是合流分别设置了一个上下文路径,你只需要一个额外的/合流。这也可能会导致未找到页面错误,如果你是使用汇流5.5+(虽然你的帖子表明,你已经纠正了这一点)。

The example on the Atlassian site is also confusing because it includes an extra "/confluence" in the URL, which you would only need if Confluence were set up with a context path. This could also result in a page not found error if you were using Confluence 5.5+ (although your post suggests that you already corrected for this).

此外,你需要告诉您正在使用基本身份验证方法通过<汇合href=\"https://developer.atlassian.com/display/CONFDEV/Using+the+REST+APIs+-+Prototype+Only#UsingtheRESTAPIs-PrototypeOnly-RESTAuthentication\">adding一个特殊的os_authType查询参数。

Additionally, you need to tell Confluence that you are using the basic authentication method by adding a special os_authType query parameter.

下面的例子为我工作的合流5.5(不要忘记改变端口和空格键如适用)。

The following example works for me on Confluence 5.5 (don't forget to change the port and space key as appropriate).

为了安全起见,我还添加了相应的内容类型的接受头,虽然这似乎是在实践中没有必要的。

For safety, I also added the appropriate content type to the Accept header, although this seems to be not needed in practice.

curl -v -u admin:admin -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -d'{"type":"page","title":"new page","space":{"key":"ATTACH"},"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}}' "http://localhost:8090/rest/api/content/?os_authType=basic"

要回答你的最后一个问题,创建由URL本身和请求的方法来确定网页的特定的API。例如,在/ REST / API /内容执行GET将获取现有页面(给予相应的查询参数),同时进行后会创建一个新的页面。

To answer your last question, the specific API that creates the page is determined by the URL itself and the request method. For example, performing a GET on "/rest/api/content" will fetch an existing page (given the appropriate query parameters), while performing a POST will create a new page.

编辑补充:

又见我的评论下面如何创建一个页面,另一个现有页面的一个孩子,而不是仅仅在空间的顶层。

See also my comment below for how to create a page as a child of another existing page, as opposed to just at the top level of a space.

这篇关于如何使用他们的REST API来创建新的Confluence的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆