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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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 Jira Automation

New to Jira Automation - goodbye Cron (sort of), hello new project created trigger, new additions to

Hey Everyone! Simeon from the Automation team here. I'm delighted to share some new features and improvements that we are shipping to Jira automation (Cloud only). Firstly, @Sam Harding&nbsp...

2,803 views 10 23
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