Confluence API在Python中创建注释

问题描述:

我试图在Confluence REST API Python站点上运行示例以向Wiki页面添加注释。直到parentPage工作(直到它从我们的Intranet wiki中获得正确的页面),但是当我运行requests.post时,它实际上并没有为找到的页面添加注释。而是printResponse(r),打印出wiki中的所有页面(不是我找到的页面)。Confluence API在Python中创建注释

我有以下脚本:

#!/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) 
+0

你尝试改变'数据= pageData'到'数据= json.dumps(pageData)'作为[文档】(https://developer.atlassian.com/confdev/confluence-rest- api/confluence-rest-api-examples#ConfluenceRESTAPIExamples-Addacommenttoapage(python))似乎把它作为一个字符串。 –

+0

是的,这是我以前的想法,它不会改变任何东西。 – PS376

我发现这里的解决方案:How do you post a comment to Atlassian confluence using their REST api?。你基本上需要扩展你的container标签。 Confluence文档根本没有提到这一点。 :(

pageData = {'type':'comment', 
    'container':{'id': str(parentPage), 
     'type':'page', 
     'status': 'current' 
    }, 
    'body':{ 
     'storage':{ 
      'value':"<p>New comment!</p>", 
      'representation':'storage' 
     } 
    } 
}