Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Double quotation causes failiur in Confluence Add Page Rest API

Mustafa Abusalah March 1, 2015

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

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Bob Swift OSS (Bob Swift Atlassian Apps)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 1, 2015

In JSON, embedded double quotes need to be escaped using \". See this for instance.

0 votes
Stephan Hassenpflug November 15, 2015

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', '', '&lt;p&gt;test&lt;/p&gt;')
# is returning error
print updatePageContent('343299206', '', '&lt;p&gt;\"test\"&lt;/p&gt;')
# is working
print updatePageContent('343299206', '', '&lt;p&gt;\\"test\\"&lt;/p&gt;')
TAGS
AUG Leaders

Atlassian Community Events