Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,029
Community Members
 
Community Events
165
Community Groups

How to structure a nice JSON for a web hook callout

In my automation I have a REST API callout with this payload spec, interested in issue comments

{
"webhookEvent": "issue_commented",
"timestamp": "{{issue.updated.setTimeZone("UTC")}}",
"eventData": {
"target": "XXX",
"comments": [
{{#issue.comments}}
{ "author": "{{author.displayName}}",
"createdAt": "{{created.setTimeZone("UTC")}}",
"body": "{{body}}"},
{{/}}
]
}
}

Two or 3 things. There is no consistency in time (I need a Tardis) between the issue updated date and time (usually 4, 5 o rsometims6 hours after the comment createdAt date and time).

There doesn't seem to be a way to prevent the final trailing ',' when the list of comments is exhausted.

E.G. I want 

{ "webhookEvent": "issue_commented", "timestamp": "2021-02-03T19:27:10.8+0000", "eventData": { "target": "XXX", "comments": [ { "author": "Stuart__", "createdAt": "2021-02-03T14:36:03.7+0000", "body": "Stuart test 1, 2, 3 and 4 and 6 and 7" }, { "author": "Stuart__", "createdAt": "2021-02-03T18:51:34.9+0000", "body": "* B1 * B2 * B3" } ] }}

But get { "webhookEvent": "issue_commented", "timestamp": "2021-02-03T19:27:10.8+0000", "eventData": { "target": "XXX", "comments": [ { "author": "Stuart__", "createdAt": "2021-02-03T14:36:03.7+0000", "body": "Stuart test 1, 2, 3 and 4 and 6 and 7" }, { "author": "Stuart__", "createdAt": "2021-02-03T18:51:34.9+0000", "body": "* B1 * B2 * B3" }, ] }}

Are there any hints on formatting webhook payload as nice JSON?

 

Thank you.

1 answer

1 accepted

2 votes
Answer accepted
Hana Kučerová Community Leader Feb 03, 2021

Hi @Stuart__ ,

according to the final trailing - please try something like this:

{{#issue.comments}}
{"author": "{{author.displayName}}",
"createdAt": "{{created.setTimeZone("UTC")}}",
"body": "{{body}}"}{{^last}},{{/}}
{{/}}

You can find more here.

Perfect, thank you.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Atlassian Automation

Jira Automation: Sum Up Story Points Roundup (Initiatives -> Epics -> Story/Tasks -> Subtasks)

Hi Everyone, In this roundup we combine all the jira automation rules to sum up story points across different issue types. We start from the lowest level, summing up story points from sub-tasks t...

1,842 views 2 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you