0

I am trying to update a Confluence page with some HTML content. I have this HTML content in a different file named Output.html in the same location. I cannot directly copy & paste that HTML content to this script, as it is a huge amount of data, and also I need to execute this script dynamically.

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

For example, my HTML file content is as follows:

<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body>  <h1>My First Heading</h1> <p>My first paragraph.</p>  </body> </html> 

I need this to be updated on my Confluence page as HTML content, which needs to fetched directy from the HTML file to the script "value":"<p> Text </p>"

When I manually copy sample HTML content to this value space, the page successfully shows the HTML content.

4

1 回答 1

2

我使用 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())

如果您有任何疑问,请随时询问。

于 2017-04-03T18:16:37.080 回答