0

我正在尝试在 Confluence REST API Python 站点上运行该示例,以向 wiki 页面添加评论。在 parentPage 工作之前的所有内容(例如,它从我们的 Intranet wiki 获取正确的页面),但是当我运行 requests.post 时,它实际上并没有向找到的页面添加评论。取而代之的是 printResponse(r),打印出 wiki 中的所有页面(不是我找到的页面)。

我有以下脚本:

    #!/usr/bin/python
import requests, json
base_url = 'http://intranet.company.com/rest/api/content'
username = 'username'
password = 'password'
def printResponse(r):
    print '{} {}\n'.format(json.dumps(r.json(), sort_keys=True, indent=4, separators=(',', ': ')), r)
r = requests.get(base_url,
    params={'title' : 'Space M Homepage'},
    auth=(username, password))
printResponse(r)
parentPage = r.json()['results'][0]
pageData = {'type':'comment', 'container':parentPage, 
    'body':{'storage':{'value':"<p>New comment!</p>",'representation':'storage'}}}
r = requests.post(base_url,
    data=json.dumps(pageData),
    auth=(username,password),
    headers=({'Content-Type':'application/json'}))
printResponse(r)
4

1 回答 1

1

我在这里找到了解决方案:你如何使用他们的 REST api 向 Atlassian confluence 发表评论?. 你基本上需要扩展你的container标签。Confluence 文档根本没有提到这一点。:(

pageData = {'type':'comment', 
    'container':{'id': str(parentPage), 
        'type':'page', 
        'status': 'current'
    }, 
    'body':{
        'storage':{
            'value':"<p>New comment!</p>", 
            'representation':'storage'
        }
    }
}
于 2017-05-26T18:02:21.213 回答