Hi All,
I managed to produce a confluence page from Jira cloud with Scriptrunner .
The problem is that it does not always work. I've figured out that multi-text fields (description) have a problem when they have a line break.
My question to Scriptrunner Support
With help from Scriptrunner I managed to remove line breaks (JsonStringEncoder) but the Script still not working.
Now the description text is without breaks but with (replaceAll didn't work)
The code:
import com.fasterxml.jackson.core.io.JsonStringEncoder
def baseUrl = new URL("https://myurl.atlassian.net/wiki/rest/api/content")
def issueKey = issue.key
def result = get('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)
String Description = result.body.fields["description"]
def USER_NAME_AND_PASS = "MyUser:pass"
JsonStringEncoder e = JsonStringEncoder.getInstance();
String encodedDescription = new String(e.quoteAsString(Description));
def body = '''
{
"type" : "page",
"status" : "current",
"title" : "NGS Kickoff Meeting Protocol (Project Number: '''+IssueKey+''') ['''+date+''']",
"space" : { "key" : "INCPM" },
"ancestors": [{
"id": 318963721
}],
"body" : {
"storage" : {
"value": "'''+encodedDescription+'''",
"representation" : "storage"
}
}
}'''
def connection = baseUrl.openConnection()
def authString = USER_NAME_AND_PASS.getBytes().encodeBase64().toString()
connection.setRequestProperty( "Authorization", "Basic ${authString}" )
connection.setRequestProperty( "Content-type", "application/json");
connection.setRequestProperty( "Accept", "application/json" );
connection.with {
doOutput = true
requestMethod = 'POST'
outputStream.withWriter { writer ->
writer << body
}
println content.text
}
Thanks,
Shira