python - Confluence:如何在创建博客文章时传递发布日期?

标签 python confluence confluence-rest-api

我正在尝试将 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/

相关文章:

Apache 作为具有子域的 Tomcat 的代理

google-chrome-extension - 使用 Chrome 内容脚本以编程方式将代码插入 Confluence 页面

python - 如何使用 Python 下载 Confluence 页面附件?

oauth-2.0 - Azure : Access to https://login. microsoftonline.com/{tenant-id}/saml2 与不记名 token

confluence - 如何通过复制现有页面并使用 REST API 在 Confluence 中创建子页面

python - 使用 python json.loads 解析 unicode 输入

python - 自动化无聊的东西 - 图像站点下载器

python - 寻找一种将矩形拟合到轮廓点的方法

python - 在 Python 中逐项列出大型 xml 文件