Webhook for adding a comment comes before POST response

We are implementing a different kind of interface to jira service desk. So, basically, users would hit our site, create a issue, and we push that issue over to JSD, and internally correlate the jira issue with our internal case thingie.

All that works fine.

We also use a webhook when comments are created, so that responses to the issue on jira make it back to our internal case.

And, we allow internal communication on our case to push to JSD as a comment. And this is where the problem occurs. When we hit the /rest/servicedeskapi/request/${param.issueKey}/comment endpoint with a POST to create a comment, we save the comment.id to correlate our internal comment with the jira issue comment. We do this for updates, but, most importantly, we do it to prevent dupes. Because when we create the comment, we still get the webhook response.

But, the webhook arrives before the POST response does. So, we do not have the id yet, and we end up with duplicate responses.

Any thoughts on how to get around this? I mean, I could add an internal delay to the webhook processing code, but, that sounds really hacky.

You can never rely on the order of webhooks so I’d recommend to queue them first and then process them.
With a queue, you can e.g. cluster the messages by issueKey and then process with a delay in the right order.
Or you can just put it back if it cannot be processed yet.

There’s no way to tell whether or not it can be processed. If I’m adding a comment and we get a webhook, how do I know if it’s a comment from another user, or the comment I’m posting in flight.

I think the only way to solve this is with a delay, and that seems like an ugly hack :frowning: