简体   繁体   English

Confluence API在Python中创建注释

[英]Confluence API to create comments in Python

I'm trying to run the example on the Confluence REST API Python site to add comments to a wiki page. 我试图在Confluence REST API Python网站上运行该示例,以将评论添加到Wiki页面。 Everything until parentPage works (as in, it gets the correct page from our intranet wiki), but when I run the requests.post, it does not actually add a comment to the page found. 直到parentPage正常为止的所有工作(例如,它从我们的Intranet Wiki获取正确的页面),但是当我运行request.post时,它实际上并未向找到的页面添加评论。 Instead printResponse(r), prints out all pages in the wiki (not the page I found). 而是printResponse(r),打印出Wiki中的所有页面(不是我找到的页面)。

I have the following script: 我有以下脚本:

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

I found the solution here: How do you post a comment to Atlassian confluence using their REST api? 我在这里找到了解决方案: 您如何使用他们的REST API对Atlassian合流发表评论? . You basically need to extend your container tag. 基本上,您需要扩展container标签。 Confluence documentation doesn't mention this at all. Confluence文档完全没有提到这一点。 :( :(

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM