我正在尝试将 WordPress 博客文章迁移到 Confluence 博客空间。我正在使用 Confluence api 来发布博客。我还需要将发布日期设置为过去的某个时间(Wordpress 上的原始发布日期)。 Confluence Web-UI 提供了一个自定义发布日期的选项,但我在 API 文档中没有看到任何可以让我通过发布日期的内容。这是我的 python 脚本,它能够创建博客文章,但无需自定义“发布日期”
import requests
import json
def main():
auth = open('/tmp/confluence', 'r').readline().strip()
username = 'rakesh'
base_url = "https://<HOSTNAME>/rest/api/content/"
space_key = "LOC"
html_body = """<h1>This is h1 header</h1>
<p> this is paragraph</p>
<table> <tr> <td> data block1</td> <td> data block2</td> </tr></table>"""
data = {'type': 'blogpost',
'title': 'Blog test4',
'space': {'key': space_key},
'body': {'storage': {'value': html_body,
'representation': 'storage'}}}
response = requests.post(base_url,
auth=(username, auth),
headers={'Content-type': 'application/json'},
data=json.dumps(data))
print response.status_code, response.text
if __name__ == "__main__":
main()
这是请求 json:
{'type': 'blogpost',
'title': 'Blog test4',
'space': {'key': space_key},
'body': {'storage': {'value': '<h1>This is h1 header</h1><p> this is paragraph</p>',
'representation': 'storage'}
}
}
最佳答案
我们只是做了同样的事情。要传递发布日期,您只需在请求 json 中添加history.createdDate即可。
{
'type': 'blogpost',
'title': 'Blog test4',
'space': {
'key': space_key
},
'history': {
'createdDate': '2016-10-10T04:00:00.000Z'
},
'body': {
'storage': {
'value': '<h1>This is h1 header</h1><p> this is paragraph</p>',
'representation': 'storage'
}
}
}
关于python - Confluence:如何在创建博客文章时传递发布日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38879895/