无法使用 curl 使用 HTML 文件中的内容更新 confluence 页面
Unable to update confluence page with content from an HTML file using curl
我正在尝试使用一些 HTML 内容更新 Confluence 页面。我在同一位置的另一个名为 Output.html
的文件中有此 HTML 内容。我无法直接将 HTML 内容复制并粘贴到此脚本,因为它是大量数据,而且我需要动态执行此脚本。
curl -u user:pass -X PUT -H 'Content-Type: application/json' -d'{"id":"2196","type":"page","title":"Main page","space":{"key":"AB"},"body":{"storage":{"value":"<p> Text </p>","representation":"storage"}},"version":{"number":2}}' https://Client.atlassian.net/wiki/rest/api/content/2196 | python -mjson.tool
比如我的HTML文件内容如下:
<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html>
我需要在我的 Confluence 页面上将其更新为 HTML 内容,它需要从 HTML 文件中直接获取到脚本 "value":"<p> Text </p>"
当我手动复制示例 HTML 内容到此 value
space 时,页面成功显示 HTML 内容。
我使用 Python 和它的请求模块让这个东西工作。请参阅下面的代码,
import json
import requests
url = 'https://Client.atlassian.net/wiki/rest/api/content/87440'
headers = {'Content-Type': "application/json", 'Accept': "application/json"}
f = open("file.html", "r")
html = f.read()
data={}
data['id'] = "87440"
data['type']="page"
data['title']="Data Page"
data['space']={"key":"AB"}
data['body'] = {"storage":{"representation":"storage"}}
data['version']={"number":4}
print data
data['body']['storage']['value'] = html
print data
res = requests.put(url, json=data, auth=('Username', 'Password'))
print (res.status_code)
print (res.raise_for_status())
如有任何疑问,欢迎随时提问。
我正在尝试使用一些 HTML 内容更新 Confluence 页面。我在同一位置的另一个名为 Output.html
的文件中有此 HTML 内容。我无法直接将 HTML 内容复制并粘贴到此脚本,因为它是大量数据,而且我需要动态执行此脚本。
curl -u user:pass -X PUT -H 'Content-Type: application/json' -d'{"id":"2196","type":"page","title":"Main page","space":{"key":"AB"},"body":{"storage":{"value":"<p> Text </p>","representation":"storage"}},"version":{"number":2}}' https://Client.atlassian.net/wiki/rest/api/content/2196 | python -mjson.tool
比如我的HTML文件内容如下:
<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html>
我需要在我的 Confluence 页面上将其更新为 HTML 内容,它需要从 HTML 文件中直接获取到脚本 "value":"<p> Text </p>"
当我手动复制示例 HTML 内容到此 value
space 时,页面成功显示 HTML 内容。
我使用 Python 和它的请求模块让这个东西工作。请参阅下面的代码,
import json
import requests
url = 'https://Client.atlassian.net/wiki/rest/api/content/87440'
headers = {'Content-Type': "application/json", 'Accept': "application/json"}
f = open("file.html", "r")
html = f.read()
data={}
data['id'] = "87440"
data['type']="page"
data['title']="Data Page"
data['space']={"key":"AB"}
data['body'] = {"storage":{"representation":"storage"}}
data['version']={"number":4}
print data
data['body']['storage']['value'] = html
print data
res = requests.put(url, json=data, auth=('Username', 'Password'))
print (res.status_code)
print (res.raise_for_status())
如有任何疑问,欢迎随时提问。