我想创建一个程序,定期将git repo中的更改上传到confluence。到目前为止,我得到了以下内容:-程序从git存储库收集更改-根据预定义的html模板对其进行格式化,并将其保存到文本文件中-稍后使用python将其解析为JSON对象。
问题是我以前没有使用过rest api,并且我不知道如何使用它将更改作为子页面上传到融合中的现有页面。我已经搜索了很多,但我没有找到任何适合我需要的解决方案,或者只是因为缺乏这方面的知识而无法理解它们。
发布于 2016-06-07 09:42:16
Confluences API文档可从here获取
根据您需要更新的文档,将需要以下uri来执行您的请求:
/rest/api/content/{contentId}如果您从未使用python完成过API请求,根据您使用的python版本,有几个库可用。requests、Http.client、urllib 1、2、3等。
要执行简单的身份验证请求,您很可能需要由confluence或管理员凭据提供的令牌:
请求的示例可以在developers.atlassian.com Add a comment to a page找到:
import requests, json
def printResponse(r):
print '{} {}\n'.format(json.dumps(r.json(), sort_keys=True, indent=4, separators=(',', ': ')), r)
r = requests.get('http://localhost:8080/confluence/rest/api/content',
params={'title' : 'Page title to comment on'},
auth=('admin', 'admin'))
printResponse(r)
parentPage = r.json()['results'][0]
pageData = {'type':'comment', 'container':parentPage,
'body':{'storage':{'value':"<p>A new comment</p>",'representation':'storage'}}}
r = requests.post('http://localhost:8080/confluence/rest/api/content',
data=json.dumps(pageData),
auth=('admin','admin'),
headers=({'Content-Type':'application/json'}))
printResponse(r)https://stackoverflow.com/questions/37541003
复制相似问题