Confluences REST API 文档可用here:
根据您需要更新的文档,需要以下 uri 来执行您的请求:
/rest/api/content/{contentId}
如果您从未使用 python 完成过 API 请求,那么根据您使用的 python 版本,可以使用多个库。 requests, Http.client, urllib 1,2,3 等等..
要执行一个简单的经过身份验证的请求,您很可能需要一个由 confluence 或管理员凭据提供的令牌:
可以在developers.atlassian.com 找到请求示例
向页面添加评论:
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)