When the content of the page has quotation, the call fails, any idea?
' {"type":"page","title":"new page-m","space":{"key":"xxx"},"parentId" : "3932626","body":{"storage":{"value":"<p>This "is" a new page</p>","representation":"storage"}}}'
Community moderators have prevented the ability to post new answers.
In JSON, embedded double quotes need to be escaped using \". See this for instance.
Hi I was having some trouble with the same question.
I found out that I need two backslashed to escape the quote. See my simple example below
import os,sys import string,types import httplib import base64 import string import json from imaplib import Response_code username="stephan.hassenpflug" password="atlassianrocks" host="wiki.url" url= "/rest/api/content/" def updatePageContent(pageID = '', title = '', body= ''): conn = httplib.HTTPConnection(host) auth = base64.encodestring('%s:%s' % (username, password)).replace('\n', '') #get current version number, space, title conn.request("GET", url + pageID + "?expand=version,space") response = conn.getresponse() data = json.load(response) contentType = data["type"] if title == '': title = data["title"] space = data["space"]["key"] version = data["version"]["number"] #prepare message message = """{ "id": "%(page)s", "type": "%(type)s", "title": "%(title)s", "space": {"key": "%(space)s"}, "version": {"number": %(version)s, "minorEdit": false}, "body": {"storage": { "value": "%(body)s", "representation": "storage" }}} """ % {'page': pageID, 'type' : contentType, 'title' : title, 'version': str(version + 1), 'space' : space, 'body' : body} conn.putrequest("PUT", "http://" + host + url + pageID ) conn.putheader("Host", host) conn.putheader("User-Agent", "CIEL") conn.putheader("Content-type", "application/json") conn.putheader("Content-length", "%d" % len(message)) conn.putheader("Authorization", "Basic %s" % auth) conn.endheaders() conn.send(message) print conn.getresponse().read() # works as expacted print updatePageContent('343299206', '', '<p>test</p>') # is returning error print updatePageContent('343299206', '', '<p>\"test\"</p>') # is working print updatePageContent('343299206', '', '<p>\\"test\\"</p>')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.