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'}
}
}