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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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
AUG Leaders

Atlassian Community Events