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

How can I escape special characters when sending issues comment through a webhook?

Pablo Serra February 11, 2022

Hi There,

I have a rule that comments issues on a cloud instance with the last comment body of the issues of another cloud instance, by sending {{issue.comments.last.body}} through a webhook:

Comment Body 1.png

 

I'm having some issues with special characters, e.g.:

Comment Body 2.png

Comment Body 3.png

On the receiving instance I'm getting the following:

Comment Body 4.png

Any suggestion on how to handle this kind of comments?

Thanks in advance!

3 answers

1 accepted

4 votes
Answer accepted
Bill Sheboy
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 5, 2022

Hi @Pablo Serra 

Have you tried any of the smart value encoding functions provided by automation before sending the message: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#Encoding 

Kind regards,
Bill

Pablo Serra March 9, 2022

Hi Bill, thanks for your reply.

I've contacted support and after a little back and forth, they provided me the following function that did the trick: asJsonString()

In my post:

{
"commentAuthor": "{{ issue.comments.last.author.displayName }}",
"commentBody": {{ issue.comments.last.body.asJsonString() }},
"keyBancar":"{{ issue.key }}",
"summary":"{{ issue.fields.summary }}",
"keyIssues":"{{ issue.fields.customfield_10716 }}"
}


Please note that it must be sent without the quotation marks around the curly brackets.

More info about this function:
https://support.atlassian.com/cloud-automation/docs/jira-smart-values-json-functions/

Like # people like this
Laura Bachiller
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 26, 2024

Hi.

You can also use the json encode function:

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#Json-encoding

{{issue.summary.jsonEncode}}

Like # people like this
0 votes
Graeme Baker September 30, 2023

This is really old, but I've been trying to do the same thing lately and came across this article.

All I want to do is comment on an issue in 1 instance, and have that fire off a message to a webhook in Jira automation, and it add that comment to a linked ticket (via custom field).

From above there was a missing colon, and comma:

{
"comment": {
"id" : "{{comment.id}}",
"body" : {{comment.body.asJsonString()}},
"author" : {
"accountId" : "{{comment.author}}",
"displayName": "{{comment.author.displayName}}"
}

}

}

How do I use an incoming webhook to update a specific issue with this comment from the payload using these smart values?

{{webhookData.comment.body}}
{{webhookData.comment.author.displayName}}
0 votes
Pablo Serra February 11, 2022

Apparently the problem are the line breaks. Only comments with line breaks failed to impact on the receiving instance.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events