Automation for Jira - A rule configured to create a Confluence page using the content of a Jira field fails with the error 500
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
To create a Confluence page from a Jira automation rule, you can follow the steps explained in the article Set a rule to create a Confluence page. This automation rule consists of sending a Web Request to Confluence, along with a JSON payload in the body of the request.
This process also allows you to use Jira Text fields to populate the Confluence page title or description by:
converting them from wiki markup to HTML, as described in Convert wiki markup to HTML or plain text in Jira automation
including them in the JSON payload sent to the Confluence application, as shown in the example below:
1
2
3
4
5
6
7
{
"type":"page",
"title":"{{Test Page Title}}",
"space":{"key":"Test"},
"body":{"storage":{"value":"{{issue.description.html}}",
"representation":"storage"}}
}
It's important to note that certain Jira fields, such as description, may contain text formatting or line breaks. These elements can potentially disrupt the creation of the page or cause incorrect formatting when copying content. Therefore, simply converting wiki markup to HTML using {{issue.description.html}} or {{issue.description.htmlEncode}} alone may not be sufficient for copying fields like issue descriptions.
This KB article explains why the request sent by the automation rule might fail with the error shown in the screenshot below and how to fix it.
Solution
CAUSE:
When using {{issue.description.html}} or {{issue.description.htmlEncode}} in the JSON Payload sent by the automation rule to Confluence (as shown in the example below), the rule may generate a JSON payload without a proper escape character:
1
2
3
4
5
6
7
{
"type":"page",
"title":"{{Test Page Title}}",
"space":{"key":"Test"},
"body":{"storage":{"value":"{{issue.description.html}}",
"representation":"storage"}}
}
This incorrect JSON Payload may lead to an error 500 in the automation rule audit log.
The reason behind this is that Confluence does not support incorrect formats in the JSON payloads, resulting in exceptions being thrown in the Confluence logs.
Example of exception 1
1
2
3
4
5
6
7
8
9
10
11
2023-11-15 17:16:52,503 ERROR [http-nio-8090-exec-9 url: /confluence/rest/api/content/; user: admin] [rest.api.model.ExceptionConverter] convertServiceException No status code found for exception, converting to internal server error :
-- url: /confluence/rest/api/content/ | userName: admin | traceId: 0df3424bb529b26d
org.codehaus.jackson.JsonParseException: Unexpected character ('t' (code 116)): was expecting comma to separate OBJECT entries
at [Source: com.atlassian.confluence.plugins.restapi.filters.LimitingRequestFilter$1@3acd0585; line: 5, column: 43]
at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1433)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:521)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:442)
at org.codehaus.jackson.impl.Utf8StreamParser.nextToken(Utf8StreamParser.java:482)
at org.codehaus.jackson.map.deser.std.BaseNodeDeserializer.deserializeObject(JsonNodeDeserializer.java:192)
at org.codehaus.jackson.map.deser.std.BaseNodeDeserializer.deserializeObject(JsonNodeDeserializer.java:197)
at org.codehaus.jackson.map.deser.std.BaseNodeDeserializer.deserializeObject(JsonNodeDeserializer.java:197)
Example of exception 2
1
2
3
4
5
6
7
8
9
10
2023-11-15 17:17:35,316 ERROR [http-nio-8090-exec-10 url: /confluence/rest/api/content/; user: admin] [rest.api.model.ExceptionConverter] convertServiceException No status code found for exception, converting to internal server error :
-- url: /confluence/rest/api/content/ | userName: admin | traceId: 8e90c890b5397d8d
org.codehaus.jackson.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value
at [Source: com.atlassian.confluence.plugins.restapi.filters.LimitingRequestFilter$1@6e450ee3; line: 5, column: 55]
at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1433)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:521)
at org.codehaus.jackson.impl.JsonParserMinimalBase._throwUnquotedSpace(JsonParserMinimalBase.java:482)
at org.codehaus.jackson.impl.Utf8StreamParser._finishString2(Utf8StreamParser.java:1975)
at org.codehaus.jackson.impl.Utf8StreamParser._finishString(Utf8StreamParser.java:1905)
at org.codehaus.jackson.impl.Utf8StreamParser.getText(Utf8StreamParser.java:276)
SOLUTION:
When working with issue descriptions, it is recommended to use the {{issue.description.html.jsonEncode}} function instead of {{issue.description.html}} or {{issue.description.htmlEncode}}. This will ensure that any special characters in the description are properly encoded and sent correctly.
Below is the sample payload:
1
2
3
4
5
6
7
{
"type":"page",
"title":"{{Test Page Title}}",
"space":{"key":"Test"},
"body":{"storage":{"value":"{{issue.description.html.jsonEncode}}",
"representation":"storage"}}
}
Was this helpful?