Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to structure a nice JSON for a web hook callout

Stuart__ February 3, 2021

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 Champion
February 3, 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.

Stuart__ February 4, 2021

Perfect, thank you.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events